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::serde::Serializable;
7
8use crate::decode::{ConversionResultExt, DecodeBytesExt, GrpcDecodeExt};
9use crate::errors::ConversionError;
10use crate::generated as proto;
11
12#[derive(Clone, Debug)]
14pub struct BatchInputs {
15 pub batch_reference_block_header: BlockHeader,
16 pub note_proofs: BTreeMap<NoteId, NoteInclusionProof>,
17 pub partial_block_chain: PartialBlockchain,
18}
19
20impl From<BatchInputs> for proto::store::BatchInputs {
21 fn from(inputs: BatchInputs) -> Self {
22 Self {
23 batch_reference_block_header: Some(inputs.batch_reference_block_header.into()),
24 note_proofs: inputs.note_proofs.iter().map(Into::into).collect(),
25 partial_block_chain: inputs.partial_block_chain.to_bytes(),
26 }
27 }
28}
29
30impl TryFrom<proto::store::BatchInputs> for BatchInputs {
31 type Error = ConversionError;
32
33 fn try_from(response: proto::store::BatchInputs) -> Result<Self, ConversionError> {
34 let decoder = response.decoder();
35 let result = Self {
36 batch_reference_block_header: crate::decode!(
37 decoder,
38 response.batch_reference_block_header
39 )?,
40 note_proofs: response
41 .note_proofs
42 .iter()
43 .map(<(NoteId, NoteInclusionProof)>::try_from)
44 .collect::<Result<_, ConversionError>>()
45 .context("note_proofs")?,
46 partial_block_chain: PartialBlockchain::decode_bytes(
47 &response.partial_block_chain,
48 "PartialBlockchain",
49 )?,
50 };
51
52 Ok(result)
53 }
54}