Skip to main content

miden_client/rpc/domain/
sync.rs

1use alloc::vec::Vec;
2
3use miden_protocol::Word;
4use miden_protocol::account::AccountId;
5use miden_protocol::block::{BlockHeader, BlockNumber};
6use miden_protocol::crypto::merkle::mmr::MmrDelta;
7
8use super::note::CommittedNote;
9use super::transaction::TransactionInclusion;
10use crate::rpc::domain::MissingFieldHelper;
11use crate::rpc::{RpcError, generated as proto};
12
13// STATE SYNC INFO
14// ================================================================================================
15
16/// Represents the composed result of `sync_notes`, `sync_chain_mmr`, and `sync_transactions`
17/// with fields converted into domain types.
18pub struct StateSyncInfo {
19    /// The block number of the chain tip at the moment of the response.
20    pub chain_tip: BlockNumber,
21    /// The returned block header.
22    pub block_header: BlockHeader,
23    /// MMR delta that contains data for (`current_block.num`, `incoming_block_header.num-1`).
24    pub mmr_delta: MmrDelta,
25    /// Tuples of `AccountId` alongside their new account commitments.
26    pub account_commitment_updates: Vec<(AccountId, Word)>,
27    /// List of tuples of Note ID, Note Index and Merkle Path for all new notes.
28    pub note_inclusions: Vec<CommittedNote>,
29    /// List of transaction IDs of transaction that were included in (`request.block_num`,
30    /// `response.block_num-1`) along with the account the tx was executed against and the block
31    /// number the transaction was included in.
32    pub transactions: Vec<TransactionInclusion>,
33}
34
35// CHAIN MMR INFO
36// ================================================================================================
37
38/// Represents the result of a `SyncChainMmr` RPC call, with fields converted into domain types.
39pub struct ChainMmrInfo {
40    /// The MMR delta for the requested block range.
41    pub mmr_delta: MmrDelta,
42}
43
44impl TryFrom<proto::rpc::SyncChainMmrResponse> for ChainMmrInfo {
45    type Error = RpcError;
46
47    fn try_from(value: proto::rpc::SyncChainMmrResponse) -> Result<Self, Self::Error> {
48        let mmr_delta = value
49            .mmr_delta
50            .ok_or(proto::rpc::SyncChainMmrResponse::missing_field(stringify!(mmr_delta)))?
51            .try_into()?;
52
53        Ok(Self { mmr_delta })
54    }
55}