sui_jsonrpc/api/
coin.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use af_sui_types::Address as SuiAddress;
5use jsonrpsee::proc_macros::rpc;
6
7use crate::msgs::{Balance, CoinPage, SuiCoinMetadata, Supply};
8
9#[rpc(client, namespace = "suix")]
10pub trait CoinReadApi {
11    /// Return all Coin<`coin_type`> objects owned by an address.
12    #[method(name = "getCoins")]
13    async fn get_coins(
14        &self,
15        owner: SuiAddress,
16        coin_type: Option<String>,
17        cursor: Option<String>,
18        limit: Option<usize>,
19    ) -> RpcResult<CoinPage>;
20
21    /// Return all Coin objects owned by an address.
22    #[method(name = "getAllCoins")]
23    async fn get_all_coins(
24        &self,
25        owner: SuiAddress,
26        cursor: Option<String>,
27        limit: Option<usize>,
28    ) -> RpcResult<CoinPage>;
29
30    /// Return the total coin balance for one coin type, owned by the address owner.
31    #[method(name = "getBalance")]
32    async fn get_balance(&self, owner: SuiAddress, coin_type: Option<String>)
33    -> RpcResult<Balance>;
34
35    /// Return the total coin balance for all coin type, owned by the address owner.
36    #[method(name = "getAllBalances")]
37    async fn get_all_balances(&self, owner: SuiAddress) -> RpcResult<Vec<Balance>>;
38
39    /// Return metadata (e.g., symbol, decimals) for a coin.
40    ///
41    /// Note that if the coin's metadata was
42    /// wrapped in the transaction that published its marker type, or the latest version of the
43    /// metadata object is wrapped or deleted, it will not be found.
44    #[method(name = "getCoinMetadata")]
45    async fn get_coin_metadata(&self, coin_type: String) -> RpcResult<Option<SuiCoinMetadata>>;
46
47    /// Return total supply for a coin
48    #[method(name = "getTotalSupply")]
49    async fn get_total_supply(&self, coin_type: String) -> RpcResult<Supply>;
50}