sui_json_rpc_api/coin.rs
1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use jsonrpsee::core::RpcResult;
5use jsonrpsee::proc_macros::rpc;
6use sui_json_rpc_types::{Balance, CoinPage, SuiCoinMetadata};
7use sui_open_rpc_macros::open_rpc;
8use sui_types::balance::Supply;
9use sui_types::base_types::SuiAddress;
10
11#[open_rpc(namespace = "suix", tag = "Coin Query API")]
12#[rpc(server, client, namespace = "suix")]
13pub trait CoinReadApi {
14 /// Return all Coin<`coin_type`> objects owned by an address.
15 #[method(name = "getCoins")]
16 async fn get_coins(
17 &self,
18 /// the owner's Sui address
19 owner: SuiAddress,
20 /// optional type name for the coin (e.g., 0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC), default to 0x2::sui::SUI if not specified.
21 coin_type: Option<String>,
22 /// optional paging cursor
23 cursor: Option<String>,
24 /// maximum number of items per page
25 limit: Option<usize>,
26 ) -> RpcResult<CoinPage>;
27
28 /// Return all Coin objects owned by an address.
29 #[method(name = "getAllCoins")]
30 async fn get_all_coins(
31 &self,
32 /// the owner's Sui address
33 owner: SuiAddress,
34 /// optional paging cursor
35 cursor: Option<String>,
36 /// maximum number of items per page
37 limit: Option<usize>,
38 ) -> RpcResult<CoinPage>;
39
40 /// Return the total coin balance for one coin type, owned by the address owner.
41 #[method(name = "getBalance")]
42 async fn get_balance(
43 &self,
44 /// the owner's Sui address
45 owner: SuiAddress,
46 /// optional type names for the coin (e.g., 0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC), default to 0x2::sui::SUI if not specified.
47 coin_type: Option<String>,
48 ) -> RpcResult<Balance>;
49
50 /// Return the total coin balance for all coin type, owned by the address owner.
51 #[method(name = "getAllBalances")]
52 async fn get_all_balances(
53 &self,
54 /// the owner's Sui address
55 owner: SuiAddress,
56 ) -> RpcResult<Vec<Balance>>;
57
58 /// Return metadata (e.g., symbol, decimals) for a coin. Note that if the coin's metadata was
59 /// wrapped in the transaction that published its marker type, or the latest version of the
60 /// metadata object is wrapped or deleted, it will not be found.
61 #[method(name = "getCoinMetadata")]
62 async fn get_coin_metadata(
63 &self,
64 /// type name for the coin (e.g., 0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC)
65 coin_type: String,
66 ) -> RpcResult<Option<SuiCoinMetadata>>;
67
68 /// Return total supply for a coin
69 #[method(name = "getTotalSupply")]
70 async fn get_total_supply(
71 &self,
72 /// type name for the coin (e.g., 0x168da5bf1f48dafc111b0a488fa454aca95e0b5e::usdc::USDC)
73 coin_type: String,
74 ) -> RpcResult<Supply>;
75}