miden_objects/block/
block_inputs.rs

1use alloc::collections::BTreeMap;
2
3use crate::account::AccountId;
4use crate::block::{AccountWitness, BlockHeader, NullifierWitness};
5use crate::note::{NoteId, NoteInclusionProof, Nullifier};
6use crate::transaction::PartialBlockchain;
7
8// BLOCK INPUTS
9// ================================================================================================
10
11/// The required inputs for building a [`ProposedBlock`](crate::block::ProposedBlock).
12#[derive(Clone, Debug)]
13pub struct BlockInputs {
14    /// The previous block header that the block should reference.
15    prev_block_header: BlockHeader,
16
17    /// The chain state at the previous block with authentication paths for:
18    /// - each block referenced by a batch in the block,
19    /// - each block referenced by a note inclusion proof for an unauthenticated note.
20    partial_blockchain: PartialBlockchain,
21
22    /// The state commitments of the accounts in the block and their authentication paths.
23    account_witnesses: BTreeMap<AccountId, AccountWitness>,
24
25    /// The nullifiers of the notes consumed in the block and their authentication paths.
26    nullifier_witnesses: BTreeMap<Nullifier, NullifierWitness>,
27
28    /// Note inclusion proofs for all unauthenticated notes in the block that are not erased (i.e.
29    /// created and consumed within the block).
30    unauthenticated_note_proofs: BTreeMap<NoteId, NoteInclusionProof>,
31}
32
33impl BlockInputs {
34    /// Creates new [`BlockInputs`] from the provided parts.
35    pub fn new(
36        prev_block_header: BlockHeader,
37        partial_blockchain: PartialBlockchain,
38        account_witnesses: BTreeMap<AccountId, AccountWitness>,
39        nullifier_witnesses: BTreeMap<Nullifier, NullifierWitness>,
40        unauthenticated_note_proofs: BTreeMap<NoteId, NoteInclusionProof>,
41    ) -> Self {
42        Self {
43            prev_block_header,
44            partial_blockchain,
45            account_witnesses,
46            nullifier_witnesses,
47            unauthenticated_note_proofs,
48        }
49    }
50
51    /// Returns a reference to the previous block header.
52    pub fn prev_block_header(&self) -> &BlockHeader {
53        &self.prev_block_header
54    }
55
56    /// Returns a reference to the [`PartialBlockchain`].
57    pub fn partial_blockchain(&self) -> &PartialBlockchain {
58        &self.partial_blockchain
59    }
60
61    /// Returns a reference to the account witnesses.
62    pub fn account_witnesses(&self) -> &BTreeMap<AccountId, AccountWitness> {
63        &self.account_witnesses
64    }
65
66    /// Returns a reference to the nullifier witnesses.
67    pub fn nullifier_witnesses(&self) -> &BTreeMap<Nullifier, NullifierWitness> {
68        &self.nullifier_witnesses
69    }
70
71    /// Returns a reference to the note inclusion proofs.
72    pub fn unauthenticated_note_proofs(&self) -> &BTreeMap<NoteId, NoteInclusionProof> {
73        &self.unauthenticated_note_proofs
74    }
75
76    /// Consumes self and returns the underlying parts.
77    #[allow(clippy::type_complexity)]
78    pub fn into_parts(
79        self,
80    ) -> (
81        BlockHeader,
82        PartialBlockchain,
83        BTreeMap<AccountId, AccountWitness>,
84        BTreeMap<Nullifier, NullifierWitness>,
85        BTreeMap<NoteId, NoteInclusionProof>,
86    ) {
87        (
88            self.prev_block_header,
89            self.partial_blockchain,
90            self.account_witnesses,
91            self.nullifier_witnesses,
92            self.unauthenticated_note_proofs,
93        )
94    }
95
96    // TESTING
97    // --------------------------------------------------------------------------------------------
98
99    /// Returns a mutable reference to the [`PartialBlockchain`].
100    ///
101    /// Allows mutating the inner partial blockchain for testing purposes.
102    #[cfg(any(feature = "testing", test))]
103    pub fn partial_blockchain_mut(&mut self) -> &mut PartialBlockchain {
104        &mut self.partial_blockchain
105    }
106
107    /// Returns a mutable reference to the note inclusion proofs.
108    ///
109    /// Allows mutating the inner note proofs map for testing purposes.
110    #[cfg(any(feature = "testing", test))]
111    pub fn unauthenticated_note_proofs_mut(&mut self) -> &mut BTreeMap<NoteId, NoteInclusionProof> {
112        &mut self.unauthenticated_note_proofs
113    }
114
115    /// Returns a mutable reference to the nullifier witnesses.
116    ///
117    /// Allows mutating the inner nullifier witnesses map for testing purposes.
118    #[cfg(any(feature = "testing", test))]
119    pub fn nullifier_witnesses_mut(&mut self) -> &mut BTreeMap<Nullifier, NullifierWitness> {
120        &mut self.nullifier_witnesses
121    }
122
123    /// Returns a mutable reference to the account witnesses.
124    ///
125    /// Allows mutating the inner account witnesses map for testing purposes.
126    #[cfg(any(feature = "testing", test))]
127    pub fn account_witnesses_mut(&mut self) -> &mut BTreeMap<AccountId, AccountWitness> {
128        &mut self.account_witnesses
129    }
130}