Skip to content

Commit

Permalink
Add change metadata to encrypted data
Browse files Browse the repository at this point in the history
Added receiver address. amount and payment id to encrypted data so a view only
wallet will be able to identify the receiver when importing a change output.
  • Loading branch information
hansieodendaal committed Dec 5, 2024
1 parent d339598 commit b6a0e16
Show file tree
Hide file tree
Showing 30 changed files with 954 additions and 186 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions applications/minotari_app_grpc/proto/wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ message CreateBurnTransactionRequest{
uint64 fee_per_gram = 2;
string message = 3;
bytes claim_public_key = 4;
string payment_id = 5;
}


Expand Down
29 changes: 24 additions & 5 deletions applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ pub(crate) const SPEND_STEP_2_SELF: &str = "step_2_for_self";
pub(crate) const SPEND_STEP_3_SELF: &str = "step_3_for_self";
pub(crate) const SPEND_STEP_3_PARTIES: &str = "step_3_for_parties";
pub(crate) const SPEND_STEP_4_LEADER: &str = "step_4_for_leader_from_";
pub(crate) const NO_PAYMENT_ID: &str = "<No payment id>";

#[derive(Debug)]
pub struct SentTransaction {}
Expand All @@ -169,6 +170,7 @@ pub async fn send_tari(
amount: MicroMinotari,
destination: TariAddress,
message: String,
payment_id: PaymentId,
) -> Result<TxId, CommandError> {
wallet_transaction_service
.send_transaction(
Expand All @@ -178,6 +180,7 @@ pub async fn send_tari(
OutputFeatures::default(),
fee_per_gram * uT,
message,
payment_id,
)
.await
.map_err(CommandError::TransactionServiceError)
Expand All @@ -188,13 +191,15 @@ pub async fn burn_tari(
fee_per_gram: u64,
amount: MicroMinotari,
message: String,
payment_id: PaymentId,
) -> Result<(TxId, BurntProof), CommandError> {
wallet_transaction_service
.burn_tari(
amount,
UtxoSelectionCriteria::default(),
fee_per_gram * uT,
message,
payment_id,
None,
)
.await
Expand Down Expand Up @@ -544,7 +549,7 @@ pub async fn make_it_rain(
// Send transaction
let tx_id = match transaction_type {
MakeItRainTransactionType::Interactive => {
send_tari(tx_service, fee, amount, address.clone(), msg.clone()).await
send_tari(tx_service, fee, amount, address.clone(), msg.clone(), PaymentId::Empty).await
},
MakeItRainTransactionType::StealthOneSided => {
send_one_sided_to_stealth_address(
Expand All @@ -558,9 +563,11 @@ pub async fn make_it_rain(
)
.await
},
MakeItRainTransactionType::BurnTari => burn_tari(tx_service, fee, amount, msg.clone())
.await
.map(|(tx_id, _)| tx_id),
MakeItRainTransactionType::BurnTari => {
burn_tari(tx_service, fee, amount, msg.clone(), PaymentId::Empty)
.await
.map(|(tx_id, _)| tx_id)
},
};
let submit_time = Instant::now();

Expand Down Expand Up @@ -784,6 +791,7 @@ pub async fn command_runner(
config.fee_per_gram,
args.amount,
args.message,
get_payment_id(&args.payment_id),
)
.await
{
Expand Down Expand Up @@ -1977,6 +1985,7 @@ pub async fn command_runner(
args.amount,
args.destination,
args.message,
get_payment_id(&args.payment_id),
)
.await
{
Expand All @@ -1995,7 +2004,7 @@ pub async fn command_runner(
UtxoSelectionCriteria::default(),
args.destination,
args.message,
PaymentId::Empty,
get_payment_id(&args.payment_id),
)
.await
{
Expand Down Expand Up @@ -2692,6 +2701,16 @@ pub async fn command_runner(
Ok(unban_peer_manager_peers)
}

fn get_payment_id(payment_id: &str) -> PaymentId {
match payment_id {
NO_PAYMENT_ID => PaymentId::Empty,
_ => {
let payment_id_arg = payment_id.as_bytes().to_vec();
PaymentId::Open(payment_id_arg)
},
}
}

async fn temp_ban_peers(wallet: &WalletSqlite, peer_list: &mut Vec<Peer>) {
for peer in peer_list {
let _unused = wallet
Expand Down
6 changes: 6 additions & 0 deletions applications/minotari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ use tari_utilities::{
};
use thiserror::Error;

use crate::automation::commands::NO_PAYMENT_ID;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
#[clap(propagate_version = true)]
Expand Down Expand Up @@ -177,13 +179,17 @@ pub struct SendMinotariArgs {
pub destination: TariAddress,
#[clap(short, long, default_value = "<No message>")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

#[derive(Debug, Args, Clone)]
pub struct BurnMinotariArgs {
pub amount: MicroMinotari,
#[clap(short, long, default_value = "Burn funds")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

#[derive(Debug, Args, Clone)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
OutputFeatures::default(),
fee_per_gram.into(),
message,
payment_id,
)
.await
} else if payment_type == PaymentType::OneSided as i32 {
Expand Down Expand Up @@ -612,6 +613,7 @@ impl wallet_server::Wallet for WalletGrpcServer {
UtxoSelectionCriteria::default(),
message.fee_per_gram.into(),
message.message,
PaymentId::Open(message.payment_id.as_bytes().to_vec()),
if message.claim_public_key.is_empty() {
None
} else {
Expand Down Expand Up @@ -985,7 +987,13 @@ impl wallet_server::Wallet for WalletGrpcServer {
output = output.with_script(script![Nop].map_err(|e| Status::invalid_argument(e.to_string()))?);

let (tx_id, transaction) = output_manager
.create_send_to_self_with_output(vec![output], fee_per_gram.into(), UtxoSelectionCriteria::default())
.create_send_to_self_with_output(
vec![output],
fee_per_gram.into(),
UtxoSelectionCriteria::default(),
message.clone(),
PaymentId::Empty,
)
.await
.map_err(|e| Status::internal(e.to_string()))?;

Expand Down
53 changes: 44 additions & 9 deletions applications/minotari_console_wallet/src/ui/components/burn_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fs;

use log::*;
use minotari_wallet::output_manager_service::UtxoSelectionCriteria;
use tari_core::transactions::tari_amount::MicroMinotari;
use tari_core::transactions::{tari_amount::MicroMinotari, transaction_components::encrypted_data::PaymentId};
use tokio::{runtime::Handle, sync::watch};
use tui::{
backend::Backend,
Expand Down Expand Up @@ -35,6 +35,7 @@ pub struct BurnTab {
amount_field: String,
fee_field: String,
message_field: String,
payment_id_field: String,
error_message: Option<String>,
success_message: Option<String>,
offline_message: Option<String>,
Expand All @@ -54,6 +55,7 @@ impl BurnTab {
amount_field: String::new(),
fee_field: app_state.get_default_fee_per_gram().as_u64().to_string(),
message_field: String::new(),
payment_id_field: String::new(),
error_message: None,
success_message: None,
offline_message: None,
Expand Down Expand Up @@ -92,22 +94,22 @@ impl BurnTab {
let instructions = Paragraph::new(vec![
Spans::from(vec![
Span::raw("Press "),
Span::styled("P", Style::default().add_modifier(Modifier::BOLD)),
Span::styled("V", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Span::styled("Burn Proof Filepath", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" field, "),
Span::raw(", "),
Span::styled("C", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Span::styled("Claim Public Key", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" field, "),
Span::raw(", "),
Span::styled("A", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Span::styled("Amount", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" and "),
Span::raw(", "),
Span::styled("F", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to edit "),
Span::styled("Fee-Per-Gram", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" field,"),
Span::raw(" and "),
Span::styled("B", Style::default().add_modifier(Modifier::BOLD)),
Span::raw(" to view burnt proofs."),
]),
Expand All @@ -129,7 +131,7 @@ impl BurnTab {
.block(
Block::default()
.borders(Borders::ALL)
.title("Save burn proof to file(p)ath:"),
.title("Sa(v)e burn proof to file path:"),
);
f.render_widget(burnt_proof_filepath_input, vert_chunks[1]);

Expand Down Expand Up @@ -162,13 +164,26 @@ impl BurnTab {
.block(Block::default().borders(Borders::ALL).title("(F)ee-per-gram (uT):"));
f.render_widget(fee_input, amount_fee_layout[1]);

let message_payment_id_layout = Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
.split(vert_chunks[4]);

let message_input = Paragraph::new(self.message_field.as_ref())
.style(match self.burn_input_mode {
BurnInputMode::Message => Style::default().fg(Color::Magenta),
_ => Style::default(),
})
.block(Block::default().borders(Borders::ALL).title("(M)essage:"));
f.render_widget(message_input, vert_chunks[4]);
f.render_widget(message_input, message_payment_id_layout[0]);

let payment_id_input = Paragraph::new(self.payment_id_field.as_ref())
.style(match self.burn_input_mode {
BurnInputMode::PaymentId => Style::default().fg(Color::Magenta),
_ => Style::default(),
})
.block(Block::default().borders(Borders::ALL).title("(P)ayment-id:"));
f.render_widget(payment_id_input, message_payment_id_layout[1]);

match self.burn_input_mode {
BurnInputMode::None => (),
Expand Down Expand Up @@ -204,6 +219,12 @@ impl BurnTab {
// Move one line down, from the border to the input line
vert_chunks[4].y + 1,
),
BurnInputMode::PaymentId => f.set_cursor(
// Put cursor past the end of the input text
vert_chunks[5].x + self.payment_id_field.width() as u16 + 1,
// Move one line down, from the border to the input line
vert_chunks[5].y + 1,
),
}
}

Expand Down Expand Up @@ -312,6 +333,7 @@ impl BurnTab {
UtxoSelectionCriteria::default(),
fee_per_gram,
self.message_field.clone(),
PaymentId::Open(self.payment_id_field.as_bytes().to_vec()),
tx,
)) {
Err(e) => {
Expand Down Expand Up @@ -356,6 +378,7 @@ impl BurnTab {
self.amount_field = "".to_string();
self.fee_field = app_state.get_default_fee_per_gram().as_u64().to_string();
self.message_field = "".to_string();
self.payment_id_field = "".to_string();
self.burn_input_mode = BurnInputMode::None;
self.burn_result_watch = Some(rx);
}
Expand Down Expand Up @@ -414,6 +437,13 @@ impl BurnTab {
return KeyHandled::Handled;
},
},
BurnInputMode::PaymentId => match c {
'\n' => self.burn_input_mode = BurnInputMode::None,
c => {
self.payment_id_field.push(c);
return KeyHandled::Handled;
},
},
}
}

Expand Down Expand Up @@ -608,13 +638,14 @@ impl<B: Backend> Component<B> for BurnTab {
}

match c {
'p' => self.burn_input_mode = BurnInputMode::BurntProofPath,
'v' => self.burn_input_mode = BurnInputMode::BurntProofPath,
'c' => self.burn_input_mode = BurnInputMode::ClaimPublicKey,
'a' => {
self.burn_input_mode = BurnInputMode::Amount;
},
'f' => self.burn_input_mode = BurnInputMode::Fee,
'm' => self.burn_input_mode = BurnInputMode::Message,
'p' => self.burn_input_mode = BurnInputMode::PaymentId,
'b' => {
self.show_proofs = !self.show_proofs;
},
Expand Down Expand Up @@ -672,6 +703,9 @@ impl<B: Backend> Component<B> for BurnTab {
BurnInputMode::Message => {
let _ = self.message_field.pop();
},
BurnInputMode::PaymentId => {
let _ = self.payment_id_field.pop();
},
BurnInputMode::None => {},
}
}
Expand All @@ -684,6 +718,7 @@ pub enum BurnInputMode {
ClaimPublicKey,
Amount,
Message,
PaymentId,
Fee,
}

Expand Down
15 changes: 13 additions & 2 deletions applications/minotari_console_wallet/src/ui/components/send_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use log::*;
use minotari_wallet::output_manager_service::UtxoSelectionCriteria;
use tari_common_types::wallet_types::WalletType;
use tari_core::transactions::tari_amount::MicroMinotari;
use tari_core::transactions::{tari_amount::MicroMinotari, transaction_components::encrypted_data::PaymentId};
use tari_utilities::hex::Hex;
use tokio::{runtime::Handle, sync::watch};
use tui::{
Expand Down Expand Up @@ -300,7 +300,12 @@ impl SendTab {
UtxoSelectionCriteria::default(),
fee_per_gram,
self.message_field.clone(),
self.payment_id_field.clone(),
if self.payment_id_field.is_empty() {
PaymentId::Empty
} else {
let bytes = self.payment_id_field.as_bytes().to_vec();
PaymentId::Open(bytes)
},
tx,
),
) {
Expand All @@ -321,6 +326,12 @@ impl SendTab {
UtxoSelectionCriteria::default(),
fee_per_gram,
self.message_field.clone(),
if self.payment_id_field.is_empty() {
PaymentId::Empty
} else {
let bytes = self.payment_id_field.as_bytes().to_vec();
PaymentId::Open(bytes)
},
tx,
)) {
Err(e) => {
Expand Down
Loading

0 comments on commit b6a0e16

Please sign in to comment.