From 2a1d2da3a2e086138a18b9c8c02a3df3120f923e Mon Sep 17 00:00:00 2001 From: danda Date: Thu, 6 Jun 2024 11:01:45 -0700 Subject: [PATCH] style: rename receiver_preimage UtxoReceiver::receiver_preimage -> receiver_privacy_digest --- src/models/state/mod.rs | 4 ++-- src/models/state/utxo_receiver.rs | 34 ++++++++++++++++++++----------- src/tests/shared.rs | 2 +- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/models/state/mod.rs b/src/models/state/mod.rs index 9833d916..31fd937f 100644 --- a/src/models/state/mod.rs +++ b/src/models/state/mod.rs @@ -439,7 +439,7 @@ impl GlobalState { commit( Hash::hash(&rd.utxo), rd.sender_randomness, - rd.receiver_preimage, + rd.receiver_privacy_digest, ) }) .collect_vec() @@ -584,7 +584,7 @@ impl GlobalState { /// Example: /// /// ```compile_fail - /// let utxo_receivers = vec![UtxoReceiver::auto(&wallet_state, &address, utxo, sender_randomness, receiver_preimage)]; + /// let utxo_receivers = vec![UtxoReceiver::auto(&wallet_state, &address, utxo, sender_randomness, receiver_privacy_digest)]; /// let (transaction, tx_data) = state.create_transaction(utxo_receivers, fee, now, ChangeNotifyMethod::default()).await?; /// state.add_expected_utxos_to_wallet(tx_data.expected_utxos).await?; /// ``` diff --git a/src/models/state/utxo_receiver.rs b/src/models/state/utxo_receiver.rs index d8e447c0..2c56c203 100644 --- a/src/models/state/utxo_receiver.rs +++ b/src/models/state/utxo_receiver.rs @@ -38,7 +38,7 @@ impl Default for ChangeNotifyMethod { pub struct UtxoReceiver { pub utxo: Utxo, pub sender_randomness: Digest, - pub receiver_preimage: Digest, + pub receiver_privacy_digest: Digest, pub utxo_notify_method: UtxoNotifyMethod, } @@ -47,7 +47,7 @@ impl From<&UtxoReceiver> for ExpectedUtxo { ExpectedUtxo::new( d.utxo.clone(), d.sender_randomness, - d.receiver_preimage, + d.receiver_privacy_digest, UtxoNotifier::Myself, ) } @@ -66,7 +66,7 @@ impl UtxoReceiver { address: &ReceivingAddress, utxo: Utxo, sender_randomness: Digest, - receiver_preimage: Digest, + receiver_privacy_digest: Digest, ) -> Result { let utxo_notify_method = match wallet_state.is_wallet_utxo(&utxo) { true => UtxoNotifyMethod::OffChain, @@ -77,7 +77,7 @@ impl UtxoReceiver { Ok(Self { utxo, sender_randomness, - receiver_preimage, + receiver_privacy_digest, utxo_notify_method, }) } @@ -88,13 +88,13 @@ impl UtxoReceiver { pub fn onchain( utxo: Utxo, sender_randomness: Digest, - receiver_preimage: Digest, + receiver_privacy_digest: Digest, public_announcement: PublicAnnouncement, ) -> Self { Self { utxo, sender_randomness, - receiver_preimage, + receiver_privacy_digest, utxo_notify_method: UtxoNotifyMethod::OnChain(public_announcement), } } @@ -102,11 +102,15 @@ impl UtxoReceiver { /// instantiates `UtxoReceiver` using OffChain notification method. /// /// For normal situations, auto() should be used instead. - pub fn offchain(utxo: Utxo, sender_randomness: Digest, receiver_preimage: Digest) -> Self { + pub fn offchain( + utxo: Utxo, + sender_randomness: Digest, + receiver_privacy_digest: Digest, + ) -> Self { Self { utxo, sender_randomness, - receiver_preimage, + receiver_privacy_digest, utxo_notify_method: UtxoNotifyMethod::OffChain, } } @@ -116,12 +120,12 @@ impl UtxoReceiver { pub fn fake_announcement( utxo: Utxo, sender_randomness: Digest, - receiver_preimage: Digest, + receiver_privacy_digest: Digest, ) -> Self { Self { utxo, sender_randomness, - receiver_preimage, + receiver_privacy_digest, utxo_notify_method: UtxoNotifyMethod::OnChain(PublicAnnouncement::default()), } } @@ -176,7 +180,10 @@ mod tests { UtxoNotifyMethod::OnChain(_) )); assert_eq!(utxo_receiver.sender_randomness, sender_randomness); - assert_eq!(utxo_receiver.receiver_preimage, receiver_privacy_digest); + assert_eq!( + utxo_receiver.receiver_privacy_digest, + receiver_privacy_digest + ); assert_eq!(utxo_receiver.utxo, utxo); Ok(()) } @@ -214,7 +221,10 @@ mod tests { UtxoNotifyMethod::OffChain )); assert_eq!(utxo_receiver.sender_randomness, sender_randomness); - assert_eq!(utxo_receiver.receiver_preimage, receiver_privacy_digest); + assert_eq!( + utxo_receiver.receiver_privacy_digest, + receiver_privacy_digest + ); assert_eq!(utxo_receiver.utxo, utxo); Ok(()) } diff --git a/src/tests/shared.rs b/src/tests/shared.rs index c44dbec8..fc0ac910 100644 --- a/src/tests/shared.rs +++ b/src/tests/shared.rs @@ -706,7 +706,7 @@ pub async fn make_mock_transaction_with_generation_key( let addition_record = commit( Hash::hash(&rd.utxo), rd.sender_randomness, - rd.receiver_preimage, + rd.receiver_privacy_digest, ); outputs.push(addition_record); }