relay_substrate_client/client/
rpc_api.rs1use crate::{Chain, ChainWithGrandpa, TransactionStatusOf};
20
21use jsonrpsee::proc_macros::rpc;
22use pallet_transaction_payment_rpc_runtime_api::FeeDetails;
23use sc_rpc_api::{state::ReadProof, system::Health};
24use sp_core::{
25 storage::{StorageData, StorageKey},
26 Bytes,
27};
28use sp_rpc::number::NumberOrHex;
29use sp_version::RuntimeVersion;
30
31#[rpc(client, client_bounds(C: Chain), namespace = "system")]
33pub(crate) trait SubstrateSystem<C> {
34 #[method(name = "health")]
36 async fn health(&self) -> RpcResult<Health>;
37 #[method(name = "properties")]
39 async fn properties(&self) -> RpcResult<sc_chain_spec::Properties>;
40}
41
42#[rpc(client, client_bounds(C: Chain), namespace = "chain")]
44pub(crate) trait SubstrateChain<C> {
45 #[method(name = "getBlockHash")]
47 async fn block_hash(&self, block_number: Option<C::BlockNumber>) -> RpcResult<C::Hash>;
48 #[method(name = "getHeader")]
50 async fn header(&self, block_hash: Option<C::Hash>) -> RpcResult<C::Header>;
51 #[method(name = "getFinalizedHead")]
53 async fn finalized_head(&self) -> RpcResult<C::Hash>;
54 #[method(name = "getBlock")]
56 async fn block(&self, block_hash: Option<C::Hash>) -> RpcResult<C::SignedBlock>;
57 #[subscription(
59 name = "subscribeNewHeads" => "newHead",
60 unsubscribe = "unsubscribeNewHeads",
61 item = C::Header
62 )]
63 async fn subscribe_new_heads(&self);
64 #[subscription(
66 name = "subscribeFinalizedHeads" => "finalizedHead",
67 unsubscribe = "unsubscribeFinalizedHeads",
68 item = C::Header
69 )]
70 async fn subscribe_finalized_heads(&self);
71}
72
73#[rpc(client, client_bounds(C: Chain), namespace = "author")]
75pub(crate) trait SubstrateAuthor<C> {
76 #[method(name = "submitExtrinsic")]
78 async fn submit_extrinsic(&self, extrinsic: Bytes) -> RpcResult<C::Hash>;
79 #[method(name = "pendingExtrinsics")]
81 async fn pending_extrinsics(&self) -> RpcResult<Vec<Bytes>>;
82 #[subscription(name = "submitAndWatchExtrinsic", unsubscribe = "unwatchExtrinsic", item = TransactionStatusOf<C>)]
84 async fn submit_and_watch_extrinsic(&self, extrinsic: Bytes);
85}
86
87#[rpc(client, client_bounds(C: Chain), namespace = "state")]
89pub(crate) trait SubstrateState<C> {
90 #[method(name = "getRuntimeVersion")]
92 async fn runtime_version(&self) -> RpcResult<RuntimeVersion>;
93 #[method(name = "call")]
95 async fn call(
96 &self,
97 method: String,
98 data: Bytes,
99 at_block: Option<C::Hash>,
100 ) -> RpcResult<Bytes>;
101 #[method(name = "getStorage")]
103 async fn storage(
104 &self,
105 key: StorageKey,
106 at_block: Option<C::Hash>,
107 ) -> RpcResult<Option<StorageData>>;
108 #[method(name = "getReadProof")]
110 async fn prove_storage(
111 &self,
112 keys: Vec<StorageKey>,
113 hash: Option<C::Hash>,
114 ) -> RpcResult<ReadProof<C::Hash>>;
115}
116
117#[rpc(client, client_bounds(C: ChainWithGrandpa), namespace = "grandpa")]
119pub(crate) trait SubstrateGrandpa<C> {
120 #[subscription(name = "subscribeJustifications", unsubscribe = "unsubscribeJustifications", item = Bytes)]
122 async fn subscribe_justifications(&self);
123}
124
125#[rpc(client, client_bounds(C: Chain), namespace = "beefy")]
128pub(crate) trait SubstrateBeefy<C> {
129 #[subscription(name = "subscribeJustifications", unsubscribe = "unsubscribeJustifications", item = Bytes)]
131 async fn subscribe_justifications(&self);
132}
133
134#[rpc(client, client_bounds(C: Chain), namespace = "system")]
136pub(crate) trait SubstrateFrameSystem<C> {
137 #[method(name = "accountNextIndex")]
139 async fn account_next_index(&self, account_id: C::AccountId) -> RpcResult<C::Nonce>;
140}
141
142#[rpc(client, client_bounds(C: Chain), namespace = "payment")]
144pub(crate) trait SubstrateTransactionPayment<C> {
145 #[method(name = "queryFeeDetails")]
147 async fn fee_details(
148 &self,
149 extrinsic: Bytes,
150 at_block: Option<C::Hash>,
151 ) -> RpcResult<FeeDetails<NumberOrHex>>;
152}