From 5252242d0cbdaf9cbc1a7c58983128a7921a2d36 Mon Sep 17 00:00:00 2001 From: qima Date: Tue, 30 Apr 2024 22:10:52 +0800 Subject: [PATCH] chore: rename output reason to purpose for clarity --- sn_networking/src/transfers.rs | 6 +++--- sn_node/src/quote.rs | 4 ++-- sn_transfers/src/cashnotes.rs | 8 ++++---- sn_transfers/src/cashnotes/builder.rs | 16 ++++++++-------- sn_transfers/src/cashnotes/cashnote.rs | 14 +++++++------- sn_transfers/src/transfers/offline_transfer.rs | 8 ++++---- sn_transfers/src/transfers/transfer.rs | 8 ++++---- sn_transfers/src/wallet/data_payments.rs | 16 ++++++++-------- sn_transfers/src/wallet/hot_wallet.rs | 18 +++++++++--------- sn_transfers/src/wallet/watch_only.rs | 4 ++-- 10 files changed, 51 insertions(+), 51 deletions(-) diff --git a/sn_networking/src/transfers.rs b/sn_networking/src/transfers.rs index 5886281892..ece1b99cd7 100644 --- a/sn_networking/src/transfers.rs +++ b/sn_networking/src/transfers.rs @@ -148,12 +148,12 @@ impl Network { .iter() .map(|u| { let unique_pubkey = main_pubkey.new_unique_pubkey(&u.derivation_index); - (u.reason.clone(), unique_pubkey, u.derivation_index) + (u.purpose.clone(), unique_pubkey, u.derivation_index) }) .collect(); let mut our_output_cash_notes = Vec::new(); - for (reason, id, derivation_index) in our_output_unique_pubkeys.into_iter() { + for (purpose, id, derivation_index) in our_output_unique_pubkeys.into_iter() { let src_tx = parent_txs .iter() .find(|tx| tx.outputs.iter().any(|o| o.unique_pubkey() == &id)) @@ -170,7 +170,7 @@ impl Network { unique_pubkey: id, parent_tx: src_tx, parent_spends: signed_spends, - reason: reason.clone(), + purpose: purpose.clone(), main_pubkey, derivation_index, }; diff --git a/sn_node/src/quote.rs b/sn_node/src/quote.rs index 5f19f95cdc..3036b7c94c 100644 --- a/sn_node/src/quote.rs +++ b/sn_node/src/quote.rs @@ -40,7 +40,7 @@ impl Node { cost, timestamp, quoting_metrics: quoting_metrics.clone(), - reason: owner, + owner, pub_key: network.get_pub_key(), signature, }; @@ -73,7 +73,7 @@ pub(crate) fn verify_quote_for_storecost( quote.cost, quote.timestamp, "e.quoting_metrics, - quote.reason.clone(), + quote.owner.clone(), ); let signature = quote.signature; if !network.verify(&bytes, &signature) { diff --git a/sn_transfers/src/cashnotes.rs b/sn_transfers/src/cashnotes.rs index 428e329d23..baacd00590 100644 --- a/sn_transfers/src/cashnotes.rs +++ b/sn_transfers/src/cashnotes.rs @@ -53,7 +53,7 @@ pub(crate) mod tests { unique_pubkey: derived_key.unique_pubkey(), parent_tx: tx, parent_spends: Default::default(), - reason: Default::default(), + purpose: Default::default(), main_pubkey: main_key.main_pubkey(), derivation_index, }; @@ -85,7 +85,7 @@ pub(crate) mod tests { unique_pubkey: derived_key.unique_pubkey(), parent_tx: tx, parent_spends: Default::default(), - reason: Default::default(), + purpose: Default::default(), main_pubkey: main_key.main_pubkey(), derivation_index, }; @@ -121,7 +121,7 @@ pub(crate) mod tests { unique_pubkey: derived_key.unique_pubkey(), parent_tx: tx, parent_spends: Default::default(), - reason: Default::default(), + purpose: Default::default(), main_pubkey: main_key.main_pubkey(), derivation_index, }; @@ -157,7 +157,7 @@ pub(crate) mod tests { unique_pubkey: derived_key.unique_pubkey(), parent_tx: tx, parent_spends: Default::default(), - reason: Default::default(), + purpose: Default::default(), main_pubkey: main_key.main_pubkey(), derivation_index, }; diff --git a/sn_transfers/src/cashnotes/builder.rs b/sn_transfers/src/cashnotes/builder.rs index 471190c8ab..799fbbc396 100644 --- a/sn_transfers/src/cashnotes/builder.rs +++ b/sn_transfers/src/cashnotes/builder.rs @@ -72,11 +72,11 @@ impl TransactionBuilder { self } - /// Add an output given the token, reason, the MainPubkey and the DerivationIndex + /// Add an output given the token, purpose, the MainPubkey and the DerivationIndex pub fn add_output( mut self, token: NanoTokens, - reason: String, + purpose: String, main_pubkey: MainPubkey, derivation_index: DerivationIndex, ) -> Self { @@ -84,9 +84,9 @@ impl TransactionBuilder { self.output_details.insert( unique_pubkey, - (reason.clone(), main_pubkey, derivation_index), + (purpose.clone(), main_pubkey, derivation_index), ); - let output = Output::new(unique_pubkey, token.as_nano(), reason); + let output = Output::new(unique_pubkey, token.as_nano(), purpose); self.outputs.push(output); self @@ -97,8 +97,8 @@ impl TransactionBuilder { mut self, outputs: impl IntoIterator, ) -> Self { - for (token, reason, main_pubkey, derivation_index) in outputs.into_iter() { - self = self.add_output(token, reason, main_pubkey, derivation_index); + for (token, purpose, main_pubkey, derivation_index) in outputs.into_iter() { + self = self.add_output(token, purpose, main_pubkey, derivation_index); } self } @@ -231,7 +231,7 @@ impl CashNoteBuilder { .outputs .iter() .map(|output| { - let (reason, main_pubkey, derivation_index) = self + let (purpose, main_pubkey, derivation_index) = self .output_details .get(&output.unique_pubkey) .ok_or(TransferError::UniquePubkeyNotFound)?; @@ -241,7 +241,7 @@ impl CashNoteBuilder { unique_pubkey: main_pubkey.new_unique_pubkey(derivation_index), parent_tx: self.spent_tx.clone(), parent_spends: self.signed_spends.clone(), - reason: reason.clone(), + purpose: purpose.clone(), main_pubkey: *main_pubkey, derivation_index: *derivation_index, }, diff --git a/sn_transfers/src/cashnotes/cashnote.rs b/sn_transfers/src/cashnotes/cashnote.rs index 84fcd00dda..5d992fbaf1 100644 --- a/sn_transfers/src/cashnotes/cashnote.rs +++ b/sn_transfers/src/cashnotes/cashnote.rs @@ -69,9 +69,9 @@ pub struct CashNote { pub parent_tx: Transaction, /// The transaction's input's SignedSpends pub parent_spends: BTreeSet, - /// The reason this cash_note created for + /// The purpose this cash_note created for /// eg. `store cost pay to...`, `network royalty`, `change to self`, `payment transfer`, ... - pub reason: String, + pub purpose: String, /// This is the MainPubkey of the owner of this CashNote pub main_pubkey: MainPubkey, /// The derivation index used to derive the UniquePubkey and DerivedSecretKey from the MainPubkey and MainSecretKey respectively. @@ -122,13 +122,13 @@ impl CashNote { self.parent_spends .iter() .next() - .map(|c| c.reason()) + .map(|s| s.reason()) .unwrap_or_default() } - /// Return the reason why this CashNote was created. - pub fn self_reason(&self) -> String { - self.reason.clone() + /// Return the purpose why this CashNote was created. + pub fn purpose(&self) -> String { + self.purpose.clone() } /// Return the value in NanoTokens for this CashNote. @@ -153,7 +153,7 @@ impl CashNote { sha3.update(&sp.to_bytes()); } - sha3.update(&self.reason.clone().into_bytes()); + sha3.update(&self.purpose.clone().into_bytes()); sha3.update(self.spent_reason().as_ref()); let mut hash = [0u8; 32]; diff --git a/sn_transfers/src/transfers/offline_transfer.rs b/sn_transfers/src/transfers/offline_transfer.rs index bd2c6b32f6..a81d9130ab 100644 --- a/sn_transfers/src/transfers/offline_transfer.rs +++ b/sn_transfers/src/transfers/offline_transfer.rs @@ -93,7 +93,7 @@ impl OfflineTransfer { available_cash_notes: CashNotesAndSecretKey, recipients: Vec<(NanoTokens, String, MainPubkey, DerivationIndex)>, change_to: MainPubkey, - reason_hash: Hash, + input_reason_hash: Hash, ) -> Result { let total_output_amount = recipients .iter() @@ -116,7 +116,7 @@ impl OfflineTransfer { change: (change_amount, change_to), }; - create_offline_transfer_with(selected_inputs, reason_hash) + create_offline_transfer_with(selected_inputs, input_reason_hash) } } @@ -294,7 +294,7 @@ fn create_transaction_builder_with( /// enough peers in the network, the transaction will be completed. fn create_offline_transfer_with( selected_inputs: TransferInputs, - reason_hash: Hash, + input_reason_hash: Hash, ) -> Result { // gather the network_royalties derivation indexes let network_royalties: Vec = selected_inputs @@ -307,7 +307,7 @@ fn create_offline_transfer_with( let (tx_builder, src_txs, change_id) = create_transaction_builder_with(selected_inputs)?; // Finalize the tx builder to get the cash_note builder. - let cash_note_builder = tx_builder.build(reason_hash, network_royalties)?; + let cash_note_builder = tx_builder.build(input_reason_hash, network_royalties)?; let tx = cash_note_builder.spent_tx.clone(); diff --git a/sn_transfers/src/transfers/transfer.rs b/sn_transfers/src/transfers/transfer.rs index 514ed716de..37928f1d56 100644 --- a/sn_transfers/src/transfers/transfer.rs +++ b/sn_transfers/src/transfers/transfer.rs @@ -139,7 +139,7 @@ pub struct CashNoteRedemption { /// using data found at this address the owner can check that the output is valid money pub parent_spend: SpendAddress, /// For what purpose this cash_note was created - pub reason: String, + pub purpose: String, } impl CashNoteRedemption { @@ -147,12 +147,12 @@ impl CashNoteRedemption { pub fn new( derivation_index: DerivationIndex, parent_spend: SpendAddress, - reason: String, + purpose: String, ) -> Self { Self { derivation_index, parent_spend, - reason, + purpose, } } @@ -167,7 +167,7 @@ impl CashNoteRedemption { Ok(Self::new( derivation_index, parent_spend, - cash_note.reason.clone(), + cash_note.purpose.clone(), )) } diff --git a/sn_transfers/src/wallet/data_payments.rs b/sn_transfers/src/wallet/data_payments.rs index b7e0164522..dc617e1ff6 100644 --- a/sn_transfers/src/wallet/data_payments.rs +++ b/sn_transfers/src/wallet/data_payments.rs @@ -106,8 +106,8 @@ pub struct PaymentQuote { pub timestamp: SystemTime, /// quoting metrics being used to generate this quote pub quoting_metrics: QuotingMetrics, - /// node's reason to accept the payment. Normally using its discord username - pub reason: String, + /// node's owner to accept the payment. Normally using its discord username + pub owner: String, /// node's public key that can verify the signature #[debug(skip)] pub pub_key: Vec, @@ -123,7 +123,7 @@ impl PaymentQuote { cost: NanoTokens::zero(), timestamp: SystemTime::now(), quoting_metrics: Default::default(), - reason: Default::default(), + owner: Default::default(), pub_key: vec![], signature: vec![], } @@ -135,7 +135,7 @@ impl PaymentQuote { cost: NanoTokens, timestamp: SystemTime, quoting_metrics: &QuotingMetrics, - reason: String, + owner: String, ) -> Vec { let mut bytes = xorname.to_vec(); bytes.extend_from_slice(&cost.to_bytes()); @@ -151,7 +151,7 @@ impl PaymentQuote { Err(_err) => vec![], }; bytes.extend_from_slice(&serialised_quoting_metrics); - bytes.extend_from_slice(&reason.into_bytes()); + bytes.extend_from_slice(&owner.into_bytes()); bytes } @@ -176,7 +176,7 @@ impl PaymentQuote { self.cost, self.timestamp, &self.quoting_metrics, - self.reason.clone(), + self.owner.clone(), ); if !pub_key.verify(&bytes, &self.signature) { @@ -205,7 +205,7 @@ impl PaymentQuote { cost, timestamp: SystemTime::now(), quoting_metrics: Default::default(), - reason: Default::default(), + owner: Default::default(), pub_key: vec![], signature: vec![], } @@ -304,7 +304,7 @@ mod tests { quote.cost, quote.timestamp, "e.quoting_metrics, - quote.reason.clone(), + quote.owner.clone(), ); let signature = if let Ok(sig) = keypair.sign(&bytes) { sig diff --git a/sn_transfers/src/wallet/hot_wallet.rs b/sn_transfers/src/wallet/hot_wallet.rs index 563d601fbb..55a0ff4999 100644 --- a/sn_transfers/src/wallet/hot_wallet.rs +++ b/sn_transfers/src/wallet/hot_wallet.rs @@ -37,7 +37,7 @@ use xor_name::XorName; /// A locked file handle, that when dropped releases the lock. pub type WalletExclusiveAccess = File; -// TransactionPayeeDetails: (reason, amount, address) +// TransactionPayeeDetails: (purpose, amount, address) pub type TransactionPayeeDetails = (String, NanoTokens, MainPubkey); /// A hot-wallet. @@ -323,8 +323,8 @@ impl HotWallet { // create a unique key for each output let to_unique_keys: Vec<_> = to .into_iter() - .map(|(reason, amount, address)| { - (amount, reason, address, DerivationIndex::random(&mut rng)) + .map(|(purpose, amount, address)| { + (amount, purpose, address, DerivationIndex::random(&mut rng)) }) .collect(); @@ -394,7 +394,7 @@ impl HotWallet { for (xorname, (main_pubkey, quote, peer_id_bytes)) in price_map.iter() { let storage_payee = ( quote.cost, - quote.reason.clone(), + quote.owner.clone(), *main_pubkey, DerivationIndex::random(&mut rng), peer_id_bytes.clone(), @@ -421,9 +421,9 @@ impl HotWallet { let recipients = recipients_by_xor .values() .flat_map( - |((cost, reason, pubkey, derivation_index, _id_bytes), roy)| { + |((cost, purpose, pubkey, derivation_index, _id_bytes), roy)| { vec![ - (*cost, reason.clone(), *pubkey, *derivation_index), + (*cost, purpose.clone(), *pubkey, *derivation_index), roy.clone(), ] }, @@ -443,13 +443,13 @@ impl HotWallet { start.elapsed() ); debug!("Available CashNotes: {:#?}", available_cash_notes); - let reason_hash = Hash::hash(b"SPEND_REASON_FOR_STORAGE"); + let input_reason_hash = Hash::hash(b"SPEND_REASON_FOR_STORAGE"); let start = Instant::now(); let offline_transfer = OfflineTransfer::new( available_cash_notes, recipients, self.address(), - reason_hash, + input_reason_hash, )?; trace!( "local_send_storage_payment created offline_transfer with {} cashnotes in {:?}", @@ -466,7 +466,7 @@ impl HotWallet { .collect(); for (xorname, recipients_info) in recipients_by_xor { let (storage_payee, royalties_payee) = recipients_info; - let (pay_amount, _reason, node_key, _, peer_id_bytes) = storage_payee; + let (pay_amount, _purpose, node_key, _, peer_id_bytes) = storage_payee; let cash_note_for_node = cashnotes_to_use .iter() .find(|cash_note| { diff --git a/sn_transfers/src/wallet/watch_only.rs b/sn_transfers/src/wallet/watch_only.rs index bea31b9aaf..34c615eab3 100644 --- a/sn_transfers/src/wallet/watch_only.rs +++ b/sn_transfers/src/wallet/watch_only.rs @@ -222,8 +222,8 @@ impl WatchOnlyWallet { // create a unique key for each output let to_unique_keys: Vec<_> = to .into_iter() - .map(|(reason, amount, address)| { - (amount, reason, address, DerivationIndex::random(&mut rng)) + .map(|(purpose, amount, address)| { + (amount, purpose, address, DerivationIndex::random(&mut rng)) }) .collect();