Skip to main content

circles_rpc/methods/
balance.rs

1use crate::client::RpcClient;
2use crate::error::Result;
3use circles_types::{Address, Balance};
4
5/// Methods for aggregate balance queries (`circles_getTotalBalance` / `circlesV2_getTotalBalance`).
6#[derive(Clone, Debug)]
7pub struct BalanceMethods {
8    client: RpcClient,
9}
10
11impl BalanceMethods {
12    /// Create a new accessor for balance RPCs.
13    pub fn new(client: RpcClient) -> Self {
14        Self { client }
15    }
16
17    /// circles_getTotalBalance / circlesV2_getTotalBalance
18    pub async fn get_total_balance(
19        &self,
20        address: Address,
21        as_time_circles: bool,
22        use_v2: bool,
23    ) -> Result<Balance> {
24        let method = if use_v2 {
25            "circlesV2_getTotalBalance"
26        } else {
27            "circles_getTotalBalance"
28        };
29        self.client.call(method, (address, as_time_circles)).await
30    }
31}