Skip to main content

celestia_rpc/
state.rs

1use celestia_types::blob::RawBlob;
2use celestia_types::state::{
3    AccAddress, Address, Coin, QueryDelegationResponse, QueryRedelegationsResponse,
4    QueryUnbondingDelegationResponse, RawTxResponse, ValAddress,
5};
6use jsonrpsee::core::RpcResult;
7use jsonrpsee::proc_macros::rpc;
8
9use crate::TxConfig;
10
11/// State RPC methods.
12#[rpc(client, server, namespace = "state", namespace_separator = ".")]
13pub trait State {
14    /// Returns the default account address for the node.
15    #[method(name = "AccountAddress")]
16    async fn state_account_address(&self) -> RpcResult<Address>;
17
18    /// Returns the balance for the node's default account.
19    #[method(name = "Balance")]
20    async fn state_balance(&self) -> RpcResult<Coin>;
21
22    /// Retrieves the Celestia coin balance for a specific address.
23    /// Verifies the returned balance against the corresponding block's AppHash.
24    #[method(name = "BalanceForAddress")]
25    async fn state_balance_for_address(&self, addr: Address) -> RpcResult<Coin>;
26
27    /// Begins a redelegation from one validator to another.
28    #[method(name = "BeginRedelegate")]
29    async fn state_begin_redelegate(
30        &self,
31        src: ValAddress,
32        dest: ValAddress,
33        amount: u64,
34        config: TxConfig,
35    ) -> RpcResult<RawTxResponse>;
36
37    /// Cancels an unbonding delegation at a specific height.
38    #[method(name = "CancelUnbondingDelegation")]
39    async fn state_cancel_unbonding_delegation(
40        &self,
41        addr: ValAddress,
42        amount: u64,
43        height: u64,
44        config: TxConfig,
45    ) -> RpcResult<RawTxResponse>;
46
47    /// Delegates tokens to a validator.
48    #[method(name = "Delegate")]
49    async fn state_delegate(
50        &self,
51        addr: ValAddress,
52        amount: u64,
53        config: TxConfig,
54    ) -> RpcResult<RawTxResponse>;
55
56    /// Checks whether the state service is stopped.
57    #[method(name = "IsStopped")]
58    async fn state_is_stopped(&self) -> RpcResult<bool>;
59
60    /// Queries delegation details for the given validator address.
61    #[method(name = "QueryDelegation")]
62    async fn state_query_delegation(&self, addr: ValAddress) -> RpcResult<QueryDelegationResponse>;
63    //
64
65    /// Queries redelegations between the given validators.
66    #[method(name = "QueryRedelegations")]
67    async fn state_query_redelegations(
68        &self,
69        src: ValAddress,
70        dest: ValAddress,
71    ) -> RpcResult<QueryRedelegationsResponse>;
72
73    /// Queries unbonding delegations for the given validator address.
74    #[method(name = "QueryUnbonding")]
75    async fn state_query_unbonding(
76        &self,
77        addr: ValAddress,
78    ) -> RpcResult<QueryUnbondingDelegationResponse>;
79
80    /// Submits a pay-for-blob transaction for the provided blobs.
81    #[method(name = "SubmitPayForBlob")]
82    async fn state_submit_pay_for_blob(
83        &self,
84        blobs: Vec<RawBlob>,
85        config: TxConfig,
86    ) -> RpcResult<RawTxResponse>;
87
88    /// Transfers tokens to a destination account.
89    #[method(name = "Transfer")]
90    async fn state_transfer(
91        &self,
92        to: AccAddress,
93        amount: u64,
94        config: TxConfig,
95    ) -> RpcResult<RawTxResponse>;
96
97    /// Undelegates tokens from a validator.
98    #[method(name = "Undelegate")]
99    async fn state_undelegate(
100        &self,
101        addr: ValAddress,
102        amount: u64,
103        config: TxConfig,
104    ) -> RpcResult<RawTxResponse>;
105}