Skip to content

Commit

Permalink
style: rename receiver_preimage
Browse files Browse the repository at this point in the history
UtxoReceiver::receiver_preimage -> receiver_privacy_digest
  • Loading branch information
dan-da committed Jun 6, 2024
1 parent 62f1807 commit 2a1d2da
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/models/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl GlobalState {
commit(
Hash::hash(&rd.utxo),
rd.sender_randomness,
rd.receiver_preimage,
rd.receiver_privacy_digest,
)
})
.collect_vec()
Expand Down Expand Up @@ -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?;
/// ```
Expand Down
34 changes: 22 additions & 12 deletions src/models/state/utxo_receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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,
)
}
Expand All @@ -66,7 +66,7 @@ impl UtxoReceiver {
address: &ReceivingAddress,
utxo: Utxo,
sender_randomness: Digest,
receiver_preimage: Digest,
receiver_privacy_digest: Digest,
) -> Result<Self> {
let utxo_notify_method = match wallet_state.is_wallet_utxo(&utxo) {
true => UtxoNotifyMethod::OffChain,
Expand All @@ -77,7 +77,7 @@ impl UtxoReceiver {
Ok(Self {
utxo,
sender_randomness,
receiver_preimage,
receiver_privacy_digest,
utxo_notify_method,
})
}
Expand All @@ -88,25 +88,29 @@ 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),
}
}

/// 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,
}
}
Expand All @@ -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()),
}
}
Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 2a1d2da

Please sign in to comment.