Skip to content

Commit

Permalink
chore: rename output reason to purpose for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi authored and RolandSherwin committed Apr 30, 2024
1 parent a3a2044 commit 5252242
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 51 deletions.
6 changes: 3 additions & 3 deletions sn_networking/src/transfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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,
};
Expand Down
4 changes: 2 additions & 2 deletions sn_node/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Node {
cost,
timestamp,
quoting_metrics: quoting_metrics.clone(),
reason: owner,
owner,
pub_key: network.get_pub_key(),
signature,
};
Expand Down Expand Up @@ -73,7 +73,7 @@ pub(crate) fn verify_quote_for_storecost(
quote.cost,
quote.timestamp,
&quote.quoting_metrics,
quote.reason.clone(),
quote.owner.clone(),
);
let signature = quote.signature;
if !network.verify(&bytes, &signature) {
Expand Down
8 changes: 4 additions & 4 deletions sn_transfers/src/cashnotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
};
Expand Down
16 changes: 8 additions & 8 deletions sn_transfers/src/cashnotes/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ 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 {
let unique_pubkey = main_pubkey.new_unique_pubkey(&derivation_index);

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
Expand All @@ -97,8 +97,8 @@ impl TransactionBuilder {
mut self,
outputs: impl IntoIterator<Item = TransferRecipientDetails>,
) -> 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
}
Expand Down Expand Up @@ -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)?;
Expand All @@ -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,
},
Expand Down
14 changes: 7 additions & 7 deletions sn_transfers/src/cashnotes/cashnote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ pub struct CashNote {
pub parent_tx: Transaction,
/// The transaction's input's SignedSpends
pub parent_spends: BTreeSet<SignedSpend>,
/// 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.
Expand Down Expand Up @@ -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.
Expand All @@ -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];
Expand Down
8 changes: 4 additions & 4 deletions sn_transfers/src/transfers/offline_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
let total_output_amount = recipients
.iter()
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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<OfflineTransfer> {
// gather the network_royalties derivation indexes
let network_royalties: Vec<DerivationIndex> = selected_inputs
Expand All @@ -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();

Expand Down
8 changes: 4 additions & 4 deletions sn_transfers/src/transfers/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,20 @@ 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 {
/// Create a new CashNoteRedemption
pub fn new(
derivation_index: DerivationIndex,
parent_spend: SpendAddress,
reason: String,
purpose: String,
) -> Self {
Self {
derivation_index,
parent_spend,
reason,
purpose,
}
}

Expand All @@ -167,7 +167,7 @@ impl CashNoteRedemption {
Ok(Self::new(
derivation_index,
parent_spend,
cash_note.reason.clone(),
cash_note.purpose.clone(),
))
}

Expand Down
16 changes: 8 additions & 8 deletions sn_transfers/src/wallet/data_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
Expand All @@ -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![],
}
Expand All @@ -135,7 +135,7 @@ impl PaymentQuote {
cost: NanoTokens,
timestamp: SystemTime,
quoting_metrics: &QuotingMetrics,
reason: String,
owner: String,
) -> Vec<u8> {
let mut bytes = xorname.to_vec();
bytes.extend_from_slice(&cost.to_bytes());
Expand All @@ -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
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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![],
}
Expand Down Expand Up @@ -304,7 +304,7 @@ mod tests {
quote.cost,
quote.timestamp,
&quote.quoting_metrics,
quote.reason.clone(),
quote.owner.clone(),
);
let signature = if let Ok(sig) = keypair.sign(&bytes) {
sig
Expand Down
18 changes: 9 additions & 9 deletions sn_transfers/src/wallet/hot_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
]
},
Expand All @@ -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 {:?}",
Expand All @@ -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| {
Expand Down
4 changes: 2 additions & 2 deletions sn_transfers/src/wallet/watch_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 5252242

Please sign in to comment.