Skip to main content

fedimint_gwv2_client/
api.rs

1use fedimint_api_client::api::{FederationApiExt, FederationResult, IModuleFederationApi};
2use fedimint_core::module::ApiRequestErased;
3use fedimint_core::task::{MaybeSend, MaybeSync};
4use fedimint_core::{OutPoint, apply, async_trait_maybe_send};
5use fedimint_lnv2_common::ContractId;
6use fedimint_lnv2_common::endpoint_constants::{
7    CONSENSUS_BLOCK_COUNT_ENDPOINT, OUTGOING_CONTRACT_EXPIRATION_ENDPOINT,
8};
9
10#[apply(async_trait_maybe_send!)]
11pub trait GatewayFederationApi {
12    async fn outgoing_contract_expiration(
13        &self,
14        outpoint: OutPoint,
15    ) -> FederationResult<Option<(ContractId, u64)>>;
16
17    /// The consensus block count, answered once a threshold of guardians
18    /// report the same value.
19    async fn consensus_block_count(&self) -> FederationResult<u64>;
20}
21
22#[apply(async_trait_maybe_send!)]
23impl<T: ?Sized> GatewayFederationApi for T
24where
25    T: IModuleFederationApi + MaybeSend + MaybeSync + 'static,
26{
27    async fn outgoing_contract_expiration(
28        &self,
29        outpoint: OutPoint,
30    ) -> FederationResult<Option<(ContractId, u64)>> {
31        self.request_current_consensus(
32            OUTGOING_CONTRACT_EXPIRATION_ENDPOINT.to_string(),
33            ApiRequestErased::new(outpoint),
34        )
35        .await
36    }
37
38    async fn consensus_block_count(&self) -> FederationResult<u64> {
39        self.request_current_consensus(
40            CONSENSUS_BLOCK_COUNT_ENDPOINT.to_string(),
41            ApiRequestErased::new(()),
42        )
43        .await
44    }
45}