Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use crate::{
FullViewingKey, OutgoingViewingKey, Scope, SpendAuthorizingKey, SpendValidatingKey,
SpendingKey,
},
note::{ExtractedNoteCommitment, Note, Nullifier, Rho, TransmittedNoteCiphertext},
note::{
ExtractedNoteCommitment, Note, NoteVersion, Nullifier, Rho, TransmittedNoteCiphertext,
DEFAULT_NOTE_VERSION,
},
note_encryption::OrchardNoteEncryption,
primitives::redpallas::{self, Binding, SpendAuth},
tree::{Anchor, MerklePath},
Expand Down Expand Up @@ -335,10 +338,13 @@ pub struct OutputInfo {
recipient: Address,
value: NoteValue,
memo: [u8; 512],
note_version: NoteVersion,
}

impl OutputInfo {
/// Constructs a new OutputInfo from its constituent parts.
///
/// This uses [`DEFAULT_NOTE_VERSION`].
pub fn new(
ovk: Option<OutgoingViewingKey>,
recipient: Address,
Expand All @@ -350,6 +356,24 @@ impl OutputInfo {
recipient,
value,
memo,
note_version: DEFAULT_NOTE_VERSION,
}
}

/// Constructs a new OutputInfo with a specified [`NoteVersion`].
pub fn new_with_version(
ovk: Option<OutgoingViewingKey>,
recipient: Address,
value: NoteValue,
memo: [u8; 512],
note_version: NoteVersion,
) -> Self {
Self {
ovk,
recipient,
value,
memo,
note_version,
}
}

Expand All @@ -375,7 +399,8 @@ impl OutputInfo {
mut rng: impl RngCore,
) -> (Note, ExtractedNoteCommitment, TransmittedNoteCiphertext) {
let rho = Rho::from_nf_old(nf_old);
let note = Note::new(self.recipient, self.value, rho, &mut rng);
let note =
Note::new_with_version(self.recipient, self.value, rho, &mut rng, self.note_version);
let cm_new = note.commitment();
let cmx = cm_new.into();

Expand Down Expand Up @@ -595,20 +620,40 @@ impl Builder {
}

/// Adds an address which will receive funds in this transaction.
///
/// This uses [`DEFAULT_NOTE_VERSION`].
pub fn add_output(
&mut self,
ovk: Option<OutgoingViewingKey>,
recipient: Address,
value: NoteValue,
memo: [u8; 512],
) -> Result<(), OutputError> {
self.add_output_with_version(ovk, recipient, value, memo, DEFAULT_NOTE_VERSION)
}

/// Adds an address which will receive funds in this transaction,
/// using the specified [`NoteVersion`].
pub fn add_output_with_version(
&mut self,
ovk: Option<OutgoingViewingKey>,
recipient: Address,
value: NoteValue,
memo: [u8; 512],
note_version: NoteVersion,
) -> Result<(), OutputError> {
let flags = self.bundle_type.flags();
if !flags.outputs_enabled() {
return Err(OutputError::OutputsDisabled);
}

self.outputs
.push(OutputInfo::new(ovk, recipient, value, memo));
self.outputs.push(OutputInfo::new_with_version(
ovk,
recipient,
value,
memo,
note_version,
));

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub use address::Address;
pub use bundle::Bundle;
pub use constants::MERKLE_DEPTH_ORCHARD as NOTE_COMMITMENT_TREE_DEPTH;
pub use constants::{L_ORCHARD_BASE, L_ORCHARD_SCALAR, L_VALUE};
pub use note::Note;
pub use note::{Note, NoteVersion};
pub use tree::Anchor;

/// A proof of the validity of an Orchard [`Bundle`].
Expand Down
Loading
Loading