diff --git a/sn_node/src/node.rs b/sn_node/src/node.rs index a81f701744..88767824ea 100644 --- a/sn_node/src/node.rs +++ b/sn_node/src/node.rs @@ -51,8 +51,6 @@ use libp2p::kad::{Quorum, Record}; use sn_networking::PutRecordCfg; #[cfg(feature = "reward-forward")] use sn_protocol::storage::{try_serialize_record, RecordKind, SpendAddress}; -#[cfg(feature = "reward-forward")] -use sn_transfers::Hash; /// Interval to trigger replication of all records to all peers. /// This is the max time it should take. Minimum interval at any ndoe will be half this @@ -776,10 +774,7 @@ impl Node { *NETWORK_ROYALTIES_PK, )]; - spend_requests.extend( - wallet - .prepare_forward_signed_spend(payee, Some(Hash::hash(&owner.into_bytes())))?, - ); + spend_requests.extend(wallet.prepare_forward_signed_spend(payee, owner)?); } let record_kind = RecordKind::Spend; diff --git a/sn_transfers/src/cashnotes/spend_reason.rs b/sn_transfers/src/cashnotes/spend_reason.rs index d50993098b..95fff403b1 100644 --- a/sn_transfers/src/cashnotes/spend_reason.rs +++ b/sn_transfers/src/cashnotes/spend_reason.rs @@ -39,6 +39,13 @@ impl SpendReason { Self::BetaRewardTracking(cypher) => Hash::hash(&cypher.cipher), } } + + pub fn create_reward_tracking_reason(input_str: &str) -> Result { + let input_pk = crate::NETWORK_ROYALTIES_PK.public_key(); + Ok(Self::BetaRewardTracking(DiscordNameCipher::create( + input_str, input_pk, + )?)) + } } lazy_static! { diff --git a/sn_transfers/src/wallet/hot_wallet.rs b/sn_transfers/src/wallet/hot_wallet.rs index ebd263fb39..ef982f4917 100644 --- a/sn_transfers/src/wallet/hot_wallet.rs +++ b/sn_transfers/src/wallet/hot_wallet.rs @@ -376,7 +376,7 @@ impl HotWallet { pub fn prepare_forward_signed_spend( &mut self, to: Vec, - reason_hash: Option, + owner: String, ) -> Result> { let (available_cash_notes, exclusive_access) = self.available_cash_notes()?; debug!( @@ -384,7 +384,15 @@ impl HotWallet { available_cash_notes ); - let reason_hash = reason_hash.unwrap_or_default(); + let spend_reason = match SpendReason::create_reward_tracking_reason(&owner) { + Ok(spend_reason) => spend_reason, + Err(err) => { + error!("Failed to generate spend_reason {err:?}"); + return Err(Error::CouldNotSendMoney(format!( + "Failed to generate spend_reason {err:?}" + ))); + } + }; // create a unique key for each output let mut rng = &mut rand::rngs::OsRng; @@ -399,7 +407,7 @@ impl HotWallet { available_cash_notes, to_unique_keys, self.address(), - reason_hash, + spend_reason, )?; let signed_spends = transfer.all_spend_requests.clone(); @@ -476,13 +484,21 @@ impl HotWallet { start.elapsed() ); debug!("Available CashNotes: {:#?}", available_cash_notes); - let input_reason_hash = SpendReason::default(); + let spend_reason = match SpendReason::create_reward_tracking_reason("STORAGE") { + Ok(spend_reason) => spend_reason, + Err(err) => { + error!("Failed to generate spend_reason for local_send {err:?}"); + return Err(Error::CouldNotSendMoney(format!( + "Failed to generate spend_reason {err:?}" + ))); + } + }; let start = Instant::now(); let offline_transfer = OfflineTransfer::new( available_cash_notes, recipients, self.address(), - input_reason_hash, + spend_reason, )?; trace!( "local_send_storage_payment created offline_transfer with {} cashnotes in {:?}",