fedimint_mint_client/
api.rs

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
use fedimint_api_client::api::{FederationApiExt, FederationResult, IModuleFederationApi};
use fedimint_core::module::ApiRequestErased;
use fedimint_core::task::{MaybeSend, MaybeSync};
use fedimint_core::{apply, async_trait_maybe_send};
use fedimint_mint_common::endpoint_constants::{BLIND_NONCE_USED_ENDPOINT, NOTE_SPENT_ENDPOINT};
use fedimint_mint_common::{BlindNonce, Nonce};

#[apply(async_trait_maybe_send!)]
pub trait MintFederationApi {
    /// Check if an e-cash  note was already issued for the given blind nonce.
    async fn check_blind_nonce_used(&self, blind_nonce: BlindNonce) -> FederationResult<bool>;

    /// Check if an e-cash note was already spent.
    async fn check_note_spent(&self, nonce: Nonce) -> FederationResult<bool>;
}

#[apply(async_trait_maybe_send!)]
impl<T: ?Sized> MintFederationApi for T
where
    T: IModuleFederationApi + MaybeSend + MaybeSync + 'static,
{
    async fn check_blind_nonce_used(&self, blind_nonce: BlindNonce) -> FederationResult<bool> {
        self.request_current_consensus(
            BLIND_NONCE_USED_ENDPOINT.to_string(),
            ApiRequestErased::new(blind_nonce),
        )
        .await
    }

    async fn check_note_spent(&self, nonce: Nonce) -> FederationResult<bool> {
        self.request_current_consensus(
            NOTE_SPENT_ENDPOINT.to_string(),
            ApiRequestErased::new(nonce),
        )
        .await
    }
}