Skip to main content

miden_objects/conversion/
transaction_inputs.rs

1use alloc::string::String;
2
3use miden_protocol::transaction::{InputNote, InputNotes, TransactionInputs};
4
5use crate::proto;
6
7impl From<&InputNote> for proto::transaction::InputNote {
8    fn from(value: &InputNote) -> Self {
9        use proto::transaction::input_note::Note as ProtoInputNote;
10
11        let note = match value {
12            InputNote::Authenticated { note, proof } => {
13                ProtoInputNote::Authenticated(proto::transaction::AuthenticatedInputNote {
14                    note: Some(note.clone().into()),
15                    proof: Some((&note.id(), proof).into()),
16                })
17            },
18            InputNote::Unauthenticated { note } => {
19                ProtoInputNote::Unauthenticated(note.clone().into())
20            },
21        };
22
23        Self { note: Some(note) }
24    }
25}
26
27impl From<&InputNotes<InputNote>> for proto::transaction::InputNotes {
28    fn from(value: &InputNotes<InputNote>) -> Self {
29        Self {
30            notes: value.iter().map(Into::into).collect(),
31        }
32    }
33}
34
35impl From<&TransactionInputs> for proto::transaction::TransactionInputsV1 {
36    fn from(value: &TransactionInputs) -> Self {
37        Self {
38            account: Some(value.account().into()),
39            block_header: Some(value.block_header().into()),
40            protocol_config: Some(value.protocol_config().into()),
41            partial_blockchain: Some(value.blockchain().into()),
42            input_notes: Some(value.input_notes().into()),
43            tx_args: Some(value.tx_args().into()),
44            advice_inputs: Some(value.advice_inputs().into()),
45            foreign_account_code: value.foreign_account_code().iter().map(Into::into).collect(),
46            foreign_account_slot_names: value
47                .foreign_account_slot_names()
48                .iter()
49                .map(|(slot_id, slot_name)| proto::transaction::ForeignAccountSlotName {
50                    slot_id: Some(slot_id.into()),
51                    slot_name: String::from(slot_name.as_str()),
52                })
53                .collect(),
54        }
55    }
56}
57
58impl From<&TransactionInputs> for proto::transaction::TransactionInputs {
59    fn from(value: &TransactionInputs) -> Self {
60        use proto::transaction::transaction_inputs::Version;
61
62        Self { version: Some(Version::V1(value.into())) }
63    }
64}
65
66impl From<TransactionInputs> for proto::transaction::TransactionInputs {
67    fn from(value: TransactionInputs) -> Self {
68        (&value).into()
69    }
70}