From 2e21b9fe5e8629b8f43d9ad8b944b9ed9da99d84 Mon Sep 17 00:00:00 2001 From: frisitano Date: Wed, 22 Nov 2023 14:25:08 +0800 Subject: [PATCH] feat: introduce from_parts constructor for Note object --- objects/src/notes/envelope.rs | 2 +- objects/src/notes/mod.rs | 21 +++++++++++++++++++-- objects/src/notes/origin.rs | 4 ++-- objects/src/notes/script.rs | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/objects/src/notes/envelope.rs b/objects/src/notes/envelope.rs index 5ba1c1c8a..a17e1a5a1 100644 --- a/objects/src/notes/envelope.rs +++ b/objects/src/notes/envelope.rs @@ -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))] diff --git a/objects/src/notes/mod.rs b/objects/src/notes/mod.rs index 6fcaaef30..0f033064f 100644 --- a/objects/src/notes/mod.rs +++ b/objects/src/notes/mod.rs @@ -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, @@ -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 // -------------------------------------------------------------------------------------------- @@ -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, diff --git a/objects/src/notes/origin.rs b/objects/src/notes/origin.rs index 238fb74c2..19a8bb2f3 100644 --- a/objects/src/notes/origin.rs +++ b/objects/src/notes/origin.rs @@ -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, @@ -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, diff --git a/objects/src/notes/script.rs b/objects/src/notes/script.rs index e9a52b169..ace746968 100644 --- a/objects/src/notes/script.rs +++ b/objects/src/notes/script.rs @@ -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,