miden_protocol/note/
details.rs1use super::{NoteAssets, NoteDetailsCommitment, NoteRecipient, NoteScript, NoteStorage};
2use crate::Word;
3use crate::utils::serde::{
4 ByteReader,
5 ByteWriter,
6 Deserializable,
7 DeserializationError,
8 Serializable,
9};
10
11#[derive(Clone, Debug, PartialEq, Eq)]
18pub struct NoteDetails {
19 assets: NoteAssets,
20 recipient: NoteRecipient,
21}
22
23impl NoteDetails {
24 pub fn new(assets: NoteAssets, recipient: NoteRecipient) -> Self {
29 Self { assets, recipient }
30 }
31
32 pub fn commitment(&self) -> NoteDetailsCommitment {
39 NoteDetailsCommitment::new(self.recipient(), self.assets())
40 }
41
42 pub fn assets(&self) -> &NoteAssets {
44 &self.assets
45 }
46
47 pub fn serial_num(&self) -> Word {
49 self.recipient.serial_num()
50 }
51
52 pub fn script(&self) -> &NoteScript {
54 self.recipient.script()
55 }
56
57 pub fn storage(&self) -> &NoteStorage {
59 self.recipient.storage()
60 }
61
62 pub fn recipient(&self) -> &NoteRecipient {
64 &self.recipient
65 }
66
67 pub fn minify_script(&mut self) {
72 self.recipient.minify_script();
73 }
74
75 pub fn into_parts(self) -> (NoteAssets, NoteRecipient) {
77 (self.assets, self.recipient)
78 }
79}
80
81impl AsRef<NoteRecipient> for NoteDetails {
85 fn as_ref(&self) -> &NoteRecipient {
86 self.recipient()
87 }
88}
89
90impl Serializable for NoteDetails {
94 fn write_into<W: ByteWriter>(&self, target: &mut W) {
95 let Self { assets, recipient } = self;
96
97 assets.write_into(target);
98 recipient.write_into(target);
99 }
100
101 fn get_size_hint(&self) -> usize {
102 self.assets.get_size_hint() + self.recipient.get_size_hint()
103 }
104}
105
106impl Deserializable for NoteDetails {
107 fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
108 let assets = NoteAssets::read_from(source)?;
109 let recipient = NoteRecipient::read_from(source)?;
110 Ok(Self::new(assets, recipient))
111 }
112}