diff --git a/applications/minotari_console_wallet/src/automation/commands.rs b/applications/minotari_console_wallet/src/automation/commands.rs index c382d6d8a2f..4b08b1fbbbd 100644 --- a/applications/minotari_console_wallet/src/automation/commands.rs +++ b/applications/minotari_console_wallet/src/automation/commands.rs @@ -483,7 +483,8 @@ pub async fn make_it_rain( let delay_ms = if start_time > now { println!( "`make-it-rain` scheduled to start at {}: payment_id \"{}\"", - start_time, payment_id.compact_display() + start_time, + payment_id.user_data_as_string() ); (start_time - now).num_milliseconds() as u64 } else { @@ -507,7 +508,9 @@ pub async fn make_it_rain( } println!( "\n`make-it-rain` starting {} {} transactions \"{}\"\n", - num_txs, transaction_type, payment_id.compact_display() + num_txs, + transaction_type, + payment_id.user_data_as_string() ); let payment_id_clone = payment_id.clone(); let (sender, mut receiver) = mpsc::channel(num_txs); @@ -552,7 +555,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(), payment_id.clone()).await + send_tari(tx_service, fee, amount, address.clone(), payment_id_clone).await }, MakeItRainTransactionType::StealthOneSided => { send_one_sided_to_stealth_address( @@ -565,11 +568,9 @@ pub async fn make_it_rain( ) .await }, - MakeItRainTransactionType::BurnTari => { - burn_tari(tx_service, fee, amount, payment_id.clone()) - .await - .map(|(tx_id, _)| tx_id) - }, + MakeItRainTransactionType::BurnTari => burn_tari(tx_service, fee, amount, payment_id_clone) + .await + .map(|(tx_id, _)| tx_id), }; let submit_time = Instant::now(); @@ -626,7 +627,7 @@ pub async fn make_it_rain( "\n`make-it-rain` concluded {} {} transactions (\"{}\") at {}", num_txs, transaction_type, - payment_id_clone.compact_display(), + payment_id_clone.user_data_as_string(), Utc::now(), ); }); @@ -792,7 +793,7 @@ pub async fn command_runner( transaction_service.clone(), config.fee_per_gram, args.amount, - PaymentId::Open(args.payment_id.as_bytes().to_vec()), + PaymentId::open_from_str(&args.payment_id), ) .await { @@ -978,7 +979,7 @@ pub async fn command_runner( output_hash, commitment.clone(), args.recipient_address, - PaymentId::Open(args.payment_id.as_bytes().to_vec()), + PaymentId::open_from_str(&args.payment_id), ) .await { @@ -1344,7 +1345,7 @@ pub async fn command_runner( } else { UseOutput::FromBlockchain(embedded_output.hash()) }, - PaymentId::Open(args.payment_id.as_bytes().to_vec()), + PaymentId::open_from_str(&args.payment_id), ) .await { @@ -1987,7 +1988,7 @@ pub async fn command_runner( config.fee_per_gram, args.amount, args.destination, - PaymentId::Open(args.payment_id.as_bytes().to_vec()), + PaymentId::open_from_str(&args.payment_id), ) .await { @@ -2005,7 +2006,7 @@ pub async fn command_runner( args.amount, UtxoSelectionCriteria::default(), args.destination, - PaymentId::Open(args.payment_id.as_bytes().to_vec()), + PaymentId::open_from_str(&args.payment_id), ) .await { @@ -2031,7 +2032,7 @@ pub async fn command_runner( args.start_time.unwrap_or_else(Utc::now), args.destination, transaction_type, - PaymentId::Open(args.payment_id.as_bytes().to_vec()), + PaymentId::open_from_str(&args.payment_id), ) .await { @@ -2043,7 +2044,7 @@ pub async fn command_runner( args.amount_per_split, args.num_splits, args.fee_per_gram, - PaymentId::Open(args.payment_id.as_bytes().to_vec()), + PaymentId::open_from_str(&args.payment_id), &mut output_service, &mut transaction_service.clone(), ) @@ -2243,7 +2244,7 @@ pub async fn command_runner( args.amount, UtxoSelectionCriteria::default(), args.destination, - PaymentId::Open(args.payment_id.as_bytes().to_vec()), + PaymentId::open_from_str(&args.payment_id), ) .await { @@ -2266,7 +2267,7 @@ pub async fn command_runner( hash, args.pre_image.into(), config.fee_per_gram.into(), - PaymentId::Open(args.payment_id.as_bytes().to_vec()), + PaymentId::open_from_str(&args.payment_id), ) .await { @@ -2286,7 +2287,7 @@ pub async fn command_runner( transaction_service.clone(), hash, config.fee_per_gram.into(), - PaymentId::Open(args.payment_id.as_bytes().to_vec()), + PaymentId::open_from_str(&args.payment_id), ) .await { @@ -2327,7 +2328,7 @@ pub async fn command_runner( ), UtxoSelectionCriteria::default(), config.fee_per_gram * uT, - PaymentId::Open(args.payment_id.as_bytes().to_vec()), + PaymentId::open_from_str(&args.payment_id), ) .await?; debug!(target: LOG_TARGET, "Registering VN tx_id {}", tx_id); diff --git a/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs b/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs index b9745617d0d..5d77635eb60 100644 --- a/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs +++ b/applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs @@ -414,7 +414,7 @@ impl wallet_server::Wallet for WalletGrpcServer { tx_id, tx, amount, - PaymentId::Open("Claiming HTLC transaction with pre-image".as_bytes().to_vec()), + PaymentId::open_from_str("Claiming HTLC transaction with pre-image"), ) .await { @@ -469,7 +469,7 @@ impl wallet_server::Wallet for WalletGrpcServer { tx_id, tx, amount, - PaymentId::Open("Creating HTLC refund transaction".as_bytes().to_vec()), + PaymentId::open_from_str("Creating HTLC refund transaction"), ) .await { @@ -525,7 +525,7 @@ impl wallet_server::Wallet for WalletGrpcServer { .map_err(Status::invalid_argument)?; let mut transfers = Vec::new(); - for (hex_address, address, amount, fee_per_gram, payment_type, payment_id) in recipients { + for (hex_address, address, amount, fee_per_gram, payment_type, payment_id) in recipients { let payment_id = PaymentId::from_bytes(&payment_id); let mut transaction_service = self.get_transaction_service(); transfers.push(async move { @@ -611,7 +611,7 @@ impl wallet_server::Wallet for WalletGrpcServer { message.amount.into(), UtxoSelectionCriteria::default(), message.fee_per_gram.into(), - PaymentId::Open(message.payment_id.as_bytes().to_vec()), + PaymentId::open_from_str(&message.payment_id), if message.claim_public_key.is_empty() { None } else { @@ -861,7 +861,7 @@ impl wallet_server::Wallet for WalletGrpcServer { .import_unblinded_output_as_non_rewindable( o.clone(), TariAddress::default(), - PaymentId::from_bytes(&message.payment_id) + PaymentId::from_bytes(&message.payment_id), ) .await .map_err(|e| Status::internal(format!("{:?}", e)))? @@ -988,7 +988,7 @@ impl wallet_server::Wallet for WalletGrpcServer { vec![output], fee_per_gram.into(), UtxoSelectionCriteria::default(), - PaymentId::Open(format!("Template registration {}", template_name).as_bytes().to_vec()), + PaymentId::open_from_str(&format!("Template registration {}", template_name)), ) .await .map_err(|e| Status::internal(e.to_string()))?; @@ -1131,7 +1131,7 @@ fn convert_wallet_transaction_into_transaction_info( fee: 0, excess_sig: Default::default(), timestamp: tx.timestamp.timestamp() as u64, - payment_id: vec![], + payment_id: tx.payment_id.to_bytes(), }, PendingOutbound(tx) => TransactionInfo { tx_id: tx.tx_id.into(), @@ -1144,7 +1144,7 @@ fn convert_wallet_transaction_into_transaction_info( fee: tx.fee.into(), excess_sig: Default::default(), timestamp: tx.timestamp.timestamp() as u64, - payment_id: vec![], + payment_id: tx.payment_id.to_bytes(), }, Completed(tx) => TransactionInfo { tx_id: tx.tx_id.into(), diff --git a/applications/minotari_console_wallet/src/notifier/mod.rs b/applications/minotari_console_wallet/src/notifier/mod.rs index 0a3cc681c58..8508920c74b 100644 --- a/applications/minotari_console_wallet/src/notifier/mod.rs +++ b/applications/minotari_console_wallet/src/notifier/mod.rs @@ -333,7 +333,7 @@ fn args_from_outbound(tx: &OutboundTransaction, event: &str) -> Vec { String::from(event), amount, tx.tx_id.to_string(), - tx.payment_id.compact_display(), + tx.payment_id.user_data_as_string(), tx.destination_address.to_base58(), status, "outbound".to_string(), @@ -349,7 +349,7 @@ fn args_from_inbound(tx: &InboundTransaction, event: &str) -> Vec { String::from(event), amount, tx.tx_id.to_string(), - tx.payment_id.compact_display(), + tx.payment_id.user_data_as_string(), tx.source_address.to_base58(), status, "inbound".to_string(), diff --git a/applications/minotari_console_wallet/src/ui/components/burn_tab.rs b/applications/minotari_console_wallet/src/ui/components/burn_tab.rs index 77ad572a058..a8f0dfb291f 100644 --- a/applications/minotari_console_wallet/src/ui/components/burn_tab.rs +++ b/applications/minotari_console_wallet/src/ui/components/burn_tab.rs @@ -314,8 +314,7 @@ impl BurnTab { if self.payment_id_field.is_empty() { PaymentId::Empty } else { - let bytes = self.payment_id_field.as_bytes().to_vec(); - PaymentId::Open(bytes) + PaymentId::open_from_str(&self.payment_id_field) }, tx, )) { diff --git a/applications/minotari_console_wallet/src/ui/components/send_tab.rs b/applications/minotari_console_wallet/src/ui/components/send_tab.rs index ffe6ae231fe..72277b121d2 100644 --- a/applications/minotari_console_wallet/src/ui/components/send_tab.rs +++ b/applications/minotari_console_wallet/src/ui/components/send_tab.rs @@ -287,8 +287,7 @@ impl SendTab { if self.payment_id_field.is_empty() { PaymentId::Empty } else { - let bytes = self.payment_id_field.as_bytes().to_vec(); - PaymentId::Open(bytes) + PaymentId::open_from_str(&self.payment_id_field) }, tx, ), @@ -312,8 +311,7 @@ impl SendTab { if self.payment_id_field.is_empty() { PaymentId::Empty } else { - let bytes = self.payment_id_field.as_bytes().to_vec(); - PaymentId::Open(bytes) + PaymentId::open_from_str(&self.payment_id_field) }, tx, )) { diff --git a/applications/minotari_console_wallet/src/ui/components/transactions_tab.rs b/applications/minotari_console_wallet/src/ui/components/transactions_tab.rs index 91dbe340876..d37494c0035 100644 --- a/applications/minotari_console_wallet/src/ui/components/transactions_tab.rs +++ b/applications/minotari_console_wallet/src/ui/components/transactions_tab.rs @@ -147,7 +147,7 @@ impl TransactionsTab { ))); column3_items.push(ListItem::new(Span::styled( - t.payment_id.clone().unwrap_or_default().compact_display(), + t.payment_id.clone().unwrap_or_default().user_data_as_string(), Style::default().fg(text_color), ))); } @@ -382,7 +382,10 @@ impl TransactionsTab { }; let status = Span::styled(status_msg, Style::default().fg(Color::White)); - let message = Span::styled(tx.payment_id.clone().unwrap_or_default().compact_display(), Style::default().fg(Color::White)); + let message = Span::styled( + tx.payment_id.clone().unwrap_or_default().user_data_as_string(), + Style::default().fg(Color::White), + ); // let mined_time = DateTime::::from_naive_utc_and_offset(tx.mined_timestamp, // Local::now().offset().to_owned()); @@ -440,8 +443,8 @@ impl TransactionsTab { let maturity = Span::styled(maturity, Style::default().fg(Color::White)); let payment_id = match tx.payment_id.clone() { - Some(v) => format!("{}", v.compact_display()), - None => "None".to_string(), + Some(v) => v.user_data_as_string(), + None => "".to_string(), }; let payment_id = Span::styled(payment_id, Style::default().fg(Color::White)); diff --git a/applications/minotari_console_wallet/src/ui/state/tasks.rs b/applications/minotari_console_wallet/src/ui/state/tasks.rs index b05b6450da4..2c88d104bc0 100644 --- a/applications/minotari_console_wallet/src/ui/state/tasks.rs +++ b/applications/minotari_console_wallet/src/ui/state/tasks.rs @@ -205,13 +205,7 @@ pub async fn send_burn_transaction_task( // ---------------------------------------------------------------------------- let (burn_tx_id, original_proof) = match transaction_service_handle - .burn_tari( - amount, - selection_criteria, - fee_per_gram, - payment_id, - claim_public_key, - ) + .burn_tari(amount, selection_criteria, fee_per_gram, payment_id, claim_public_key) .await { Ok((burn_tx_id, original_proof)) => (burn_tx_id, original_proof), diff --git a/base_layer/core/src/transactions/transaction_components/encrypted_data.rs b/base_layer/core/src/transactions/transaction_components/encrypted_data.rs index dfd9aac6fee..8e616ad0fc2 100644 --- a/base_layer/core/src/transactions/transaction_components/encrypted_data.rs +++ b/base_layer/core/src/transactions/transaction_components/encrypted_data.rs @@ -96,7 +96,10 @@ pub enum PaymentId { Open(Vec), /// This payment ID is automatically generated by the system for output UTXOs. The optional user specified /// `Open(Vec)` payment ID will be assigned to `id`; the system adds in the sender address. - AddressAndData { sender_address: TariAddress, user_data: Vec }, + AddressAndData { + sender_address: TariAddress, + user_data: Vec, + }, /// This payment ID is automatically generated by the system for change outputs. The optional user specified /// `Open(Vec)` payment ID will be assigned to `id`; the system adds in the transaction amount and recipient /// address. @@ -127,7 +130,7 @@ impl PaymentId { } } - pub fn get_user_data(&self) -> Vec { + pub fn user_data_as_bytes(&self) -> Vec { match &self { PaymentId::Empty => vec![], PaymentId::U64(v) => v.to_le_bytes().to_vec(), @@ -268,27 +271,30 @@ impl PaymentId { String::from_utf8_lossy(bytes).to_string() } - /// Helper function to display the payment id in a compact form - pub fn compact_display(&self) -> String { + /// Helper function to display the payment id's user data + pub fn user_data_as_string(&self) -> String { match self { - PaymentId::Empty => { - self.to_string() - }, + PaymentId::Empty => self.to_string(), PaymentId::U64(v) => format!("{}", v), PaymentId::U256(v) => format!("{}", v), - PaymentId::Address(v) => format!("{}", v.to_base58()), - PaymentId::Open(v) => format!("{}", PaymentId::stringify_bytes(v)), + PaymentId::Address(v) => v.to_base58(), + PaymentId::Open(v) => PaymentId::stringify_bytes(v), PaymentId::AddressAndData { sender_address: _sender_address, user_data, - } => format!("{}", PaymentId::stringify_bytes(user_data)), + } => PaymentId::stringify_bytes(user_data), PaymentId::ChangeInfo { recipient_address: _recipient_address, amount: _amount, user_data, - } => format!("{}", PaymentId::stringify_bytes(user_data)), + } => PaymentId::stringify_bytes(user_data), } } + + /// Helper function to create a `PaymentId::Open` from a string + pub fn open_from_str(s: &str) -> Self { + PaymentId::Open(s.as_bytes().to_vec()) + } } impl Display for PaymentId { @@ -605,7 +611,7 @@ mod test { // All the bytes except for the last byte of the two payment ids should be the same let address_vec = address.to_vec(); - let payment_id_2_vec = payment_id_2_from_bytes.get_user_data(); + let payment_id_2_vec = payment_id_2_from_bytes.user_data_as_bytes(); assert_eq!( address_vec[..address_vec.len() - 1], payment_id_2_vec[..payment_id_2_vec.len() - 1] @@ -880,32 +886,37 @@ mod test { #[test] fn it_gets_useable_data() { let payment_id = PaymentId::Empty; - assert_eq!("", PaymentId::stringify_bytes(&payment_id.get_user_data())); + assert_eq!("", PaymentId::stringify_bytes(&payment_id.user_data_as_bytes())); let payment_id = PaymentId::U64(12345); assert_eq!( "12345", - u64::from_le_bytes(payment_id.get_user_data().try_into().unwrap()).to_string() + u64::from_le_bytes(payment_id.user_data_as_bytes().try_into().unwrap()).to_string() ); let payment_id = PaymentId::U256(U256::from_dec_str("123456789").unwrap()); assert_eq!( "123456789", - U256::from_little_endian(&payment_id.get_user_data()).to_string() + U256::from_little_endian(&payment_id.user_data_as_bytes()).to_string() ); let payment_id = PaymentId::Address(TariAddress::from_base58("f3S7XTiyKQauZpDUjdR8NbcQ33MYJigiWiS44ccZCxwAAjk").unwrap()); assert_eq!( "f3S7XTiyKQauZpDUjdR8NbcQ33MYJigiWiS44ccZCxwAAjk", - TariAddress::from_bytes(&payment_id.get_user_data()).unwrap().to_base58() + TariAddress::from_bytes(&payment_id.user_data_as_bytes()) + .unwrap() + .to_base58() ); let payment_id = PaymentId::AddressAndData { sender_address: TariAddress::from_base58("f3S7XTiyKQauZpDUjdR8NbcQ33MYJigiWiS44ccZCxwAAjk").unwrap(), user_data: "Hello World!!!".as_bytes().to_vec(), }; - assert_eq!("Hello World!!!", PaymentId::stringify_bytes(&payment_id.get_user_data())); + assert_eq!( + "Hello World!!!", + PaymentId::stringify_bytes(&payment_id.user_data_as_bytes()) + ); let payment_id = PaymentId::ChangeInfo { recipient_address: TariAddress::from_base58("f3S7XTiyKQauZpDUjdR8NbcQ33MYJigiWiS44ccZCxwAAjk").unwrap(), @@ -921,7 +932,7 @@ mod test { }; assert_eq!( "Hello World!!! | 11-22-33", - PaymentId::stringify_bytes(&payment_id.get_user_data()) + PaymentId::stringify_bytes(&payment_id.user_data_as_bytes()) ); } } diff --git a/base_layer/core/src/transactions/transaction_protocol/recipient.rs b/base_layer/core/src/transactions/transaction_protocol/recipient.rs index 53e6c80af2d..ee2e2a148b9 100644 --- a/base_layer/core/src/transactions/transaction_protocol/recipient.rs +++ b/base_layer/core/src/transactions/transaction_protocol/recipient.rs @@ -207,7 +207,6 @@ mod test { public_excess: sender_test_params.kernel_nonce_key_pk, // any random key will do public_nonce: sender_test_params.public_nonce_key_pk, // any random key will do metadata: m.clone(), - message: "".to_string(), payment_id: PaymentId::Empty, features, script, diff --git a/base_layer/core/src/transactions/transaction_protocol/single_receiver.rs b/base_layer/core/src/transactions/transaction_protocol/single_receiver.rs index 8e1922a6c2f..453fecac7a8 100644 --- a/base_layer/core/src/transactions/transaction_protocol/single_receiver.rs +++ b/base_layer/core/src/transactions/transaction_protocol/single_receiver.rs @@ -285,7 +285,6 @@ mod test { public_excess: pub_xs.clone(), public_nonce: pub_rs.clone(), metadata: m.clone(), - message: "".to_string(), payment_id: PaymentId::Empty, features: OutputFeatures::default(), script: script.clone(), diff --git a/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs b/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs index e931dd62ffa..b2839f975a6 100644 --- a/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs +++ b/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs @@ -410,7 +410,7 @@ where KM: TransactionKeyManagerInterface recipient_address: recipient.recipient_address, amount: recipient.amount, user_data: if let Some(payment_id) = self.payment_id.clone() { - payment_id.get_user_data() + payment_id.user_data_as_bytes() } else { vec![] }, @@ -420,7 +420,7 @@ where KM: TransactionKeyManagerInterface recipient_address: address, amount: total_to_self, user_data: if let Some(payment_id) = self.payment_id.clone() { - payment_id.get_user_data() + payment_id.user_data_as_bytes() } else { vec![] }, diff --git a/base_layer/wallet/src/output_manager_service/service.rs b/base_layer/wallet/src/output_manager_service/service.rs index f0e01cd6b13..bb0eec3dd93 100644 --- a/base_layer/wallet/src/output_manager_service/service.rs +++ b/base_layer/wallet/src/output_manager_service/service.rs @@ -482,12 +482,7 @@ where payment_id, } => { let (tx_id, transaction) = self - .create_pay_to_self_containing_outputs( - outputs, - selection_criteria, - fee_per_gram, - payment_id, - ) + .create_pay_to_self_containing_outputs(outputs, selection_criteria, fee_per_gram, payment_id) .await?; Ok(OutputManagerResponse::CreatePayToSelfWithOutputs { transaction: Box::new(transaction), @@ -1980,7 +1975,7 @@ where Covenant::default(), self.resources.interactive_tari_address.clone(), ) - .with_payment_id(PaymentId::Open("Pay to self transaction".as_bytes().to_vec())); + .with_payment_id(PaymentId::open_from_str("Pay to self transaction")); let mut stp = builder .build() @@ -2410,10 +2405,10 @@ where self.resources.key_manager.clone(), ); tx_builder - .with_payment_id(PaymentId::Open(format!( + .with_payment_id(PaymentId::open_from_str(&format!( "Coin split transaction, {} into {} outputs", accumulated_amount, number_of_splits - ).as_bytes().to_vec())) + ))) .with_lock_height(0) .with_fee_per_gram(fee_per_gram) .with_kernel_features(KernelFeatures::empty()); @@ -2573,10 +2568,10 @@ where self.resources.key_manager.clone(), ); tx_builder - .with_payment_id(PaymentId::Open( format!( + .with_payment_id(PaymentId::open_from_str(&format!( "Coin split transaction, {} into {} outputs", accumulated_amount, number_of_splits - ).as_bytes().to_vec())) + ))) .with_lock_height(0) .with_fee_per_gram(fee_per_gram) .with_kernel_features(KernelFeatures::empty()); @@ -2809,11 +2804,11 @@ where self.resources.key_manager.clone(), ); tx_builder - .with_payment_id(PaymentId::Open(format!( + .with_payment_id(PaymentId::open_from_str(&format!( "Coin join transaction, {} outputs{} into", src_outputs.len(), accumulated_amount - ).as_bytes().to_vec())) + ))) .with_lock_height(0) .with_fee_per_gram(fee_per_gram) .with_kernel_features(KernelFeatures::empty()); @@ -3021,7 +3016,7 @@ where builder .with_lock_height(0) .with_fee_per_gram(fee_per_gram) - .with_payment_id(PaymentId::Open("SHA-XTR atomic swap".as_bytes().to_vec())) + .with_payment_id(PaymentId::open_from_str("SHA-XTR atomic swap")) .with_kernel_features(KernelFeatures::empty()) .with_prevent_fee_gt_amount(self.resources.config.prevent_fee_gt_amount) .with_input(rewound_output) @@ -3104,7 +3099,7 @@ where builder .with_lock_height(0) .with_fee_per_gram(fee_per_gram) - .with_payment_id(PaymentId::Open("SHA-XTR atomic refund".as_bytes().to_vec())) + .with_payment_id(PaymentId::open_from_str("SHA-XTR atomic refund")) .with_kernel_features(KernelFeatures::empty()) .with_prevent_fee_gt_amount(self.resources.config.prevent_fee_gt_amount) .with_input(output) diff --git a/base_layer/wallet/src/transaction_service/handle.rs b/base_layer/wallet/src/transaction_service/handle.rs index 897db9205ca..3c1244e2c35 100644 --- a/base_layer/wallet/src/transaction_service/handle.rs +++ b/base_layer/wallet/src/transaction_service/handle.rs @@ -235,11 +235,7 @@ impl fmt::Display for TransactionServiceRequest { "SendTransaction (amount: {}, to: {}, payment_id: {})", amount, destination, payment_id ), - Self::BurnTari { - amount, - payment_id, - .. - } => write!(f, "Burning Tari ({}, {})", amount, payment_id), + Self::BurnTari { amount, payment_id, .. } => write!(f, "Burning Tari ({}, {})", amount, payment_id), Self::SpendBackupPreMineUtxo { fee_per_gram, output_hash, @@ -665,7 +661,7 @@ impl TransactionServiceHandle { validator_node_signature: Signature, selection_criteria: UtxoSelectionCriteria, fee_per_gram: MicroMinotari, - payment_id: PaymentId + payment_id: PaymentId, ) -> Result { match self .handle diff --git a/base_layer/wallet/src/transaction_service/service.rs b/base_layer/wallet/src/transaction_service/service.rs index e5792eb117f..f51b54fc56a 100644 --- a/base_layer/wallet/src/transaction_service/service.rs +++ b/base_layer/wallet/src/transaction_service/service.rs @@ -825,7 +825,7 @@ where binary_url, }, UtxoSelectionCriteria::default(), - PaymentId::Open( format!("Template Registration: {}", template_name).as_bytes().to_vec()), + PaymentId::open_from_str(&format!("Template Registration: {}", template_name)), send_transaction_join_handles, transaction_broadcast_join_handles, reply_channel.take().expect("Reply channel is not set"), @@ -930,14 +930,7 @@ where .await .map(TransactionServiceResponse::UtxoImported), TransactionServiceRequest::SubmitTransactionToSelf(tx_id, tx, fee, amount, payment_id) => self - .submit_transaction_to_self( - transaction_broadcast_join_handles, - tx_id, - tx, - fee, - amount, - payment_id, - ) + .submit_transaction_to_self(transaction_broadcast_join_handles, tx_id, tx, fee, amount, payment_id) .await .map(|_| TransactionServiceResponse::TransactionSubmitted), TransactionServiceRequest::SetLowPowerMode => { @@ -3066,7 +3059,11 @@ where amount = Some(ro.output.value); } }, - PaymentId::ChangeInfo { recipient_address, amount: tx_amount, user_data: _user_data } => { + PaymentId::ChangeInfo { + recipient_address, + amount: tx_amount, + user_data: _user_data, + } => { source_address = Some(recipient_address.clone()); payment_id = Some(ro.output.payment_id.clone()); amount = Some(*tx_amount); diff --git a/base_layer/wallet/src/transaction_service/storage/sqlite_db.rs b/base_layer/wallet/src/transaction_service/storage/sqlite_db.rs index 5373f750af1..d4008e90d17 100644 --- a/base_layer/wallet/src/transaction_service/storage/sqlite_db.rs +++ b/base_layer/wallet/src/transaction_service/storage/sqlite_db.rs @@ -2280,7 +2280,7 @@ mod test { builder .with_lock_height(0) .with_fee_per_gram(MicroMinotari::from(177 / 5)) - .with_payment_id(PaymentId::Open("Yo!".as_bytes().to_vec())) + .with_payment_id(PaymentId::open_from_str("Yo!")) .with_input(input) .await .unwrap() @@ -2315,7 +2315,7 @@ mod test { fee: stp.get_fee_amount().unwrap(), sender_protocol: stp.clone(), status: TransactionStatus::Pending, - payment_id: PaymentId::Open("Yo!".as_bytes().to_vec()), + payment_id: PaymentId::open_from_str("Yo!"), timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -2334,7 +2334,7 @@ mod test { fee: stp.get_fee_amount().unwrap(), sender_protocol: stp.clone(), status: TransactionStatus::Pending, - payment_id: PaymentId::Open("Yo!".as_bytes().to_vec()), + payment_id: PaymentId::open_from_str("Yo!"), timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -2400,7 +2400,7 @@ mod test { amount, receiver_protocol: rtp.clone(), status: TransactionStatus::Pending, - payment_id: PaymentId::Open("Yo!".as_bytes().to_vec()), + payment_id: PaymentId::open_from_str("Yo!"), timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -2418,7 +2418,7 @@ mod test { amount, receiver_protocol: rtp, status: TransactionStatus::Pending, - payment_id: PaymentId::Open("Yo!".as_bytes().to_vec()), + payment_id: PaymentId::open_from_str("Yo!"), timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -2479,7 +2479,7 @@ mod test { fee: MicroMinotari::from(100), transaction: tx.clone(), status: TransactionStatus::MinedUnconfirmed, - payment_id: PaymentId::Open("Yo!".as_bytes().to_vec()), + timestamp: Utc::now().naive_utc(), cancelled: None, direction: TransactionDirection::Unknown, send_count: 0, @@ -2489,7 +2489,7 @@ mod test { mined_height: None, mined_in_block: None, mined_timestamp: None, - payment_id: PaymentId::Empty, + payment_id: PaymentId::open_from_str("Yo!"), }; let source_address = TariAddress::new_dual_address_with_default_features( PublicKey::from_secret_key(&PrivateKey::random(&mut OsRng)), @@ -2509,7 +2509,7 @@ mod test { fee: MicroMinotari::from(100), transaction: tx.clone(), status: TransactionStatus::Broadcast, - payment_id: PaymentId::Open("Yo!".as_bytes().to_vec()), + timestamp: Utc::now().naive_utc(), cancelled: None, direction: TransactionDirection::Unknown, send_count: 0, @@ -2519,7 +2519,7 @@ mod test { mined_height: None, mined_in_block: None, mined_timestamp: None, - payment_id: PaymentId::Empty, + payment_id: PaymentId::open_from_str("Yo!"), }; CompletedTransactionSql::try_from(completed_tx1.clone(), &cipher) @@ -2679,7 +2679,7 @@ mod test { amount: MicroMinotari::from(100), receiver_protocol: ReceiverTransactionProtocol::new_placeholder(), status: TransactionStatus::Pending, - payment_id: PaymentId::Open("Yo!".as_bytes().to_vec()), + payment_id: PaymentId::open_from_str("Yo!"), timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -2707,7 +2707,7 @@ mod test { fee: MicroMinotari::from(10), sender_protocol: SenderTransactionProtocol::new_placeholder(), status: TransactionStatus::Pending, - payment_id: PaymentId::Open("Yo!".as_bytes().to_vec()), + payment_id: PaymentId::open_from_str("Yo!"), timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -2758,7 +2758,7 @@ mod test { mined_height: None, mined_in_block: None, mined_timestamp: None, - payment_id: PaymentId::Open("Yo!".as_bytes().to_vec()), + payment_id: PaymentId::open_from_str("Yo!"), }; let completed_tx_sql = CompletedTransactionSql::try_from(completed_tx.clone(), &cipher).unwrap(); @@ -2822,7 +2822,7 @@ mod test { amount: MicroMinotari::from(100), receiver_protocol: ReceiverTransactionProtocol::new_placeholder(), status: TransactionStatus::Pending, - payment_id: PaymentId::Open("Yo!".as_bytes().to_vec()), + payment_id: PaymentId::open_from_str("Yo!"), timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -2845,7 +2845,7 @@ mod test { fee: MicroMinotari::from(10), sender_protocol: SenderTransactionProtocol::new_placeholder(), status: TransactionStatus::Pending, - payment_id: PaymentId::Open("Yo!".as_bytes().to_vec()), + payment_id: PaymentId::open_from_str("Yo!"), timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -2890,7 +2890,7 @@ mod test { mined_height: None, mined_in_block: None, mined_timestamp: None, - payment_id: PaymentId::Open("Yo!".as_bytes().to_vec()), + payment_id: PaymentId::open_from_str("Yo!"), }; let completed_tx_sql = CompletedTransactionSql::try_from(completed_tx, &cipher).unwrap(); @@ -3032,7 +3032,7 @@ mod test { mined_height: None, mined_in_block: None, mined_timestamp: None, - payment_id: PaymentId::Open("Yo!".as_bytes().to_vec()), + payment_id: PaymentId::open_from_str("Yo!"), }; let completed_tx_sql = CompletedTransactionSql::try_from(completed_tx.clone(), &cipher).unwrap(); diff --git a/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs b/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs index 53d61e8f861..fb964001544 100644 --- a/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs +++ b/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs @@ -605,7 +605,7 @@ where .await? .into_iter() .map(|ro| -> Result<_, UtxoScannerError> { - let status = if ro.output.features.is_coinbase() { + let status = if ro.output.features.is_coinbase() { ImportStatus::CoinbaseUnconfirmed } else { ImportStatus::OneSidedUnconfirmed diff --git a/base_layer/wallet/tests/output_manager_service_tests/service.rs b/base_layer/wallet/tests/output_manager_service_tests/service.rs index 065e150a5cd..2a2e2ba2a39 100644 --- a/base_layer/wallet/tests/output_manager_service_tests/service.rs +++ b/base_layer/wallet/tests/output_manager_service_tests/service.rs @@ -438,7 +438,6 @@ async fn test_utxo_selection_no_chain_metadata() { OutputFeatures::default(), fee_per_gram, TransactionMetadata::default(), - String::new(), script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), diff --git a/base_layer/wallet/tests/transaction_service_tests/service.rs b/base_layer/wallet/tests/transaction_service_tests/service.rs index 4f78ab142e4..0fd5649920f 100644 --- a/base_layer/wallet/tests/transaction_service_tests/service.rs +++ b/base_layer/wallet/tests/transaction_service_tests/service.rs @@ -609,7 +609,6 @@ async fn manage_single_transaction() { UtxoSelectionCriteria::default(), OutputFeatures::default(), MicroMinotari::from(4), - "".to_string(), PaymentId::Empty, ) .await @@ -620,7 +619,6 @@ async fn manage_single_transaction() { .mark_outputs_as_unspent(vec![(uo1.hash(&alice_key_manager_handle).await.unwrap(), true)]) .unwrap(); - let message = "TAKE MAH MONEYS!".to_string(); alice_ts .send_transaction( bob_address, @@ -628,8 +626,7 @@ async fn manage_single_transaction() { UtxoSelectionCriteria::default(), OutputFeatures::default(), MicroMinotari::from(4), - message, - PaymentId::Empty, + PaymentId::open_from_str("TAKE MAH MONEYS!"), ) .await .expect("Alice sending tx"); @@ -779,7 +776,6 @@ async fn large_interactive_transaction() { let bob_address = TariAddress::new_single_address_with_interactive_only(bob_node_identity.public_key().clone(), network); - let message = "TAKE MAH MONEYS!".to_string(); alice_ts .send_transaction( bob_address, @@ -787,8 +783,7 @@ async fn large_interactive_transaction() { UtxoSelectionCriteria::default(), OutputFeatures::default(), MicroMinotari::from(1), - message, - PaymentId::Empty, + PaymentId::open_from_str("TAKE MAH MONEYS!"), ) .await .expect("Alice sending large tx"); @@ -939,7 +934,6 @@ async fn test_spend_dust_to_self_in_oversized_transaction() { // Alice try to spend too much dust to self let fee_per_gram = MicroMinotari::from(1); - let message = "TAKE MAH _OWN_ MONEYS!".to_string(); let value = balance.available_balance - amount_per_output * 10; let alice_address = TariAddress::new_single_address_with_interactive_only(alice_node_identity.public_key().clone(), network); @@ -950,8 +944,7 @@ async fn test_spend_dust_to_self_in_oversized_transaction() { UtxoSelectionCriteria::default(), OutputFeatures::default(), fee_per_gram, - message.clone(), - PaymentId::Empty, + PaymentId::open_from_str("TAKE MAH _OWN_ MONEYS!"), ) .await .is_err()); @@ -1038,7 +1031,6 @@ async fn test_spend_dust_to_other_in_oversized_transaction() { // Alice try to spend too much dust to Bob let fee_per_gram = MicroMinotari::from(1); - let message = "GIVE MAH _OWN_ MONEYS AWAY!".to_string(); let value = balance.available_balance - amount_per_output * 10; let bob_address = TariAddress::new_single_address_with_interactive_only(bob_node_identity.public_key().clone(), network); @@ -1049,8 +1041,7 @@ async fn test_spend_dust_to_other_in_oversized_transaction() { UtxoSelectionCriteria::default(), OutputFeatures::default(), fee_per_gram, - message.clone(), - PaymentId::Empty, + PaymentId::open_from_str("GIVE MAH _OWN_ MONEYS AWAY!"), ) .await .unwrap(); @@ -1155,7 +1146,6 @@ async fn test_spend_dust_happy_path() { // Alice try to spend a fair amount of dust to self [should succeed] (we just need to verify that the // transaction is created and that the available balance is correct) - let message = "TAKE MAH _OWN_ MONEYS!".to_string(); let value_self = (number_of_outputs / 3) * amount_per_output; let alice_address = TariAddress::new_single_address_with_interactive_only(alice_node_identity.public_key().clone(), network); @@ -1166,8 +1156,7 @@ async fn test_spend_dust_happy_path() { UtxoSelectionCriteria::default(), OutputFeatures::default(), fee_per_gram, - message.clone(), - PaymentId::Empty, + PaymentId::open_from_str("TAKE MAH _OWN_ MONEYS!"), ) .await .unwrap(); @@ -1201,7 +1190,6 @@ async fn test_spend_dust_happy_path() { // Alice try to spend a fair amount of dust to Bob [should succeed] (We do not need Bob to be present, // we just need to verify that the transaction is created and that the available balance is correct) - let message = "GIVE MAH _OWN_ MONEYS AWAY!".to_string(); let value_bob = (number_of_outputs / 3) * amount_per_output; let bob_address = TariAddress::new_single_address_with_interactive_only(bob_node_identity.public_key().clone(), network); @@ -1212,8 +1200,7 @@ async fn test_spend_dust_happy_path() { UtxoSelectionCriteria::default(), OutputFeatures::default(), fee_per_gram, - message.clone(), - PaymentId::Empty, + PaymentId::open_from_str("GIVE MAH _OWN_ MONEYS AWAY!"), ) .await .unwrap(); @@ -1303,7 +1290,6 @@ async fn single_transaction_to_self() { alice_db .mark_outputs_as_unspent(vec![(uo1.hash(&key_manager_handle).await.unwrap(), true)]) .unwrap(); - let message = "TAKE MAH _OWN_ MONEYS!".to_string(); let value = 10000.into(); let alice_address = TariAddress::new_single_address_with_interactive_only(alice_node_identity.public_key().clone(), network); @@ -1314,8 +1300,7 @@ async fn single_transaction_to_self() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 20.into(), - message.clone(), - PaymentId::Empty, + PaymentId::open_from_str("TAKE MAH _OWN_ MONEYS!"), ) .await .expect("Alice sending tx"); @@ -1404,8 +1389,7 @@ async fn large_coin_split_transaction() { tx_id, coin_split_tx, amount, - "large coin-split".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("large coin-split"), ) .await .expect("Alice sending coin-split tx"); @@ -1630,7 +1614,6 @@ async fn send_one_sided_transaction_to_other() { .mark_outputs_as_unspent(vec![(uo1.hash(&key_manager_handle).await.unwrap(), true)]) .unwrap(); - let message = "SEE IF YOU CAN CATCH THIS ONE..... SIDED TX!".to_string(); let value = 10000.into(); let mut alice_ts_clone = alice_ts.clone(); let random_pvt_key = PrivateKey::random(&mut OsRng); @@ -1647,8 +1630,7 @@ async fn send_one_sided_transaction_to_other() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 20.into(), - message.clone(), - PaymentId::Empty, + PaymentId::open_from_str("SEE IF YOU CAN CATCH THIS ONE..... SIDED TX!"), ) .await .expect("Alice sending one-sided tx to Bob"); @@ -1780,7 +1762,6 @@ async fn recover_one_sided_transaction() { .mark_outputs_as_unspent(vec![(uo1.hash(&alice_key_manager_handle).await.unwrap(), true)]) .unwrap(); - let message = "".to_string(); let value = 10000.into(); let mut alice_ts_clone = alice_ts.clone(); let bob_view_key = bob_key_manager_handle.get_view_key().await.unwrap(); @@ -1796,7 +1777,6 @@ async fn recover_one_sided_transaction() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 20.into(), - message.clone(), PaymentId::Empty, ) .await @@ -1907,7 +1887,6 @@ async fn recover_stealth_one_sided_transaction() { .mark_outputs_as_unspent(vec![(uo1.hash(&alice_key_manager_handle).await.unwrap(), true)]) .unwrap(); - let message = "".to_string(); let value = 10000.into(); let mut alice_ts_clone = alice_ts.clone(); @@ -1923,7 +1902,6 @@ async fn recover_stealth_one_sided_transaction() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 20.into(), - message.clone(), PaymentId::Empty, ) .await @@ -2021,7 +1999,6 @@ async fn test_htlc_send_and_claim() { .mark_outputs_as_unspent(vec![(uo1.hash(&key_manager_handle).await.unwrap(), true)]) .unwrap(); - let message = "".to_string(); let value = 10000.into(); let bob_pubkey = bob_ts_interface.base_node_identity.public_key().clone(); let bob_view_key = bob_ts_interface.key_manager_handle.get_view_key().await.unwrap(); @@ -2033,7 +2010,7 @@ async fn test_htlc_send_and_claim() { value, UtxoSelectionCriteria::default(), 20.into(), - message.clone(), + PaymentId::Empty, ) .await .expect("Alice sending HTLC transaction"); @@ -2076,7 +2053,7 @@ async fn test_htlc_send_and_claim() { bob_ts_interface .transaction_service_handle - .submit_transaction(tx_id_htlc, tx, htlc_amount, "".to_string(), PaymentId::Empty) + .submit_transaction(tx_id_htlc, tx, htlc_amount, PaymentId::Empty) .await .unwrap(); assert_eq!( @@ -2272,8 +2249,7 @@ async fn manage_multiple_transactions() { UtxoSelectionCriteria::default(), OutputFeatures::default(), MicroMinotari::from(20), - "a to b 1".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("a to b 1"), ) .await .unwrap(); @@ -2290,8 +2266,7 @@ async fn manage_multiple_transactions() { UtxoSelectionCriteria::default(), OutputFeatures::default(), MicroMinotari::from(20), - "a to c 1".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("a to c 1"), ) .await .unwrap(); @@ -2310,8 +2285,7 @@ async fn manage_multiple_transactions() { UtxoSelectionCriteria::default(), OutputFeatures::default(), MicroMinotari::from(20), - "b to a 1".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("b to a 1"), ) .await .unwrap(); @@ -2322,8 +2296,7 @@ async fn manage_multiple_transactions() { UtxoSelectionCriteria::default(), OutputFeatures::default(), MicroMinotari::from(20), - "a to b 2".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("a to b 2"), ) .await .unwrap(); @@ -2468,7 +2441,6 @@ async fn test_accepting_unknown_tx_id_and_malformed_reply() { UtxoSelectionCriteria::default(), OutputFeatures::default(), MicroMinotari::from(20), - "".to_string(), PaymentId::Empty, ) .await @@ -2570,7 +2542,6 @@ async fn finalize_tx_with_incorrect_pubkey() { OutputFeatures::default(), MicroMinotari::from(25), TransactionMetadata::default(), - "".to_string(), script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), @@ -2701,7 +2672,6 @@ async fn finalize_tx_with_missing_output() { OutputFeatures::default(), MicroMinotari::from(20), TransactionMetadata::default(), - "".to_string(), script!(Nop).unwrap(), Covenant::default(), MicroMinotari::zero(), @@ -2904,8 +2874,7 @@ async fn discovery_async_return_test() { UtxoSelectionCriteria::default(), OutputFeatures::default(), MicroMinotari::from(20), - "Discovery Tx!".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Discovery Tx!"), ) .await .unwrap(); @@ -2944,8 +2913,7 @@ async fn discovery_async_return_test() { UtxoSelectionCriteria::default(), OutputFeatures::default(), MicroMinotari::from(20), - "Discovery Tx2!".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Discovery Tx2!"), ) .await .unwrap(); @@ -3036,7 +3004,6 @@ async fn test_power_mode_updates() { fee: MicroMinotari::from(100), transaction: tx.clone(), status: TransactionStatus::Completed, - message: "Yo!".to_string(), timestamp: Utc::now().naive_utc(), cancelled: None, direction: TransactionDirection::Outbound, @@ -3047,7 +3014,7 @@ async fn test_power_mode_updates() { mined_height: None, mined_in_block: None, mined_timestamp: None, - payment_id: PaymentId::Empty, + payment_id: PaymentId::open_from_str("Yo!"), }; let source_address = TariAddress::new_dual_address_with_default_features( @@ -3068,7 +3035,6 @@ async fn test_power_mode_updates() { fee: MicroMinotari::from(200), transaction: tx.clone(), status: TransactionStatus::Completed, - message: "Yo!".to_string(), timestamp: Utc::now().naive_utc(), cancelled: None, direction: TransactionDirection::Outbound, @@ -3079,7 +3045,7 @@ async fn test_power_mode_updates() { mined_height: None, mined_in_block: None, mined_timestamp: None, - payment_id: PaymentId::Empty, + payment_id: PaymentId::open_from_str("Yo!"), }; tx_backend @@ -3253,8 +3219,7 @@ async fn test_transaction_cancellation() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 100 * uT, - "Testing Message".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Testing Message"), ) .await .unwrap(); @@ -3360,7 +3325,7 @@ async fn test_transaction_cancellation() { builder .with_lock_height(0) .with_fee_per_gram(MicroMinotari::from(5)) - .with_payment_id(PaymentId::Open("Yo!".as_bytes().to_vec())) + .with_payment_id(PaymentId::open_from_str("Yo!")) .with_input(input) .await .unwrap() @@ -3447,7 +3412,7 @@ async fn test_transaction_cancellation() { builder .with_lock_height(0) .with_fee_per_gram(MicroMinotari::from(5)) - .with_payment_id(PaymentId::Open("Yo!".as_bytes().to_vec())) + .with_payment_id(PaymentId::open_from_str("Yo!")) .with_input(input) .await .unwrap() @@ -3604,8 +3569,7 @@ async fn test_direct_vs_saf_send_of_tx_reply_and_finalize() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 100 * uT, - "Testing Message".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Testing Message"), ) .await .unwrap(); @@ -3807,8 +3771,7 @@ async fn test_direct_vs_saf_send_of_tx_reply_and_finalize() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 100 * uT, - "Testing Message".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Testing Message"), ) .await .unwrap(); @@ -3997,8 +3960,7 @@ async fn test_tx_direct_send_behaviour() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 100 * uT, - "Testing Message1".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Testing Message1"), ) .await .unwrap(); @@ -4042,8 +4004,7 @@ async fn test_tx_direct_send_behaviour() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 100 * uT, - "Testing Message2".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Testing Message2"), ) .await .unwrap(); @@ -4092,8 +4053,7 @@ async fn test_tx_direct_send_behaviour() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 100 * uT, - "Testing Message3".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Testing Message3"), ) .await .unwrap(); @@ -4142,8 +4102,7 @@ async fn test_tx_direct_send_behaviour() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 100 * uT, - "Testing Message4".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Testing Message4"), ) .await .unwrap(); @@ -4284,8 +4243,7 @@ async fn test_restarting_transaction_protocols() { amount: msg.amount, receiver_protocol, status: TransactionStatus::Pending, - message: msg.message.clone(), - payment_id: Default::default(), + payment_id: msg.payment_id.clone(), timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -4312,8 +4270,7 @@ async fn test_restarting_transaction_protocols() { fee, sender_protocol: bob_pre_finalize, status: TransactionStatus::Pending, - message: msg.message, - payment_id: PaymentId::Empty, + payment_id: msg.payment_id, timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -4472,8 +4429,7 @@ async fn test_transaction_resending() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 100 * uT, - "Testing Message".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Testing Message"), ) .await .unwrap(); @@ -4661,7 +4617,7 @@ async fn test_resend_on_startup() { builder .with_lock_height(0) .with_fee_per_gram(MicroMinotari::from(177 / 5)) - .with_payment_id(PaymentId::Open("Yo!".as_bytes().to_vec())) + .with_payment_id(PaymentId::open_from_str("Yo!")) .with_input(input) .await .unwrap() @@ -4701,8 +4657,7 @@ async fn test_resend_on_startup() { fee: stp.get_fee_amount().unwrap(), sender_protocol: stp, status: TransactionStatus::Pending, - message: "Yo!".to_string(), - payment_id: PaymentId::Empty, + payment_id: PaymentId::open_from_str("Yo!"), timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -4835,8 +4790,7 @@ async fn test_resend_on_startup() { amount, receiver_protocol: rtp, status: TransactionStatus::Pending, - message: "Yo2".to_string(), - payment_id: Default::default(), + payment_id: PaymentId::open_from_str("Yo2"), timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -4998,8 +4952,7 @@ async fn test_replying_to_cancelled_tx() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 100 * uT, - "Testing Message".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Testing Message"), ) .await .unwrap(); @@ -5139,8 +5092,7 @@ async fn test_transaction_timeout_cancellation() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 20 * uT, - "Testing Message".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Testing Message"), ) .await .unwrap(); @@ -5195,7 +5147,7 @@ async fn test_transaction_timeout_cancellation() { builder .with_lock_height(0) .with_fee_per_gram(MicroMinotari::from(177 / 5)) - .with_payment_id(PaymentId::Open("Yo!".as_bytes().to_vec())) + .with_payment_id(PaymentId::open_from_str("Yo!")) .with_input(input) .await .unwrap() @@ -5235,8 +5187,7 @@ async fn test_transaction_timeout_cancellation() { fee: stp.get_fee_amount().unwrap(), sender_protocol: stp, status: TransactionStatus::Pending, - message: "Yo!".to_string(), - payment_id: PaymentId::Empty, + payment_id: PaymentId::open_from_str("Yo!"), timestamp: Utc::now() .naive_utc() .checked_sub_signed(ChronoDuration::seconds(20)) @@ -5439,8 +5390,7 @@ async fn transaction_service_tx_broadcast() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 100 * uT, - "Testing Message".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Testing Message"), ) .await .unwrap(); @@ -5501,8 +5451,7 @@ async fn transaction_service_tx_broadcast() { UtxoSelectionCriteria::default(), OutputFeatures::default(), 20 * uT, - "Testing Message2".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("Testing Message2"), ) .await .unwrap(); @@ -5783,7 +5732,6 @@ async fn broadcast_all_completed_transactions_on_startup() { fee: MicroMinotari::from(20), transaction: tx.clone(), status: TransactionStatus::Completed, - message: "Yo!".to_string(), timestamp: Utc::now().naive_utc(), cancelled: None, direction: TransactionDirection::Outbound, @@ -5794,7 +5742,7 @@ async fn broadcast_all_completed_transactions_on_startup() { mined_height: None, mined_in_block: None, mined_timestamp: None, - payment_id: PaymentId::Empty, + payment_id: PaymentId::open_from_str("Yo!"), }; let completed_tx2 = CompletedTransaction { @@ -5925,7 +5873,6 @@ async fn test_update_faux_tx_on_oms_validation() { .import_utxo_with_status( MicroMinotari::from(10000), alice_address.clone(), - "blah".to_string(), ImportStatus::Imported, None, None, @@ -5933,7 +5880,7 @@ async fn test_update_faux_tx_on_oms_validation() { uo_1.to_transaction_output(&alice_ts_interface.key_manager_handle) .await .unwrap(), - PaymentId::Empty, + PaymentId::open_from_str("blah"), ) .await .unwrap(); @@ -5942,7 +5889,6 @@ async fn test_update_faux_tx_on_oms_validation() { .import_utxo_with_status( MicroMinotari::from(20000), alice_address.clone(), - "one-sided 1".to_string(), ImportStatus::OneSidedUnconfirmed, None, None, @@ -5950,7 +5896,7 @@ async fn test_update_faux_tx_on_oms_validation() { uo_2.to_transaction_output(&alice_ts_interface.key_manager_handle) .await .unwrap(), - PaymentId::Empty, + PaymentId::open_from_str("one-sided 1"), ) .await .unwrap(); @@ -5959,7 +5905,6 @@ async fn test_update_faux_tx_on_oms_validation() { .import_utxo_with_status( MicroMinotari::from(30000), alice_address, - "one-sided 2".to_string(), ImportStatus::OneSidedConfirmed, None, None, @@ -5967,7 +5912,7 @@ async fn test_update_faux_tx_on_oms_validation() { uo_3.to_transaction_output(&alice_ts_interface.key_manager_handle) .await .unwrap(), - PaymentId::Empty, + PaymentId::open_from_str("one-sided 2"), ) .await .unwrap(); @@ -6103,7 +6048,6 @@ async fn test_update_coinbase_tx_on_oms_validation() { .import_utxo_with_status( MicroMinotari::from(10000), alice_address.clone(), - "coinbase_confirmed".to_string(), ImportStatus::CoinbaseConfirmed, None, None, @@ -6111,7 +6055,7 @@ async fn test_update_coinbase_tx_on_oms_validation() { uo_1.to_transaction_output(&alice_ts_interface.key_manager_handle) .await .unwrap(), - PaymentId::Empty, + PaymentId::open_from_str("coinbase_confirmed"), ) .await .unwrap(); @@ -6120,7 +6064,6 @@ async fn test_update_coinbase_tx_on_oms_validation() { .import_utxo_with_status( MicroMinotari::from(20000), alice_address.clone(), - "one-coinbase_unconfirmed 1".to_string(), ImportStatus::CoinbaseUnconfirmed, None, None, @@ -6128,7 +6071,7 @@ async fn test_update_coinbase_tx_on_oms_validation() { uo_2.to_transaction_output(&alice_ts_interface.key_manager_handle) .await .unwrap(), - PaymentId::Empty, + PaymentId::open_from_str("one-coinbase_unconfirmed 1"), ) .await .unwrap(); @@ -6137,7 +6080,6 @@ async fn test_update_coinbase_tx_on_oms_validation() { .import_utxo_with_status( MicroMinotari::from(30000), alice_address, - "Coinbase_not_mined".to_string(), ImportStatus::CoinbaseUnconfirmed, None, None, @@ -6145,7 +6087,7 @@ async fn test_update_coinbase_tx_on_oms_validation() { uo_3.to_transaction_output(&alice_ts_interface.key_manager_handle) .await .unwrap(), - PaymentId::Empty, + PaymentId::open_from_str("Coinbase_not_mined"), ) .await .unwrap(); diff --git a/base_layer/wallet/tests/transaction_service_tests/storage.rs b/base_layer/wallet/tests/transaction_service_tests/storage.rs index 9e826fec9a7..4a6fc74e297 100644 --- a/base_layer/wallet/tests/transaction_service_tests/storage.rs +++ b/base_layer/wallet/tests/transaction_service_tests/storage.rs @@ -92,7 +92,7 @@ pub async fn test_db_backend(backend: T) { builder .with_lock_height(0) .with_fee_per_gram(MicroMinotari::from(177 / 5)) - .with_payment_id(PaymentId::Open("Yo!".as_bytes().to_vec())) + .with_payment_id(PaymentId::open_from_str("Yo!")) .with_input(input) .await .unwrap() @@ -118,7 +118,7 @@ pub async fn test_db_backend(backend: T) { let stp = builder.build().await.unwrap(); - let messages = ["Hey!".to_string(), "Yo!".to_string(), "Sup!".to_string()]; + let messages = ["Hey!", "Yo!", "Sup!"]; let amounts = [ MicroMinotari::from(10_000), MicroMinotari::from(23_000), @@ -141,8 +141,7 @@ pub async fn test_db_backend(backend: T) { fee: stp.clone().get_fee_amount().unwrap(), sender_protocol: stp.clone(), status: TransactionStatus::Pending, - message: messages[i].clone(), - payment_id: PaymentId::Empty, + payment_id: PaymentId::open_from_str(messages[i]), timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -255,8 +254,7 @@ pub async fn test_db_backend(backend: T) { amount: amounts[i], receiver_protocol: rtp.clone(), status: TransactionStatus::Pending, - message: messages[i].clone(), - payment_id: Default::default(), + payment_id: PaymentId::open_from_str(messages[i]), timestamp: Utc::now().naive_utc(), cancelled: false, direct_send_success: false, @@ -336,7 +334,6 @@ pub async fn test_db_backend(backend: T) { 1 => TransactionStatus::Broadcast, _ => TransactionStatus::MinedUnconfirmed, }, - message: messages[i].clone(), timestamp: Utc::now().naive_utc(), cancelled: None, direction: TransactionDirection::Outbound, @@ -348,7 +345,7 @@ pub async fn test_db_backend(backend: T) { mined_height: None, mined_in_block: None, mined_timestamp: None, - payment_id: PaymentId::Empty, + payment_id: PaymentId::open_from_str(messages[i]), }); db.complete_outbound_transaction(outbound_txs[i].tx_id, completed_txs[i].clone()) .unwrap(); @@ -448,8 +445,7 @@ pub async fn test_db_backend(backend: T) { 22 * uT, rtp, TransactionStatus::Pending, - "To be cancelled".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("To be cancelled"), Utc::now().naive_utc(), ), ) @@ -502,8 +498,7 @@ pub async fn test_db_backend(backend: T) { stp.get_fee_amount().unwrap(), stp, TransactionStatus::Pending, - "To be cancelled".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("To be cancelled"), Utc::now().naive_utc(), false, ), @@ -596,12 +591,11 @@ async fn import_tx_and_read_it_from_db() { PrivateKey::random(&mut OsRng), ), TransactionStatus::Imported, - "message".to_string(), Utc::now().naive_utc(), TransactionDirection::Inbound, Some(5), Some(NaiveDateTime::from_timestamp_opt(0, 0).unwrap()), - PaymentId::Empty, + PaymentId::open_from_str("message"), ) .unwrap(); @@ -626,12 +620,11 @@ async fn import_tx_and_read_it_from_db() { PrivateKey::random(&mut OsRng), ), TransactionStatus::OneSidedUnconfirmed, - "message".to_string(), Utc::now().naive_utc(), TransactionDirection::Inbound, Some(6), Some(NaiveDateTime::from_timestamp_opt(0, 0).unwrap()), - PaymentId::Empty, + PaymentId::open_from_str("message"), ) .unwrap(); @@ -656,12 +649,11 @@ async fn import_tx_and_read_it_from_db() { PrivateKey::random(&mut OsRng), ), TransactionStatus::OneSidedConfirmed, - "message".to_string(), Utc::now().naive_utc(), TransactionDirection::Inbound, Some(7), Some(NaiveDateTime::from_timestamp_opt(0, 0).unwrap()), - PaymentId::Empty, + PaymentId::open_from_str("message"), ) .unwrap(); diff --git a/base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs b/base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs index fef5d8c7fa4..6b30ee82478 100644 --- a/base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs +++ b/base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs @@ -231,12 +231,11 @@ pub async fn add_transaction_to_database( 200 * uT, tx1, status.unwrap_or(TransactionStatus::Completed), - "Test".to_string(), Utc::now().naive_local(), TransactionDirection::Outbound, None, None, - PaymentId::Empty, + PaymentId::open_from_str("Test"), ) .unwrap(); db.insert_completed_transaction(tx_id, completed_tx1).unwrap(); diff --git a/base_layer/wallet_ffi/src/callback_handler_tests.rs b/base_layer/wallet_ffi/src/callback_handler_tests.rs index 172f5f4ae7d..72863e14fbd 100644 --- a/base_layer/wallet_ffi/src/callback_handler_tests.rs +++ b/base_layer/wallet_ffi/src/callback_handler_tests.rs @@ -319,8 +319,7 @@ mod test { 22 * uT, rtp, TransactionStatus::Pending, - "1".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("1"), Utc::now().naive_utc(), ); db.add_pending_inbound_transaction(1u64.into(), inbound_tx.clone()) @@ -350,12 +349,11 @@ mod test { PrivateKey::default(), ), TransactionStatus::Completed, - "2".to_string(), Utc::now().naive_utc(), TransactionDirection::Inbound, None, None, - PaymentId::Empty, + PaymentId::open_from_str("2"), ) .unwrap(); db.insert_completed_transaction(2u64.into(), completed_tx.clone()) @@ -374,8 +372,7 @@ mod test { 23 * uT, stp, TransactionStatus::Pending, - "3".to_string(), - PaymentId::Empty, + PaymentId::open_from_str("3"), Utc::now().naive_utc(), false, ); @@ -423,12 +420,11 @@ mod test { PrivateKey::default(), ), TransactionStatus::OneSidedUnconfirmed, - "6".to_string(), Utc::now().naive_utc(), TransactionDirection::Inbound, Some(2), Some(NaiveDateTime::from_timestamp_opt(0, 0).unwrap_or(NaiveDateTime::MIN)), - PaymentId::Empty, + PaymentId::open_from_str("6"), ) .unwrap(); db.insert_completed_transaction(6u64.into(), faux_unconfirmed_tx.clone()) @@ -458,12 +454,11 @@ mod test { PrivateKey::default(), ), TransactionStatus::OneSidedConfirmed, - "7".to_string(), Utc::now().naive_utc(), TransactionDirection::Inbound, Some(5), Some(NaiveDateTime::from_timestamp_opt(0, 0).unwrap()), - PaymentId::Empty, + PaymentId::open_from_str("7"), ) .unwrap(); db.insert_completed_transaction(7u64.into(), faux_confirmed_tx.clone()) diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index 1a3f1282168..42a3d6e26ad 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -2175,7 +2175,7 @@ pub unsafe extern "C" fn wallet_import_external_utxo_as_non_rewindable( .block_on((*wallet).wallet.import_unblinded_output_as_non_rewindable( (*output).clone(), source_address, - PaymentId::Open(payment_id_string.as_bytes().to_vec()) + PaymentId::open_from_str(&payment_id_string), )) { Ok(tx_id) => tx_id.as_u64(), Err(e) => { @@ -4204,7 +4204,7 @@ pub unsafe extern "C" fn completed_transaction_get_payment_id( ptr::swap(error_out, &mut error as *mut c_int); return result.into_raw(); } - match CString::new(payment_id.compact_display()) { + match CString::new(payment_id.user_data_as_string()) { Ok(v) => result = v, _ => { error = LibWalletError::from(InterfaceError::PointerError("payment id".to_string())).code; @@ -4599,7 +4599,7 @@ pub unsafe extern "C" fn pending_outbound_transaction_get_payment_id( return result.into_raw(); } - match CString::new(payment_id.compact_display()) { + match CString::new(payment_id.user_data_as_string()) { Ok(v) => result = v, _ => { error = LibWalletError::from(InterfaceError::PointerError("message".to_string())).code; @@ -4807,7 +4807,7 @@ pub unsafe extern "C" fn pending_inbound_transaction_get_payment_id( return result.into_raw(); } - match CString::new(payment_id.compact_display()) { + match CString::new(payment_id.user_data_as_string()) { Ok(v) => result = v, _ => { error = LibWalletError::from(InterfaceError::PointerError("message".to_string())).code; @@ -7325,11 +7325,7 @@ pub unsafe extern "C" fn wallet_send_transaction( PaymentId::Empty } else { match CStr::from_ptr(payment_id_string).to_str() { - Ok(v) => { - let rust_str = v.to_owned(); - let bytes = rust_str.as_bytes().to_vec(); - PaymentId::Open(bytes) - }, + Ok(v) => PaymentId::open_from_str(v), _ => { error = LibWalletError::from(InterfaceError::NullError("payment_id".to_string())).code; ptr::swap(error_out, &mut error as *mut c_int); diff --git a/base_layer/wallet_ffi/wallet.h b/base_layer/wallet_ffi/wallet.h index 78a32104538..0cf8a8c2d98 100644 --- a/base_layer/wallet_ffi/wallet.h +++ b/base_layer/wallet_ffi/wallet.h @@ -1165,7 +1165,7 @@ struct TariUnblindedOutputs *wallet_get_unspent_outputs(struct TariWallet *walle unsigned long long wallet_import_external_utxo_as_non_rewindable(struct TariWallet *wallet, TariUnblindedOutput *output, TariWalletAddress *source_address, - const char *message, + const char *payment_id, int *error_out); /** @@ -2197,7 +2197,7 @@ unsigned long long completed_transaction_get_timestamp(TariCompletedTransaction int *error_out); /** - * Gets the payment id of a TariCompletedTransaction + * Gets the payment ID of a TariCompletedTransaction * * ## Arguments * `transaction` - The pointer to a TariCompletedTransaction @@ -2429,7 +2429,7 @@ unsigned long long pending_outbound_transaction_get_timestamp(TariPendingOutboun * leak */ const char *pending_outbound_transaction_get_payment_id(TariPendingOutboundTransaction *transaction, - int *error_out); + int *error_out); /** * Gets the status of a TariPendingOutboundTransaction @@ -2544,7 +2544,7 @@ unsigned long long pending_inbound_transaction_get_timestamp(TariPendingInboundT int *error_out); /** - * Gets the message of a TariPendingInboundTransaction + * Gets the payment ID of a TariPendingInboundTransaction * * ## Arguments * `transaction` - The pointer to a TariPendingInboundTransaction @@ -2560,7 +2560,7 @@ unsigned long long pending_inbound_transaction_get_timestamp(TariPendingInboundT * leak */ const char *pending_inbound_transaction_get_payment_id(TariPendingInboundTransaction *transaction, - int *error_out); + int *error_out); /** * Gets the status of a TariPendingInboundTransaction @@ -3436,7 +3436,6 @@ unsigned long long wallet_send_transaction(struct TariWallet *wallet, unsigned long long amount, struct TariVector *commitments, unsigned long long fee_per_gram, - const char *message, bool one_sided, const char *payment_id_string, int *error_out); diff --git a/integration_tests/src/ffi/wallet.rs b/integration_tests/src/ffi/wallet.rs index c4203a413c6..266d8f26250 100644 --- a/integration_tests/src/ffi/wallet.rs +++ b/integration_tests/src/ffi/wallet.rs @@ -31,6 +31,7 @@ use callbacks::Callbacks; use indexmap::IndexMap; use libc::{c_ulonglong, c_void}; use tari_common_types::tari_address::TariAddress; +use tari_core::transactions::transaction_components::encrypted_data::PaymentId; use super::{ ffi_import::{ @@ -371,7 +372,7 @@ impl Wallet { dest: String, amount: u64, fee_per_gram: u64, - message: String, + payment_id: PaymentId, one_sided: bool, ) -> u64 { let tx_id; @@ -383,9 +384,8 @@ impl Wallet { amount, null_mut(), fee_per_gram, - CString::new(message).unwrap().into_raw(), one_sided, - CString::new("").unwrap().into_raw(), + CString::new(payment_id.user_data_as_string()).unwrap().into_raw(), &mut error, ); if error > 0 { diff --git a/integration_tests/src/wallet_ffi.rs b/integration_tests/src/wallet_ffi.rs index 25c9ef737b3..7d054d9f3a8 100644 --- a/integration_tests/src/wallet_ffi.rs +++ b/integration_tests/src/wallet_ffi.rs @@ -32,6 +32,7 @@ use chrono::{DateTime, Utc}; use indexmap::IndexMap; use libc::c_void; use tari_common_types::tari_address::TariAddress; +use tari_core::transactions::transaction_components::encrypted_data::PaymentId; use super::ffi::{ Balance, @@ -167,13 +168,13 @@ impl WalletFFI { dest: String, amount: u64, fee_per_gram: u64, - message: String, + payment_id: PaymentId, one_sided: bool, ) -> u64 { self.wallet .lock() .unwrap() - .send_transaction(dest, amount, fee_per_gram, message, one_sided) + .send_transaction(dest, amount, fee_per_gram, payment_id, one_sided) } pub fn restart(&mut self) { diff --git a/integration_tests/tests/steps/wallet_cli_steps.rs b/integration_tests/tests/steps/wallet_cli_steps.rs index 08ed8322042..83287699f55 100644 --- a/integration_tests/tests/steps/wallet_cli_steps.rs +++ b/integration_tests/tests/steps/wallet_cli_steps.rs @@ -152,9 +152,8 @@ async fn send_from_cli(world: &mut TariWorld, amount: u64, wallet_a: String, wal let args = SendMinotariArgs { amount: MicroMinotari(amount), - message: format!("Send amount {} from {} to {}", amount, wallet_a, wallet_b), destination: wallet_b_address, - payment_id: "123456".to_string(), + payment_id: format!("Send amount {} from {} to {}", amount, wallet_a, wallet_b) }; cli.command2 = Some(CliCommands::SendMinotari(args)); @@ -175,8 +174,7 @@ async fn create_burn_tx_via_cli(world: &mut TariWorld, amount: u64, wallet: Stri let args = BurnMinotariArgs { amount: MicroMinotari(amount), - message: format!("Burn, burn amount {} !!!", amount,), - payment_id: "123456".to_string(), + payment_id: format!("Burn, burn amount {} !!!", amount) }; cli.command2 = Some(CliCommands::BurnMinotari(args)); @@ -220,15 +218,15 @@ async fn make_it_rain( start_amount: MicroMinotari(start_amount), transactions_per_second: f64::from(txs_per_second), duration: Duration::from_secs(duration), - message: format!( - "Make it raing amount {} from {} to {}", - start_amount, wallet_a, wallet_b - ), increase_amount: MicroMinotari(increment_amount), destination: wallet_b_address, start_time: None, one_sided: false, burn_tari: false, + payment_id: format!( + "Make it raing amount {} from {} to {}", + start_amount, wallet_a, wallet_b + ), }; cli.command2 = Some(CliCommands::MakeItRain(args)); @@ -252,8 +250,7 @@ async fn coin_split_via_cli(world: &mut TariWorld, wallet: String, amount: u64, amount_per_split: MicroMinotari(amount), num_splits: usize::try_from(splits).unwrap(), fee_per_gram: MicroMinotari(20), - message: format!("coin split amount {} with splits {}", amount, splits), - payment_id: "".to_string(), + payment_id: format!("coin split amount {} with splits {}", amount, splits), }; cli.command2 = Some(CliCommands::CoinSplit(args)); diff --git a/integration_tests/tests/steps/wallet_ffi_steps.rs b/integration_tests/tests/steps/wallet_ffi_steps.rs index 306d9510b12..4d4b7c346d8 100644 --- a/integration_tests/tests/steps/wallet_ffi_steps.rs +++ b/integration_tests/tests/steps/wallet_ffi_steps.rs @@ -24,6 +24,7 @@ use std::{convert::TryFrom, io::BufRead, ptr::null, time::Duration}; use cucumber::{given, then, when}; use tari_common_types::tari_address::TariAddress; +use tari_core::transactions::transaction_components::encrypted_data::PaymentId; use tari_integration_tests::{ wallet_ffi::{create_contact, create_seed_words, get_mnemonic_word_list_for_language, spawn_wallet_ffi}, TariWorld, @@ -209,8 +210,8 @@ async fn ffi_check_no_contact(world: &mut TariWorld, alias: String, wallet: Stri async fn ffi_send_transaction(world: &mut TariWorld, amount: u64, wallet: String, dest: String, fee: u64) { let ffi_wallet = world.get_ffi_wallet(&wallet).unwrap(); let dest_pub_key = world.get_wallet_address(&dest).await.unwrap(); - let message = format!("Send from ffi {} to ${} at fee ${}", wallet, dest, fee); - let tx_id = ffi_wallet.send_transaction(dest_pub_key, amount, fee, message, false); + let payment_id = PaymentId::open_from_str(&format!("Send from ffi {} to ${} at fee ${}", wallet, dest, fee)); + let tx_id = ffi_wallet.send_transaction(dest_pub_key, amount, fee, payment_id, false); assert_ne!(tx_id, 0, "Send transaction was not successful"); } @@ -219,8 +220,8 @@ async fn ffi_send_transaction(world: &mut TariWorld, amount: u64, wallet: String async fn ffi_send_one_sided_transaction(world: &mut TariWorld, amount: u64, wallet: String, dest: String, fee: u64) { let ffi_wallet = world.get_ffi_wallet(&wallet).unwrap(); let dest_pub_key = world.get_wallet_address(&dest).await.unwrap(); - let message = format!("Send from ffi {} to ${} at fee ${}", wallet, dest, fee); - let tx_id = ffi_wallet.send_transaction(dest_pub_key, amount, fee, message, true); + let payment_id = PaymentId::open_from_str(&format!("Send from ffi {} to ${} at fee ${}", wallet, dest, fee)); + let tx_id = ffi_wallet.send_transaction(dest_pub_key, amount, fee, payment_id, true); assert_ne!(tx_id, 0, "Send transaction was not successful"); } diff --git a/integration_tests/tests/steps/wallet_steps.rs b/integration_tests/tests/steps/wallet_steps.rs index 375040e5807..7199f172394 100644 --- a/integration_tests/tests/steps/wallet_steps.rs +++ b/integration_tests/tests/steps/wallet_steps.rs @@ -70,7 +70,7 @@ use tari_integration_tests::{ }; use tari_script::{ExecutionStack, TariScript}; use tari_utilities::hex::Hex; - +use tari_core::transactions::transaction_components::encrypted_data::PaymentId; use crate::steps::{mining_steps::create_miner, CONFIRMATION_PERIOD, HALF_SECOND, TWO_MINUTES_WITH_HALF_SECOND_SLEEP}; #[given(expr = "a wallet {word} connected to base node {word}")] @@ -497,17 +497,15 @@ async fn list_all_txs_for_wallet(world: &mut TariWorld, transaction_type: String while let Some(tx) = completed_txs.next().await { let tx_info = tx.unwrap().transaction.unwrap(); - if (tx_info.message.contains("Coinbase Transaction for Block ") && transaction_type == "COINBASE") || - (!tx_info.message.contains("Coinbase Transaction for Block ") && transaction_type == "NORMAL") - { - println!("Transaction with status COINBASE found for wallet {}: ", wallet); - } else { + let is_coinbase = tx_info.status == TransactionStatus::Coinbase as i32 || + tx_info.status == TransactionStatus::CoinbaseConfirmed as i32 || + tx_info.status == TransactionStatus::CoinbaseUnconfirmed as i32 || + tx_info.status == TransactionStatus::CoinbaseNotInBlockChain as i32; + if transaction_type == "COINBASE" && !is_coinbase || transaction_type == "NORMAL" && is_coinbase { continue; } println!("\n"); - println!("TxId: {}", tx_info.tx_id); - println!("Status: {}", tx_info.status); - println!("IsCancelled: {}", tx_info.is_cancelled); + println!("TxId: {}, Status: {}, IsCancelled: {}, {}", tx_info.tx_id, tx_info.status, tx_info.is_cancelled, transaction_type); } }