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 }
49 }
50}
51
52impl From<TransactionArgs> for proto::transaction::TransactionArgs {
53 fn from(value: TransactionArgs) -> Self {
54 (&value).into()
55 }
56}
57
58impl From<&TxAccountUpdate> for proto::transaction::TxAccountUpdate {
62 fn from(value: &TxAccountUpdate) -> Self {
63 Self {
64 account_id: Some(value.account_id().into()),
65 initial_state_commitment: Some(value.initial_state_commitment().into()),
66 final_state_commitment: Some(value.final_state_commitment().into()),
67 account_patch_commitment: Some(value.account_patch_commitment().into()),
68 details: Some(value.details().into()),
69 }
70 }
71}
72
73impl From<&ProvenTransaction> for proto::transaction::ProvenTransaction {
77 fn from(value: &ProvenTransaction) -> Self {
78 Self {
79 account_update: Some(value.account_update().into()),
80 input_notes: value.input_notes().iter().map(Into::into).collect(),
81 output_notes: value.output_notes().iter().map(Into::into).collect(),
82 reference_block_num: Some(value.ref_block_num().into()),
83 reference_block_commitment: Some(value.ref_block_commitment().into()),
84 expiration_block_num: Some(value.expiration_block_num().into()),
85 proof: Some(value.proof().into()),
86 }
87 }
88}
89
90impl From<ProvenTransaction> for proto::transaction::ProvenTransaction {
91 fn from(value: ProvenTransaction) -> Self {
92 Self::from(&value)
93 }
94}
95
96impl From<&TransactionId> for proto::transaction::TransactionId {
100 fn from(value: &TransactionId) -> Self {
101 proto::transaction::TransactionId { id: Some(value.as_word().into()) }
102 }
103}
104
105impl From<TransactionId> for proto::transaction::TransactionId {
106 fn from(value: TransactionId) -> Self {
107 (&value).into()
108 }
109}
110
111impl From<InputNoteCommitment> for proto::transaction::InputNoteCommitment {
118 fn from(value: InputNoteCommitment) -> Self {
119 Self::from(&value)
120 }
121}
122
123impl From<&InputNoteCommitment> for proto::transaction::InputNoteCommitment {
124 fn from(value: &InputNoteCommitment) -> Self {
125 Self {
126 nullifier: Some(value.nullifier().as_word().into()),
127 header: value.header().copied().map(Into::into),
128 }
129 }
130}
131
132impl From<&TransactionHeader> for proto::transaction::TransactionHeader {
136 fn from(header: &TransactionHeader) -> Self {
137 Self {
138 transaction_id: Some(header.id().into()),
139 account_id: Some(header.account_id().into()),
140 initial_state_commitment: Some(header.initial_state_commitment().into()),
141 final_state_commitment: Some(header.final_state_commitment().into()),
142 input_notes: header.input_notes().iter().map(Into::into).collect(),
143 output_notes: header.output_notes().iter().copied().map(Into::into).collect(),
144 }
145 }
146}
147
148impl From<TransactionHeader> for proto::transaction::TransactionHeader {
149 fn from(header: TransactionHeader) -> Self {
150 Self::from(&header)
151 }
152}
153
154impl From<&PublicOutputNote> for proto::transaction::PublicOutputNote {
158 fn from(note: &PublicOutputNote) -> Self {
159 Self {
160 note: Some(note.as_note().clone().into()),
161 }
162 }
163}
164
165impl From<PublicOutputNote> for proto::transaction::PublicOutputNote {
166 fn from(note: PublicOutputNote) -> Self {
167 Self::from(¬e)
168 }
169}
170
171impl From<&PrivateOutputNote> for proto::transaction::PrivateOutputNote {
172 fn from(note: &PrivateOutputNote) -> Self {
173 Self {
174 header: Some((*note.header()).into()),
175 attachments: Some(note.attachments().into()),
176 }
177 }
178}
179
180impl From<PrivateOutputNote> for proto::transaction::PrivateOutputNote {
181 fn from(note: PrivateOutputNote) -> Self {
182 Self::from(¬e)
183 }
184}
185
186impl From<&OutputNote> for proto::transaction::OutputNote {
187 fn from(note: &OutputNote) -> Self {
188 use proto::transaction::output_note::Note;
189
190 let note = match note {
191 OutputNote::Public(note) => Note::Public(note.into()),
192 OutputNote::Private(note) => Note::Private(note.into()),
193 };
194 Self { note: Some(note) }
195 }
196}
197
198impl From<OutputNote> for proto::transaction::OutputNote {
199 fn from(note: OutputNote) -> Self {
200 Self::from(¬e)
201 }
202}
203
204impl From<&RawOutputNote> for proto::transaction::RawOutputNote {
208 fn from(note: &RawOutputNote) -> Self {
209 use proto::transaction::raw_output_note::Note;
210
211 let note = match note {
212 RawOutputNote::Full(note) => Note::Full(note.clone().into()),
213 RawOutputNote::Partial(note) => Note::Partial(note.into()),
214 };
215 Self { note: Some(note) }
216 }
217}
218
219impl From<RawOutputNote> for proto::transaction::RawOutputNote {
220 fn from(note: RawOutputNote) -> Self {
221 Self::from(¬e)
222 }
223}
224
225impl From<&RawOutputNotes> for proto::transaction::RawOutputNotes {
226 fn from(notes: &RawOutputNotes) -> Self {
227 Self {
228 notes: notes.iter().map(Into::into).collect(),
229 }
230 }
231}