miden_client/rpc/domain/
nullifier.rs

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