Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions client/rpc-api/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ pub mod error;
#[rpc(client, server)]
pub trait ChainApi<Number, Hash, Header, SignedBlock> {
/// Get header.
#[method(name = "chain_getHeader")]
async fn header(&self, hash: Option<Hash>) -> RpcResult<Option<Header>>;
#[method(name = "chain_getHeader", blocking)]
fn header(&self, hash: Option<Hash>) -> RpcResult<Option<Header>>;

/// Get header and body of a relay chain block.
#[method(name = "chain_getBlock")]
async fn block(&self, hash: Option<Hash>) -> RpcResult<Option<SignedBlock>>;
#[method(name = "chain_getBlock", blocking)]
fn block(&self, hash: Option<Hash>) -> RpcResult<Option<SignedBlock>>;

/// Get hash of the n-th block in the canon chain.
///
/// By default returns latest block hash.
#[method(name = "chain_getBlockHash", aliases = ["chain_getHead"])]
#[method(name = "chain_getBlockHash", aliases = ["chain_getHead"], blocking)]
fn block_hash(
&self,
hash: Option<ListOrValue<NumberOrHex>>,
) -> RpcResult<ListOrValue<Option<Hash>>>;

/// Get hash of the last finalized block in the canon chain.
#[method(name = "chain_getFinalizedHead", aliases = ["chain_getFinalisedHead"])]
#[method(name = "chain_getFinalizedHead", aliases = ["chain_getFinalisedHead"], blocking)]
fn finalized_head(&self) -> RpcResult<Hash>;

/// All head subscription.
Expand Down
28 changes: 14 additions & 14 deletions client/rpc-api/src/child_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ use sp_core::storage::{PrefixedStorageKey, StorageData, StorageKey};
#[rpc(client, server)]
pub trait ChildStateApi<Hash> {
/// Returns the keys with prefix from a child storage, leave empty to get all the keys
#[method(name = "childstate_getKeys")]
#[method(name = "childstate_getKeys", blocking)]
#[deprecated(since = "2.0.0", note = "Please use `getKeysPaged` with proper paging support")]
async fn storage_keys(
fn storage_keys(
&self,
child_storage_key: PrefixedStorageKey,
prefix: StorageKey,
Expand All @@ -40,8 +40,8 @@ pub trait ChildStateApi<Hash> {
/// Returns the keys with prefix from a child storage with pagination support.
/// Up to `count` keys will be returned.
/// If `start_key` is passed, return next keys in storage in lexicographic order.
#[method(name = "childstate_getKeysPaged", aliases = ["childstate_getKeysPagedAt"])]
async fn storage_keys_paged(
#[method(name = "childstate_getKeysPaged", aliases = ["childstate_getKeysPagedAt"], blocking)]
fn storage_keys_paged(
&self,
child_storage_key: PrefixedStorageKey,
prefix: Option<StorageKey>,
Expand All @@ -51,44 +51,44 @@ pub trait ChildStateApi<Hash> {
) -> RpcResult<Vec<StorageKey>>;

/// Returns a child storage entry at a specific block's state.
#[method(name = "childstate_getStorage")]
async fn storage(
#[method(name = "childstate_getStorage", blocking)]
fn storage(
&self,
child_storage_key: PrefixedStorageKey,
key: StorageKey,
hash: Option<Hash>,
) -> RpcResult<Option<StorageData>>;

/// Returns child storage entries for multiple keys at a specific block's state.
#[method(name = "childstate_getStorageEntries")]
async fn storage_entries(
#[method(name = "childstate_getStorageEntries", blocking)]
fn storage_entries(
&self,
child_storage_key: PrefixedStorageKey,
keys: Vec<StorageKey>,
hash: Option<Hash>,
) -> RpcResult<Vec<Option<StorageData>>>;

/// Returns the hash of a child storage entry at a block's state.
#[method(name = "childstate_getStorageHash")]
async fn storage_hash(
#[method(name = "childstate_getStorageHash", blocking)]
fn storage_hash(
&self,
child_storage_key: PrefixedStorageKey,
key: StorageKey,
hash: Option<Hash>,
) -> RpcResult<Option<Hash>>;

/// Returns the size of a child storage entry at a block's state.
#[method(name = "childstate_getStorageSize")]
async fn storage_size(
#[method(name = "childstate_getStorageSize", blocking)]
fn storage_size(
&self,
child_storage_key: PrefixedStorageKey,
key: StorageKey,
hash: Option<Hash>,
) -> RpcResult<Option<u64>>;

/// Returns proof of storage for child key entries at a specific block's state.
#[method(name = "state_getChildReadProof")]
async fn read_child_proof(
#[method(name = "state_getChildReadProof", blocking)]
fn read_child_proof(
&self,
child_storage_key: PrefixedStorageKey,
keys: Vec<StorageKey>,
Expand Down
60 changes: 26 additions & 34 deletions client/rpc-api/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,17 @@ pub use self::helpers::ReadProof;
#[rpc(client, server)]
pub trait StateApi<Hash> {
/// Call a contract at a block's state.
#[method(name = "state_call", aliases = ["state_callAt"])]
async fn call(&self, name: String, bytes: Bytes, hash: Option<Hash>) -> RpcResult<Bytes>;
#[method(name = "state_call", aliases = ["state_callAt"], blocking)]
fn call(&self, name: String, bytes: Bytes, hash: Option<Hash>) -> RpcResult<Bytes>;

/// Returns the keys with prefix, leave empty to get all the keys.
#[method(name = "state_getKeys")]
#[method(name = "state_getKeys", blocking)]
#[deprecated(since = "2.0.0", note = "Please use `getKeysPaged` with proper paging support")]
async fn storage_keys(
&self,
prefix: StorageKey,
hash: Option<Hash>,
) -> RpcResult<Vec<StorageKey>>;
fn storage_keys(&self, prefix: StorageKey, hash: Option<Hash>) -> RpcResult<Vec<StorageKey>>;

/// Returns the keys with prefix, leave empty to get all the keys
#[method(name = "state_getPairs")]
async fn storage_pairs(
#[method(name = "state_getPairs", blocking)]
fn storage_pairs(
&self,
prefix: StorageKey,
hash: Option<Hash>,
Expand All @@ -57,8 +53,8 @@ pub trait StateApi<Hash> {
/// Returns the keys with prefix with pagination support.
/// Up to `count` keys will be returned.
/// If `start_key` is passed, return next keys in storage in lexicographic order.
#[method(name = "state_getKeysPaged", aliases = ["state_getKeysPagedAt"])]
async fn storage_keys_paged(
#[method(name = "state_getKeysPaged", aliases = ["state_getKeysPagedAt"], blocking)]
fn storage_keys_paged(
&self,
prefix: Option<StorageKey>,
count: u32,
Expand All @@ -67,53 +63,49 @@ pub trait StateApi<Hash> {
) -> RpcResult<Vec<StorageKey>>;

/// Returns a storage entry at a specific block's state.
#[method(name = "state_getStorage", aliases = ["state_getStorageAt"])]
async fn storage(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<StorageData>>;
#[method(name = "state_getStorage", aliases = ["state_getStorageAt"], blocking)]
fn storage(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<StorageData>>;

/// Returns the hash of a storage entry at a block's state.
#[method(name = "state_getStorageHash", aliases = ["state_getStorageHashAt"])]
async fn storage_hash(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<Hash>>;
#[method(name = "state_getStorageHash", aliases = ["state_getStorageHashAt"], blocking)]
fn storage_hash(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<Hash>>;

/// Returns the size of a storage entry at a block's state.
#[method(name = "state_getStorageSize", aliases = ["state_getStorageSizeAt"])]
async fn storage_size(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<u64>>;
#[method(name = "state_getStorageSize", aliases = ["state_getStorageSizeAt"], blocking)]
fn storage_size(&self, key: StorageKey, hash: Option<Hash>) -> RpcResult<Option<u64>>;

/// Returns the runtime metadata as an opaque blob.
#[method(name = "state_getMetadata")]
async fn metadata(&self, hash: Option<Hash>) -> RpcResult<Bytes>;
#[method(name = "state_getMetadata", blocking)]
fn metadata(&self, hash: Option<Hash>) -> RpcResult<Bytes>;

/// Get the runtime version.
#[method(name = "state_getRuntimeVersion", aliases = ["chain_getRuntimeVersion"])]
async fn runtime_version(&self, hash: Option<Hash>) -> RpcResult<RuntimeVersion>;
#[method(name = "state_getRuntimeVersion", aliases = ["chain_getRuntimeVersion"], blocking)]
fn runtime_version(&self, hash: Option<Hash>) -> RpcResult<RuntimeVersion>;

/// Query historical storage entries (by key) starting from a block given as the second
/// parameter.
///
/// NOTE This first returned result contains the initial state of storage for all keys.
/// Subsequent values in the vector represent changes to the previous state (diffs).
#[method(name = "state_queryStorage")]
async fn query_storage(
#[method(name = "state_queryStorage", blocking)]
fn query_storage(
&self,
keys: Vec<StorageKey>,
block: Hash,
hash: Option<Hash>,
) -> RpcResult<Vec<StorageChangeSet<Hash>>>;

/// Query storage entries (by key) starting at block hash given as the second parameter.
#[method(name = "state_queryStorageAt")]
async fn query_storage_at(
#[method(name = "state_queryStorageAt", blocking)]
fn query_storage_at(
&self,
keys: Vec<StorageKey>,
at: Option<Hash>,
) -> RpcResult<Vec<StorageChangeSet<Hash>>>;

/// Returns proof of storage entries at a specific block's state.
#[method(name = "state_getReadProof")]
async fn read_proof(
&self,
keys: Vec<StorageKey>,
hash: Option<Hash>,
) -> RpcResult<ReadProof<Hash>>;
#[method(name = "state_getReadProof", blocking)]
fn read_proof(&self, keys: Vec<StorageKey>, hash: Option<Hash>) -> RpcResult<ReadProof<Hash>>;

/// New runtime version subscription
#[subscription(
Expand Down Expand Up @@ -285,8 +277,8 @@ pub trait StateApi<Hash> {
///
/// If you are having issues with maximum payload size you can use the flag
/// `-ltracing=trace` to get some logging during tracing.
#[method(name = "state_traceBlock")]
async fn trace_block(
#[method(name = "state_traceBlock", blocking)]
fn trace_block(
&self,
block: Hash,
targets: Option<String>,
Expand Down
7 changes: 3 additions & 4 deletions client/rpc/src/chain/chain_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use futures::{
future::{self, FutureExt},
stream::{self, Stream, StreamExt},
};
use jsonrpsee::{core::async_trait, PendingSubscription};
use jsonrpsee::PendingSubscription;
use sc_client_api::{BlockBackend, BlockchainEvents};
use sp_blockchain::HeaderBackend;
use sp_runtime::{
Expand All @@ -51,7 +51,6 @@ impl<Block: BlockT, Client> FullChain<Block, Client> {
}
}

#[async_trait]
impl<Block, Client> ChainBackend<Client, Block> for FullChain<Block, Client>
where
Block: BlockT + 'static,
Expand All @@ -62,11 +61,11 @@ where
&self.client
}

async fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>, Error> {
fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>, Error> {
self.client.header(BlockId::Hash(self.unwrap_or_best(hash))).map_err(client_err)
}

async fn block(&self, hash: Option<Block::Hash>) -> Result<Option<SignedBlock<Block>>, Error> {
fn block(&self, hash: Option<Block::Hash>) -> Result<Option<SignedBlock<Block>>, Error> {
self.client.block(&BlockId::Hash(self.unwrap_or_best(hash))).map_err(client_err)
}

Expand Down
19 changes: 7 additions & 12 deletions client/rpc/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ use std::sync::Arc;

use crate::SubscriptionTaskExecutor;

use jsonrpsee::{
core::{async_trait, RpcResult},
PendingSubscription,
};
use jsonrpsee::{core::RpcResult, PendingSubscription};
use sc_client_api::BlockchainEvents;
use sp_rpc::{list::ListOrValue, number::NumberOrHex};
use sp_runtime::{
Expand All @@ -45,7 +42,6 @@ pub use sc_rpc_api::chain::*;
use sp_blockchain::HeaderBackend;

/// Blockchain backend API
#[async_trait]
trait ChainBackend<Client, Block: BlockT>: Send + Sync + 'static
where
Block: BlockT + 'static,
Expand All @@ -64,10 +60,10 @@ where
}

/// Get header of a relay chain block.
async fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>, Error>;
fn header(&self, hash: Option<Block::Hash>) -> Result<Option<Block::Header>, Error>;

/// Get header and body of a relay chain block.
async fn block(&self, hash: Option<Block::Hash>) -> Result<Option<SignedBlock<Block>>, Error>;
fn block(&self, hash: Option<Block::Hash>) -> Result<Option<SignedBlock<Block>>, Error>;

/// Get hash of the n-th block in the canon chain.
///
Expand Down Expand Up @@ -126,20 +122,19 @@ pub struct Chain<Block: BlockT, Client> {
backend: Box<dyn ChainBackend<Client, Block>>,
}

#[async_trait]
impl<Block, Client> ChainApiServer<NumberFor<Block>, Block::Hash, Block::Header, SignedBlock<Block>>
for Chain<Block, Client>
where
Block: BlockT + 'static,
Block::Header: Unpin,
Client: HeaderBackend<Block> + BlockchainEvents<Block> + 'static,
{
async fn header(&self, hash: Option<Block::Hash>) -> RpcResult<Option<Block::Header>> {
self.backend.header(hash).await.map_err(Into::into)
fn header(&self, hash: Option<Block::Hash>) -> RpcResult<Option<Block::Header>> {
self.backend.header(hash).map_err(Into::into)
}

async fn block(&self, hash: Option<Block::Hash>) -> RpcResult<Option<SignedBlock<Block>>> {
self.backend.block(hash).await.map_err(Into::into)
fn block(&self, hash: Option<Block::Hash>) -> RpcResult<Option<SignedBlock<Block>>> {
self.backend.block(hash).map_err(Into::into)
}

fn block_hash(
Expand Down
Loading