Skip to main content

miden_client/rpc/domain/
nullifier.rs

1use miden_protocol::Word;
2use miden_protocol::block::BlockNumber;
3use miden_protocol::note::Nullifier;
4
5use crate::rpc::domain::MissingFieldHelper;
6use crate::rpc::errors::RpcConversionError;
7use crate::rpc::generated as proto;
8
9// NULLIFIER UPDATE
10// ================================================================================================
11
12/// Represents a note that was consumed in the node at a certain block.
13#[derive(Debug, Clone, Eq, PartialOrd, Ord)]
14pub struct NullifierUpdate {
15    /// The nullifier of the consumed note.
16    pub nullifier: Nullifier,
17    /// The number of the block in which the note consumption was registered.
18    pub block_num: BlockNumber,
19}
20
21impl PartialEq for NullifierUpdate {
22    fn eq(&self, other: &Self) -> bool {
23        self.nullifier == other.nullifier
24    }
25}
26
27// CONVERSIONS
28// ================================================================================================
29
30impl TryFrom<proto::primitives::Digest> for Nullifier {
31    type Error = RpcConversionError;
32
33    fn try_from(value: proto::primitives::Digest) -> Result<Self, Self::Error> {
34        let word: Word = value.try_into()?;
35        Ok(Self::from_raw(word))
36    }
37}
38
39impl TryFrom<&proto::rpc::sync_nullifiers_response::NullifierUpdate> for NullifierUpdate {
40    type Error = RpcConversionError;
41
42    fn try_from(
43        value: &proto::rpc::sync_nullifiers_response::NullifierUpdate,
44    ) -> Result<Self, Self::Error> {
45        Ok(Self {
46            nullifier: value
47                .nullifier
48                .ok_or(proto::rpc::sync_nullifiers_response::NullifierUpdate::missing_field(
49                    stringify!(nullifier),
50                ))?
51                .try_into()?,
52            block_num: value.block_num.into(),
53        })
54    }
55}