sui_jsonrpc/api/
coin.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use jsonrpsee::proc_macros::rpc;
5use sui_sdk_types::Address;
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: Address,
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: Address,
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: Address, coin_type: Option<String>) -> RpcResult<Balance>;
33
34    /// Return the total coin balance for all coin type, owned by the address owner.
35    #[method(name = "getAllBalances")]
36    async fn get_all_balances(&self, owner: Address) -> RpcResult<Vec<Balance>>;
37
38    /// Return metadata (e.g., symbol, decimals) for a coin.
39    ///
40    /// Note that if the coin's metadata was
41    /// wrapped in the transaction that published its marker type, or the latest version of the
42    /// metadata object is wrapped or deleted, it will not be found.
43    #[method(name = "getCoinMetadata")]
44    async fn get_coin_metadata(&self, coin_type: String) -> RpcResult<Option<SuiCoinMetadata>>;
45
46    /// Return total supply for a coin
47    #[method(name = "getTotalSupply")]
48    async fn get_total_supply(&self, coin_type: String) -> RpcResult<Supply>;
49}