miden_client/rpc/domain/
nullifier.rs

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