miden_client/rpc/domain/
nullifier.rs

1use miden_objects::Word;
2use miden_objects::block::BlockNumber;
3use miden_objects::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)]
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
21// CONVERSIONS
22// ================================================================================================
23
24impl TryFrom<proto::primitives::Digest> for Nullifier {
25    type Error = RpcConversionError;
26
27    fn try_from(value: proto::primitives::Digest) -> Result<Self, Self::Error> {
28        let word: Word = value.try_into()?;
29        Ok(word.into())
30    }
31}
32
33impl TryFrom<&proto::rpc_store::sync_nullifiers_response::NullifierUpdate> for NullifierUpdate {
34    type Error = RpcConversionError;
35
36    fn try_from(
37        value: &proto::rpc_store::sync_nullifiers_response::NullifierUpdate,
38    ) -> Result<Self, Self::Error> {
39        Ok(Self {
40            nullifier: value
41                .nullifier
42                .ok_or(proto::rpc_store::sync_nullifiers_response::NullifierUpdate::missing_field(
43                    stringify!(nullifier),
44                ))?
45                .try_into()?,
46            block_num: value.block_num.into(),
47        })
48    }
49}