miden_objects/conversion/
transaction.rs1use miden_protocol::transaction::{
2 InputNoteCommitment,
3 OutputNote,
4 PrivateOutputNote,
5 ProvenTransaction,
6 PublicOutputNote,
7 RawOutputNote,
8 RawOutputNotes,
9 TransactionArgs,
10 TransactionHeader,
11 TransactionId,
12 TransactionScript,
13 TxAccountUpdate,
14};
15
16use crate::proto;
17
18#[cfg(test)]
19mod tests;
20
21impl From<&TransactionScript> for proto::transaction::TransactionScript {
25 fn from(value: &TransactionScript) -> Self {
26 Self {
27 entrypoint: value.entrypoint().into(),
28 mast: Some(value.mast().as_ref().into()),
29 }
30 }
31}
32
33impl From<&TransactionArgs> for proto::transaction::TransactionArgs {
34 fn from(value: &TransactionArgs) -> Self {
35 Self {
36 tx_script: value.tx_script().map(Into::into),
37 tx_script_args: Some(value.tx_script_args().into()),
38 note_args: value
39 .note_args()
40 .iter()
41 .map(|(note_id, args)| proto::transaction::NoteArgument {
42 note_id: Some(note_id.into()),
43 args: Some(args.into()),
44 })
45 .collect(),
46 advice_inputs: Some(value.advice_inputs().into()),
47 auth_args: Some(value.auth_args().into()),
48 account_code_upgrade: value.account_code_upgrade().map(Into::into),
49 }
50 }
51}
52
53impl From<TransactionArgs> for proto::transaction::TransactionArgs {
54 fn from(value: TransactionArgs) -> Self {
55 (&value).into()
56 }
57}
58
59impl From<&TxAccountUpdate> for proto::transaction::TxAccountUpdate {
63 fn from(value: &TxAccountUpdate) -> Self {
64 Self {
65 account_id: Some(value.account_id().into()),
66 initial_state_commitment: Some(value.initial_state_commitment().into()),
67 final_state_commitment: Some(value.final_state_commitment().into()),
68 account_patch_commitment: Some(value.account_patch_commitment().into()),
69 details: Some(value.details().into()),
70 }
71 }
72}
73
74impl From<&ProvenTransaction> for proto::transaction::ProvenTransaction {
78 fn from(value: &ProvenTransaction) -> Self {
79 Self {
80 account_update: Some(value.account_update().into()),
81 input_notes: value.input_notes().iter().map(Into::into).collect(),
82 output_notes: value.output_notes().iter().map(Into::into).collect(),
83 reference_block_num: Some(value.ref_block_num().into()),
84 reference_block_commitment: Some(value.ref_block_commitment().into()),
85 expiration_block_num: Some(value.expiration_block_num().into()),
86 proof: Some(value.proof().into()),
87 }
88 }
89}
90
91impl From<ProvenTransaction> for proto::transaction::ProvenTransaction {
92 fn from(value: ProvenTransaction) -> Self {
93 Self::from(&value)
94 }
95}
96
97impl From<&TransactionId> for proto::transaction::TransactionId {
101 fn from(value: &TransactionId) -> Self {
102 proto::transaction::TransactionId { id: Some(value.as_word().into()) }
103 }
104}
105
106impl From<TransactionId> for proto::transaction::TransactionId {
107 fn from(value: TransactionId) -> Self {
108 (&value).into()
109 }
110}
111
112impl From<InputNoteCommitment> for proto::transaction::InputNoteCommitment {
119 fn from(value: InputNoteCommitment) -> Self {
120 Self::from(&value)
121 }
122}
123
124impl From<&InputNoteCommitment> for proto::transaction::InputNoteCommitment {
125 fn from(value: &InputNoteCommitment) -> Self {
126 Self {
127 nullifier: Some(value.nullifier().as_word().into()),
128 header: value.header().copied().map(Into::into),
129 }
130 }
131}
132
133impl From<&TransactionHeader> for proto::transaction::TransactionHeader {
137 fn from(header: &TransactionHeader) -> Self {
138 Self {
139 transaction_id: Some(header.id().into()),
140 account_id: Some(header.account_id().into()),
141 initial_state_commitment: Some(header.initial_state_commitment().into()),
142 final_state_commitment: Some(header.final_state_commitment().into()),
143 input_notes: header.input_notes().iter().map(Into::into).collect(),
144 output_notes: header.output_notes().iter().copied().map(Into::into).collect(),
145 }
146 }
147}
148
149impl From<TransactionHeader> for proto::transaction::TransactionHeader {
150 fn from(header: TransactionHeader) -> Self {
151 Self::from(&header)
152 }
153}
154
155impl From<&PublicOutputNote> for proto::transaction::PublicOutputNote {
159 fn from(note: &PublicOutputNote) -> Self {
160 Self {
161 note: Some(note.as_note().clone().into()),
162 }
163 }
164}
165
166impl From<PublicOutputNote> for proto::transaction::PublicOutputNote {
167 fn from(note: PublicOutputNote) -> Self {
168 Self::from(¬e)
169 }
170}
171
172impl From<&PrivateOutputNote> for proto::transaction::PrivateOutputNote {
173 fn from(note: &PrivateOutputNote) -> Self {
174 Self {
175 header: Some((*note.header()).into()),
176 attachments: Some(note.attachments().into()),
177 }
178 }
179}
180
181impl From<PrivateOutputNote> for proto::transaction::PrivateOutputNote {
182 fn from(note: PrivateOutputNote) -> Self {
183 Self::from(¬e)
184 }
185}
186
187impl From<&OutputNote> for proto::transaction::OutputNote {
188 fn from(note: &OutputNote) -> Self {
189 use proto::transaction::output_note::Note;
190
191 let note = match note {
192 OutputNote::Public(note) => Note::Public(note.into()),
193 OutputNote::Private(note) => Note::Private(note.into()),
194 };
195 Self { note: Some(note) }
196 }
197}
198
199impl From<OutputNote> for proto::transaction::OutputNote {
200 fn from(note: OutputNote) -> Self {
201 Self::from(¬e)
202 }
203}
204
205impl From<&RawOutputNote> for proto::transaction::RawOutputNote {
209 fn from(note: &RawOutputNote) -> Self {
210 use proto::transaction::raw_output_note::Note;
211
212 let note = match note {
213 RawOutputNote::Full(note) => Note::Full(note.clone().into()),
214 RawOutputNote::Partial(note) => Note::Partial(note.into()),
215 };
216 Self { note: Some(note) }
217 }
218}
219
220impl From<RawOutputNote> for proto::transaction::RawOutputNote {
221 fn from(note: RawOutputNote) -> Self {
222 Self::from(¬e)
223 }
224}
225
226impl From<&RawOutputNotes> for proto::transaction::RawOutputNotes {
227 fn from(notes: &RawOutputNotes) -> Self {
228 Self {
229 notes: notes.iter().map(Into::into).collect(),
230 }
231 }
232}