Skip to main content

cdk_mint_rpc/
wallet_info.rs

1//! Read-only on-chain wallet information provider.
2
3use std::sync::Arc;
4
5use async_trait::async_trait;
6use thiserror::Error;
7
8use crate::wallet::{GetBalanceResponse, WalletAddress, WalletTransaction};
9
10/// Error returned while reading the configured on-chain wallet.
11#[derive(Debug, Error)]
12#[error("{message}")]
13pub struct WalletInfoError {
14    message: String,
15}
16
17impl WalletInfoError {
18    /// Creates an error from a backend-provided message.
19    pub fn new(message: impl Into<String>) -> Self {
20        Self {
21            message: message.into(),
22        }
23    }
24}
25
26/// A page of wallet transactions.
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct WalletTransactionPage {
29    /// Transactions in newest-first order.
30    pub transactions: Vec<WalletTransaction>,
31    /// Total transactions before pagination.
32    pub total: u64,
33}
34
35/// A page of revealed wallet addresses.
36#[derive(Debug, Clone, PartialEq, Eq)]
37pub struct WalletAddressPage {
38    /// Revealed addresses in derivation order.
39    pub addresses: Vec<WalletAddress>,
40    /// Total revealed addresses before pagination.
41    pub total: u64,
42}
43
44/// Supplies read-only information for the management wallet service.
45#[async_trait]
46pub trait WalletInfoProvider {
47    /// Returns the wallet balance.
48    async fn get_balance(&self) -> Result<GetBalanceResponse, WalletInfoError>;
49
50    /// Returns a page of wallet transactions.
51    async fn list_transactions(
52        &self,
53        offset: usize,
54        limit: usize,
55    ) -> Result<WalletTransactionPage, WalletInfoError>;
56
57    /// Returns a page of revealed wallet addresses.
58    async fn list_addresses(
59        &self,
60        offset: usize,
61        limit: usize,
62    ) -> Result<WalletAddressPage, WalletInfoError>;
63}
64
65/// Dynamically dispatched wallet information provider.
66pub type DynWalletInfoProvider = Arc<dyn WalletInfoProvider + Send + Sync>;