Skip to content

Commit

Permalink
Merge pull request #323 from 0xPolygonMiden/frisitano-note-from-parts
Browse files Browse the repository at this point in the history
Introduce `from_parts` constructor for Note object
  • Loading branch information
frisitano authored Nov 27, 2023
2 parents 967bcfe + 2e21b9f commit e6f19b7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion objects/src/notes/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use vm_core::StarkField;
/// it is four elements in size (a word). The metadata includes the following elements:
/// - sender
/// - tag
/// - ZERO
/// - num assets
/// - ZERO
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
Expand Down
21 changes: 19 additions & 2 deletions objects/src/notes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub const NOTE_LEAF_DEPTH: u8 = NOTE_TREE_DEPTH + 1;
/// Auxiliary data which is used to verify authenticity and signal additional information:
/// - A metadata object which contains information about the sender, the tag and the number of
/// assets in the note.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Note {
script: NoteScript,
Expand Down Expand Up @@ -95,6 +95,23 @@ impl Note {
})
}

/// Returns a note instance created from the provided parts.
pub fn from_parts(
script: NoteScript,
inputs: NoteInputs,
vault: NoteVault,
serial_num: Word,
metadata: NoteMetadata,
) -> Self {
Self {
script,
inputs,
vault,
serial_num,
metadata,
}
}

// PUBLIC ACCESSORS
// --------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -185,7 +202,7 @@ impl Note {
/// This struct is composed:
/// - A note which has been recorded.
/// - The inclusion proof of the note.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct RecordedNote {
note: Note,
Expand Down
4 changes: 2 additions & 2 deletions objects/src/notes/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{Digest, Felt, NoteError, ToString, NOTE_TREE_DEPTH};
use crate::crypto::merkle::{MerklePath, NodeIndex};

/// Contains information about the origin of a note.
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct NoteOrigin {
pub block_num: Felt,
Expand All @@ -18,7 +18,7 @@ pub struct NoteOrigin {
/// in.
/// note_path - the Merkle path to the note in the note Merkle tree of the block the note was
/// created in.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct NoteInclusionProof {
origin: NoteOrigin,
Expand Down
2 changes: 1 addition & 1 deletion objects/src/notes/script.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{Assembler, AssemblyContext, CodeBlock, Digest, NoteError, ProgramAst};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct NoteScript {
hash: Digest,
Expand Down

0 comments on commit e6f19b7

Please sign in to comment.