Skip to main content

miden_objects/conversion/
batch.rs

1use miden_protocol::batch::{BatchAccountUpdate, ProposedBatch, ProvenBatch};
2
3use crate::proto;
4
5impl From<&BatchAccountUpdate> for proto::transaction::BatchAccountUpdate {
6    fn from(value: &BatchAccountUpdate) -> Self {
7        Self {
8            account_id: Some(value.account_id().into()),
9            initial_state_commitment: Some(value.initial_state_commitment().into()),
10            final_state_commitment: Some(value.final_state_commitment().into()),
11            details: Some(value.details().into()),
12        }
13    }
14}
15
16impl From<&ProposedBatch> for proto::transaction::ProposedBatch {
17    fn from(value: &ProposedBatch) -> Self {
18        let (transactions, reference_block_header, partial_blockchain, note_proofs, ..) =
19            value.clone().into_parts();
20        Self {
21            transactions: transactions.iter().map(|tx| tx.as_ref().into()).collect(),
22            reference_block_header: Some(reference_block_header.into()),
23            partial_blockchain: Some((&partial_blockchain).into()),
24            unauthenticated_note_proofs: note_proofs.iter().map(Into::into).collect(),
25        }
26    }
27}
28
29impl From<ProposedBatch> for proto::transaction::ProposedBatch {
30    fn from(value: ProposedBatch) -> Self {
31        Self::from(&value)
32    }
33}
34
35impl From<&ProvenBatch> for proto::transaction::ProvenBatch {
36    fn from(value: &ProvenBatch) -> Self {
37        Self {
38            reference_block_commitment: Some(value.reference_block_commitment().into()),
39            reference_block_num: Some(value.reference_block_num().into()),
40            account_updates: value.account_updates().values().map(Into::into).collect(),
41            input_notes: value.input_notes().iter().map(Into::into).collect(),
42            output_notes: value.output_notes().iter().map(Into::into).collect(),
43            expiration_block_num: Some(value.batch_expiration_block_num().into()),
44            transactions: value.transactions().as_slice().iter().map(Into::into).collect(),
45            proof: Some(value.proof().into()),
46        }
47    }
48}
49
50impl From<ProvenBatch> for proto::transaction::ProvenBatch {
51    fn from(value: ProvenBatch) -> Self {
52        Self::from(&value)
53    }
54}