use jsonrpsee::proc_macros::rpc;
use sp_core::{
storage::{StorageChangeSet, StorageData, StorageKey},
Bytes,
};
use sp_version::RuntimeVersion;
pub mod error;
pub mod helpers;
pub use self::helpers::ReadProof;
pub use error::Error;
#[rpc(client, server)]
pub trait StateApi<Hash> {
#[method(name = "state_call", aliases = ["state_callAt"], blocking)]
fn call(&self, name: String, bytes: Bytes, hash: Option<Hash>) -> Result<Bytes, Error>;
#[method(name = "state_getKeys", blocking)]
#[deprecated(since = "2.0.0", note = "Please use `getKeysPaged` with proper paging support")]
fn storage_keys(
&self,
prefix: StorageKey,
hash: Option<Hash>,
) -> Result<Vec<StorageKey>, Error>;
#[method(name = "state_getPairs", blocking, with_extensions)]
fn storage_pairs(
&self,
prefix: StorageKey,
hash: Option<Hash>,
) -> Result<Vec<(StorageKey, StorageData)>, Error>;
#[method(name = "state_getKeysPaged", aliases = ["state_getKeysPagedAt"], blocking)]
fn storage_keys_paged(
&self,
prefix: Option<StorageKey>,
count: u32,
start_key: Option<StorageKey>,
hash: Option<Hash>,
) -> Result<Vec<StorageKey>, Error>;
#[method(name = "state_getStorage", aliases = ["state_getStorageAt"], blocking)]
fn storage(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<StorageData>, Error>;
#[method(name = "state_getStorageHash", aliases = ["state_getStorageHashAt"], blocking)]
fn storage_hash(&self, key: StorageKey, hash: Option<Hash>) -> Result<Option<Hash>, Error>;
#[method(name = "state_getStorageSize", aliases = ["state_getStorageSizeAt"], with_extensions)]
async fn storage_size(&self, key: StorageKey, hash: Option<Hash>)
-> Result<Option<u64>, Error>;
#[method(name = "state_getMetadata", blocking)]
fn metadata(&self, hash: Option<Hash>) -> Result<Bytes, Error>;
#[method(name = "state_getRuntimeVersion", aliases = ["chain_getRuntimeVersion"], blocking)]
fn runtime_version(&self, hash: Option<Hash>) -> Result<RuntimeVersion, Error>;
#[method(name = "state_queryStorage", blocking, with_extensions)]
fn query_storage(
&self,
keys: Vec<StorageKey>,
block: Hash,
hash: Option<Hash>,
) -> Result<Vec<StorageChangeSet<Hash>>, Error>;
#[method(name = "state_queryStorageAt", blocking)]
fn query_storage_at(
&self,
keys: Vec<StorageKey>,
at: Option<Hash>,
) -> Result<Vec<StorageChangeSet<Hash>>, Error>;
#[method(name = "state_getReadProof", blocking)]
fn read_proof(
&self,
keys: Vec<StorageKey>,
hash: Option<Hash>,
) -> Result<ReadProof<Hash>, Error>;
#[subscription(
name = "state_subscribeRuntimeVersion" => "state_runtimeVersion",
unsubscribe = "state_unsubscribeRuntimeVersion",
aliases = ["chain_subscribeRuntimeVersion"],
unsubscribe_aliases = ["chain_unsubscribeRuntimeVersion"],
item = RuntimeVersion,
)]
fn subscribe_runtime_version(&self);
#[subscription(
name = "state_subscribeStorage" => "state_storage",
unsubscribe = "state_unsubscribeStorage",
item = StorageChangeSet<Hash>,
with_extensions,
)]
fn subscribe_storage(&self, keys: Option<Vec<StorageKey>>);
#[method(name = "state_traceBlock", blocking, with_extensions)]
fn trace_block(
&self,
block: Hash,
targets: Option<String>,
storage_keys: Option<String>,
methods: Option<String>,
) -> Result<sp_rpc::tracing::TraceBlockResponse, Error>;
}