-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Rename NoteEnvelope into NoteHeader * Change Note struct to be based on header and details
- Loading branch information
Showing
13 changed files
with
244 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use miden_crypto::{ | ||
utils::{ByteReader, ByteWriter, Deserializable, Serializable}, | ||
Word, | ||
}; | ||
use vm_processor::DeserializationError; | ||
|
||
use super::{NoteAssets, NoteId, NoteInputs, NoteRecipient, NoteScript, Nullifier}; | ||
|
||
// NOTE DETAILS | ||
// ================================================================================================ | ||
|
||
/// Details of a note consisting of assets, script, inputs, and a serial number. | ||
/// | ||
/// See [super::Note] for more details. | ||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] | ||
pub struct NoteDetails { | ||
assets: NoteAssets, | ||
recipient: NoteRecipient, | ||
} | ||
|
||
impl NoteDetails { | ||
// CONSTRUCTOR | ||
// -------------------------------------------------------------------------------------------- | ||
|
||
/// Returns a new note created with the specified parameters. | ||
pub fn new(assets: NoteAssets, recipient: NoteRecipient) -> Self { | ||
Self { assets, recipient } | ||
} | ||
|
||
// PUBLIC ACCESSORS | ||
// -------------------------------------------------------------------------------------------- | ||
|
||
/// Returns the note's unique identifier. | ||
/// | ||
/// This value is both an unique identifier and a commitment to the note. | ||
pub fn id(&self) -> NoteId { | ||
NoteId::from(self) | ||
} | ||
|
||
/// Returns the note's assets. | ||
pub fn assets(&self) -> &NoteAssets { | ||
&self.assets | ||
} | ||
|
||
/// Returns the note's recipient serial_num, the secret required to consume the note. | ||
pub fn serial_num(&self) -> Word { | ||
self.recipient.serial_num() | ||
} | ||
|
||
/// Returns the note's recipient script which locks the assets of this note. | ||
pub fn script(&self) -> &NoteScript { | ||
self.recipient.script() | ||
} | ||
|
||
/// Returns the note's recipient inputs which customizes the script's behavior. | ||
pub fn inputs(&self) -> &NoteInputs { | ||
self.recipient.inputs() | ||
} | ||
|
||
/// Returns the note's recipient. | ||
pub fn recipient(&self) -> &NoteRecipient { | ||
&self.recipient | ||
} | ||
|
||
/// Returns the note's nullifier. | ||
/// | ||
/// This is public data, used to prevent double spend. | ||
pub fn nullifier(&self) -> Nullifier { | ||
Nullifier::from(self) | ||
} | ||
|
||
/// Decomposes note details into underlying assets and recipient. | ||
pub fn into_parts(self) -> (NoteAssets, NoteRecipient) { | ||
(self.assets, self.recipient) | ||
} | ||
} | ||
|
||
// SERIALIZATION | ||
// ================================================================================================ | ||
|
||
impl Serializable for NoteDetails { | ||
fn write_into<W: ByteWriter>(&self, target: &mut W) { | ||
let Self { assets, recipient } = self; | ||
|
||
assets.write_into(target); | ||
recipient.write_into(target); | ||
} | ||
} | ||
|
||
impl Deserializable for NoteDetails { | ||
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> { | ||
let assets = NoteAssets::read_from(source)?; | ||
let recipient = NoteRecipient::read_from(source)?; | ||
Ok(Self::new(assets, recipient)) | ||
} | ||
} |
Oops, something went wrong.