miden_node_proto/domain/
batch.rs1use std::collections::BTreeMap;
2
3use miden_protocol::block::BlockHeader;
4use miden_protocol::note::{NoteId, NoteInclusionProof};
5use miden_protocol::transaction::PartialBlockchain;
6use miden_protocol::utils::{Deserializable, Serializable};
7
8use crate::errors::{ConversionError, MissingFieldHelper};
9use crate::generated as proto;
10
11#[derive(Clone, Debug)]
13pub struct BatchInputs {
14 pub batch_reference_block_header: BlockHeader,
15 pub note_proofs: BTreeMap<NoteId, NoteInclusionProof>,
16 pub partial_block_chain: PartialBlockchain,
17}
18
19impl From<BatchInputs> for proto::store::BatchInputs {
20 fn from(inputs: BatchInputs) -> Self {
21 Self {
22 batch_reference_block_header: Some(inputs.batch_reference_block_header.into()),
23 note_proofs: inputs.note_proofs.iter().map(Into::into).collect(),
24 partial_block_chain: inputs.partial_block_chain.to_bytes(),
25 }
26 }
27}
28
29impl TryFrom<proto::store::BatchInputs> for BatchInputs {
30 type Error = ConversionError;
31
32 fn try_from(response: proto::store::BatchInputs) -> Result<Self, ConversionError> {
33 let result = Self {
34 batch_reference_block_header: response
35 .batch_reference_block_header
36 .ok_or(proto::store::BatchInputs::missing_field("block_header"))?
37 .try_into()?,
38 note_proofs: response
39 .note_proofs
40 .iter()
41 .map(<(NoteId, NoteInclusionProof)>::try_from)
42 .collect::<Result<_, ConversionError>>()?,
43 partial_block_chain: PartialBlockchain::read_from_bytes(&response.partial_block_chain)
44 .map_err(|source| {
45 ConversionError::deserialization_error("PartialBlockchain", source)
46 })?,
47 };
48
49 Ok(result)
50 }
51}