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