miden_objects/note/
mod.rs1use miden_crypto::{
2 Word,
3 utils::{ByteReader, ByteWriter, Deserializable, Serializable},
4};
5use vm_processor::DeserializationError;
6
7use crate::{Digest, Felt, Hasher, NoteError, WORD_SIZE, ZERO, account::AccountId};
8
9mod assets;
10pub use assets::NoteAssets;
11
12mod details;
13pub use details::NoteDetails;
14
15mod header;
16pub use header::{NoteHeader, compute_note_commitment};
17
18mod inputs;
19pub use inputs::NoteInputs;
20
21mod metadata;
22pub use metadata::NoteMetadata;
23
24mod execution_hint;
25pub use execution_hint::{AfterBlockNumber, NoteExecutionHint};
26
27mod note_id;
28pub use note_id::NoteId;
29
30mod note_tag;
31pub use note_tag::{NoteExecutionMode, NoteTag};
32
33mod note_type;
34pub use note_type::NoteType;
35
36mod nullifier;
37pub use nullifier::Nullifier;
38
39mod location;
40pub use location::{NoteInclusionProof, NoteLocation};
41
42mod partial;
43pub use partial::PartialNote;
44
45mod recipient;
46pub use recipient::NoteRecipient;
47
48mod script;
49pub use script::NoteScript;
50
51mod file;
52pub use file::NoteFile;
53
54#[derive(Clone, Debug, PartialEq, Eq)]
79pub struct Note {
80 header: NoteHeader,
81 details: NoteDetails,
82
83 nullifier: Nullifier,
84}
85
86impl Note {
87 pub fn new(assets: NoteAssets, metadata: NoteMetadata, recipient: NoteRecipient) -> Self {
92 let details = NoteDetails::new(assets, recipient);
93 let header = NoteHeader::new(details.id(), metadata);
94 let nullifier = details.nullifier();
95
96 Self { header, details, nullifier }
97 }
98
99 pub fn header(&self) -> &NoteHeader {
104 &self.header
105 }
106
107 pub fn id(&self) -> NoteId {
111 self.header.id()
112 }
113
114 pub fn metadata(&self) -> &NoteMetadata {
116 self.header.metadata()
117 }
118
119 pub fn assets(&self) -> &NoteAssets {
121 self.details.assets()
122 }
123
124 pub fn serial_num(&self) -> Word {
126 self.details.serial_num()
127 }
128
129 pub fn script(&self) -> &NoteScript {
131 self.details.script()
132 }
133
134 pub fn inputs(&self) -> &NoteInputs {
136 self.details.inputs()
137 }
138
139 pub fn recipient(&self) -> &NoteRecipient {
141 self.details.recipient()
142 }
143
144 pub fn nullifier(&self) -> Nullifier {
148 self.nullifier
149 }
150
151 pub fn commitment(&self) -> Digest {
158 self.header.commitment()
159 }
160}
161
162impl AsRef<NoteRecipient> for Note {
166 fn as_ref(&self) -> &NoteRecipient {
167 self.recipient()
168 }
169}
170
171impl From<&Note> for NoteHeader {
175 fn from(note: &Note) -> Self {
176 note.header
177 }
178}
179
180impl From<Note> for NoteHeader {
181 fn from(note: Note) -> Self {
182 note.header
183 }
184}
185
186impl From<&Note> for NoteDetails {
187 fn from(note: &Note) -> Self {
188 note.details.clone()
189 }
190}
191
192impl From<Note> for NoteDetails {
193 fn from(note: Note) -> Self {
194 note.details
195 }
196}
197
198impl From<Note> for PartialNote {
199 fn from(note: Note) -> Self {
200 let (assets, recipient, ..) = note.details.into_parts();
201 PartialNote::new(*note.header.metadata(), recipient.digest(), assets)
202 }
203}
204
205impl From<&Note> for PartialNote {
206 fn from(note: &Note) -> Self {
207 PartialNote::new(
208 *note.header.metadata(),
209 note.details.recipient().digest(),
210 note.details.assets().clone(),
211 )
212 }
213}
214
215impl Serializable for Note {
219 fn write_into<W: ByteWriter>(&self, target: &mut W) {
220 let Self {
221 header,
222 details,
223
224 nullifier: _,
226 } = self;
227
228 header.metadata().write_into(target);
230 details.write_into(target);
231 }
232}
233
234impl Deserializable for Note {
235 fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
236 let metadata = NoteMetadata::read_from(source)?;
237 let details = NoteDetails::read_from(source)?;
238 let (assets, recipient) = details.into_parts();
239
240 Ok(Self::new(assets, metadata, recipient))
241 }
242}