Skip to content

Commit

Permalink
Merge pull request #148 from zcash/pczt-user-address
Browse files Browse the repository at this point in the history
pczt: Add output field for storing the user-facing address
  • Loading branch information
nuttycom authored Dec 13, 2024
2 parents 5bf2578 + e47d57f commit 34aedac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ impl PreparedOutputInfo {
// TODO: Save this?
ock: None,
zip32_derivation: None,
user_address: None,
proprietary: BTreeMap::new(),
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/pczt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ pub struct Output {
/// The ZIP 32 derivation path at which the spending key can be found for the output.
pub(crate) zip32_derivation: Option<Zip32Derivation>,

/// The user-facing address to which this output is being sent, if any.
///
/// - This is set by an Updater.
/// - Signers must parse this address (if present) and confirm that it contains
/// `recipient` (either directly, or e.g. as a receiver within a Unified Address).
pub(crate) user_address: Option<String>,

/// Proprietary fields related to the note being created.
pub(crate) proprietary: BTreeMap<String, Vec<u8>>,
}
Expand All @@ -283,6 +290,7 @@ impl fmt::Debug for Output {
.field("rseed", &self.rseed)
.field("rcv", &self.rcv)
.field("zip32_derivation", &self.zip32_derivation)
.field("user_address", &self.user_address)
.field("proprietary", &self.proprietary)
.finish_non_exhaustive()
}
Expand Down
2 changes: 2 additions & 0 deletions src/pczt/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ impl Output {
rcv: Option<[u8; 32]>,
ock: Option<[u8; 32]>,
zip32_derivation: Option<Zip32Derivation>,
user_address: Option<String>,
proprietary: BTreeMap<String, Vec<u8>>,
) -> Result<Self, ParseError> {
let cv = ValueCommitment::from_bytes_not_small_order(&cv)
Expand Down Expand Up @@ -232,6 +233,7 @@ impl Output {
rcv,
ock,
zip32_derivation,
user_address,
proprietary,
})
}
Expand Down
5 changes: 5 additions & 0 deletions src/pczt/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ impl<'a> OutputUpdater<'a> {
self.0.zip32_derivation = Some(derivation);
}

/// Sets the user-facing address that the new note is being sent to.
pub fn set_user_address(&mut self, user_address: String) {
self.0.user_address = Some(user_address);
}

/// Stores the given proprietary value at the given key.
pub fn set_proprietary(&mut self, key: String, value: Vec<u8>) {
self.0.proprietary.insert(key, value);
Expand Down

0 comments on commit 34aedac

Please sign in to comment.