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 fca9af0
Show file tree
Hide file tree
Showing 44 changed files with 1,235 additions and 310 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
60 changes: 51 additions & 9 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 All @@ -216,6 +221,8 @@ async fn encumber_aggregate_utxo(
recipient_address: TariAddress,
original_maturity: u64,
use_output: UseOutput,
message: String,
payment_id: PaymentId,
) -> Result<(TxId, Transaction, PublicKey, PublicKey, PublicKey, PublicKey), CommandError> {
wallet_transaction_service
.encumber_aggregate_utxo(
Expand All @@ -229,6 +236,8 @@ async fn encumber_aggregate_utxo(
recipient_address,
original_maturity,
use_output,
message,
payment_id,
)
.await
.map_err(CommandError::TransactionServiceError)
Expand All @@ -240,9 +249,18 @@ async fn spend_backup_pre_mine_utxo(
output_hash: HashOutput,
expected_commitment: PedersenCommitment,
recipient_address: TariAddress,
message: String,
payment_id: PaymentId,
) -> Result<TxId, CommandError> {
wallet_transaction_service
.spend_backup_pre_mine_utxo(fee_per_gram, output_hash, expected_commitment, recipient_address)
.spend_backup_pre_mine_utxo(
fee_per_gram,
output_hash,
expected_commitment,
recipient_address,
message,
payment_id,
)
.await
.map_err(CommandError::TransactionServiceError)
}
Expand Down Expand Up @@ -297,12 +315,13 @@ pub async fn finalise_sha_atomic_swap(
pre_image: PublicKey,
fee_per_gram: MicroMinotari,
message: String,
payment_id: PaymentId,
) -> Result<TxId, CommandError> {
let (tx_id, _fee, amount, tx) = output_service
.create_claim_sha_atomic_swap_transaction(output_hash, pre_image, fee_per_gram)
.await?;
transaction_service
.submit_transaction(tx_id, tx, amount, message)
.submit_transaction(tx_id, tx, amount, message, payment_id)
.await?;
Ok(tx_id)
}
Expand All @@ -314,12 +333,13 @@ pub async fn claim_htlc_refund(
output_hash: FixedHash,
fee_per_gram: MicroMinotari,
message: String,
payment_id: PaymentId,
) -> Result<TxId, CommandError> {
let (tx_id, _fee, amount, tx) = output_service
.create_htlc_refund_transaction(output_hash, fee_per_gram)
.await?;
transaction_service
.submit_transaction(tx_id, tx, amount, message)
.submit_transaction(tx_id, tx, amount, message, payment_id)
.await?;
Ok(tx_id)
}
Expand Down Expand Up @@ -374,14 +394,15 @@ pub async fn coin_split(
num_splits: usize,
fee_per_gram: MicroMinotari,
message: String,
payment_id: PaymentId,
output_service: &mut OutputManagerHandle,
transaction_service: &mut TransactionServiceHandle,
) -> Result<TxId, CommandError> {
let (tx_id, tx, amount) = output_service
.create_coin_split(vec![], amount_per_split, num_splits, fee_per_gram)
.await?;
transaction_service
.submit_transaction(tx_id, tx, amount, message)
.submit_transaction(tx_id, tx, amount, message, payment_id)
.await?;

Ok(tx_id)
Expand Down Expand Up @@ -544,7 +565,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 +579,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 +807,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 @@ -969,6 +993,8 @@ pub async fn command_runner(
output_hash,
commitment.clone(),
args.recipient_address,
args.message,
get_payment_id(&args.payment_id),
)
.await
{
Expand Down Expand Up @@ -1334,6 +1360,8 @@ pub async fn command_runner(
} else {
UseOutput::FromBlockchain(embedded_output.hash())
},
args.message.clone(),
get_payment_id(&args.payment_id),
)
.await
{
Expand Down Expand Up @@ -1977,6 +2005,7 @@ pub async fn command_runner(
args.amount,
args.destination,
args.message,
get_payment_id(&args.payment_id),
)
.await
{
Expand All @@ -1995,7 +2024,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 @@ -2034,6 +2063,7 @@ pub async fn command_runner(
args.num_splits,
args.fee_per_gram,
args.message,
get_payment_id(&args.payment_id),
&mut output_service,
&mut transaction_service.clone(),
)
Expand Down Expand Up @@ -2257,6 +2287,7 @@ pub async fn command_runner(
args.pre_image.into(),
config.fee_per_gram.into(),
args.message,
get_payment_id(&args.payment_id),
)
.await
{
Expand All @@ -2277,6 +2308,7 @@ pub async fn command_runner(
hash,
config.fee_per_gram.into(),
args.message,
get_payment_id(&args.payment_id),
)
.await
{
Expand Down Expand Up @@ -2692,6 +2724,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
20 changes: 20 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 Expand Up @@ -265,6 +271,10 @@ pub struct PreMineSpendEncumberAggregateUtxoArgs {
pub input_file_names: Vec<String>,
#[clap(long)]
pub pre_mine_file_path: Option<PathBuf>,
#[clap(short, long, default_value = "Spend pre-mine encumber aggregate UTXO")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

#[derive(Debug, Args, Clone)]
Expand Down Expand Up @@ -293,6 +303,10 @@ pub struct PreMineSpendBackupUtxoArgs {
pub recipient_address: TariAddress,
#[clap(long)]
pub pre_mine_file_path: Option<PathBuf>,
#[clap(short, long, default_value = "Spend pre-mine backup UTXO")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

#[derive(Debug, Args, Clone)]
Expand Down Expand Up @@ -362,6 +376,8 @@ pub struct CoinSplitArgs {
pub fee_per_gram: MicroMinotari,
#[clap(short, long, default_value = "Coin split")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

#[derive(Debug, Args, Clone)]
Expand Down Expand Up @@ -431,6 +447,8 @@ pub struct FinaliseShaAtomicSwapArgs {
pub pre_image: UniPublicKey,
#[clap(short, long, default_value = "Claimed HTLC atomic swap")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

fn parse_hex(s: &str) -> Result<Vec<u8>, CliParseError> {
Expand All @@ -443,6 +461,8 @@ pub struct ClaimShaAtomicSwapRefundArgs {
pub output_hash: Vec<Vec<u8>>,
#[clap(short, long, default_value = "Claimed HTLC atomic swap refund")]
pub message: String,
#[clap(short, long, default_value = NO_PAYMENT_ID)]
pub payment_id: String,
}

#[derive(Debug, Args, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_console_wallet/src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn convert_to_transaction_event(event: String, source: TransactionWrapper) -
direction: completed.direction.to_string(),
amount: completed.amount.as_u64(),
message: completed.message.to_string(),
payment_id: completed.payment_id.map(|id| id.to_bytes()).unwrap_or_default(),
payment_id: completed.payment_id.to_bytes(),
},
TransactionWrapper::Outbound(outbound) => TransactionEvent {
event,
Expand Down
Loading

0 comments on commit fca9af0

Please sign in to comment.