mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
removes use of sc_client::Client from sc-rpc (#5063)
* removes use of sc_client::Client from sc-rpc * remove Client impl from sc-finality-benches * remove client impl from sc-finality-grandpa * read_proof accepts iterator * remove generic Executor param from ExecutorProvider * fix long ass line * code style changes * merge with master Co-authored-by: Arkadiy Paronyan <arkady.paronyan@gmail.com>
This commit is contained in:
committed by
GitHub
parent
dc85ccb7df
commit
99ae5342eb
@@ -32,7 +32,7 @@ use rpc::{
|
||||
|
||||
use sc_rpc_api::Subscriptions;
|
||||
use sc_client::{
|
||||
self, Client, BlockchainEvents,
|
||||
self, BlockchainEvents,
|
||||
light::{fetcher::Fetcher, blockchain::RemoteBlockchain},
|
||||
};
|
||||
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
|
||||
@@ -45,16 +45,17 @@ use sp_runtime::{
|
||||
use self::error::{Result, Error, FutureResult};
|
||||
|
||||
pub use sc_rpc_api::chain::*;
|
||||
use sp_blockchain::HeaderBackend;
|
||||
use sc_client_api::BlockBody;
|
||||
|
||||
/// Blockchain backend API
|
||||
trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
|
||||
trait ChainBackend<Client, Block: BlockT>: Send + Sync + 'static
|
||||
where
|
||||
Block: BlockT + 'static,
|
||||
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
|
||||
E: sc_client::CallExecutor<Block> + Send + Sync + 'static,
|
||||
Client: HeaderBackend<Block> + BlockchainEvents<Block> + 'static,
|
||||
{
|
||||
/// Get client reference.
|
||||
fn client(&self) -> &Arc<Client<B, E, Block, RA>>;
|
||||
fn client(&self) -> &Arc<Client>;
|
||||
|
||||
/// Get subscriptions reference.
|
||||
fn subscriptions(&self) -> &Subscriptions;
|
||||
@@ -62,7 +63,7 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
|
||||
/// Tries to unwrap passed block hash, or uses best block hash otherwise.
|
||||
fn unwrap_or_best(&self, hash: Option<Block::Hash>) -> Block::Hash {
|
||||
match hash.into() {
|
||||
None => self.client().chain_info().best_hash,
|
||||
None => self.client().info().best_hash,
|
||||
Some(hash) => hash,
|
||||
}
|
||||
}
|
||||
@@ -81,9 +82,9 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
|
||||
number: Option<NumberOrHex<NumberFor<Block>>>,
|
||||
) -> Result<Option<Block::Hash>> {
|
||||
Ok(match number {
|
||||
None => Some(self.client().chain_info().best_hash),
|
||||
None => Some(self.client().info().best_hash),
|
||||
Some(num_or_hex) => self.client()
|
||||
.header(&BlockId::number(num_or_hex.to_number()?))
|
||||
.header(BlockId::number(num_or_hex.to_number()?))
|
||||
.map_err(client_err)?
|
||||
.map(|h| h.hash()),
|
||||
})
|
||||
@@ -91,7 +92,7 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
|
||||
|
||||
/// Get hash of the last finalized block in the canon chain.
|
||||
fn finalized_head(&self) -> Result<Block::Hash> {
|
||||
Ok(self.client().chain_info().finalized_hash)
|
||||
Ok(self.client().info().finalized_hash)
|
||||
}
|
||||
|
||||
/// All new head subscription
|
||||
@@ -104,7 +105,7 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
|
||||
self.client(),
|
||||
self.subscriptions(),
|
||||
subscriber,
|
||||
|| self.client().chain_info().best_hash,
|
||||
|| self.client().info().best_hash,
|
||||
|| self.client().import_notification_stream()
|
||||
.map(|notification| Ok::<_, ()>(notification.header))
|
||||
.compat(),
|
||||
@@ -130,7 +131,7 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
|
||||
self.client(),
|
||||
self.subscriptions(),
|
||||
subscriber,
|
||||
|| self.client().chain_info().best_hash,
|
||||
|| self.client().info().best_hash,
|
||||
|| self.client().import_notification_stream()
|
||||
.filter(|notification| future::ready(notification.is_new_best))
|
||||
.map(|notification| Ok::<_, ()>(notification.header))
|
||||
@@ -157,7 +158,7 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
|
||||
self.client(),
|
||||
self.subscriptions(),
|
||||
subscriber,
|
||||
|| self.client().chain_info().finalized_hash,
|
||||
|| self.client().info().finalized_hash,
|
||||
|| self.client().finality_notification_stream()
|
||||
.map(|notification| Ok::<_, ()>(notification.header))
|
||||
.compat(),
|
||||
@@ -175,15 +176,13 @@ trait ChainBackend<B, E, Block: BlockT, RA>: Send + Sync + 'static
|
||||
}
|
||||
|
||||
/// Create new state API that works on full node.
|
||||
pub fn new_full<B, E, Block: BlockT, RA>(
|
||||
client: Arc<Client<B, E, Block, RA>>,
|
||||
pub fn new_full<Block: BlockT, Client>(
|
||||
client: Arc<Client>,
|
||||
subscriptions: Subscriptions,
|
||||
) -> Chain<B, E, Block, RA>
|
||||
) -> Chain<Block, Client>
|
||||
where
|
||||
Block: BlockT + 'static,
|
||||
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
|
||||
E: sc_client::CallExecutor<Block> + Send + Sync + 'static + Clone,
|
||||
RA: Send + Sync + 'static,
|
||||
Client: BlockBody<Block> + HeaderBackend<Block> + BlockchainEvents<Block> + 'static,
|
||||
{
|
||||
Chain {
|
||||
backend: Box::new(self::chain_full::FullChain::new(client, subscriptions)),
|
||||
@@ -191,17 +190,15 @@ pub fn new_full<B, E, Block: BlockT, RA>(
|
||||
}
|
||||
|
||||
/// Create new state API that works on light node.
|
||||
pub fn new_light<B, E, Block: BlockT, RA, F: Fetcher<Block>>(
|
||||
client: Arc<Client<B, E, Block, RA>>,
|
||||
pub fn new_light<Block: BlockT, Client, F: Fetcher<Block>>(
|
||||
client: Arc<Client>,
|
||||
subscriptions: Subscriptions,
|
||||
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
|
||||
fetcher: Arc<F>,
|
||||
) -> Chain<B, E, Block, RA>
|
||||
) -> Chain<Block, Client>
|
||||
where
|
||||
Block: BlockT + 'static,
|
||||
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
|
||||
E: sc_client::CallExecutor<Block> + Send + Sync + 'static + Clone,
|
||||
RA: Send + Sync + 'static,
|
||||
Client: BlockBody<Block> + HeaderBackend<Block> + BlockchainEvents<Block> + 'static,
|
||||
F: Send + Sync + 'static,
|
||||
{
|
||||
Chain {
|
||||
@@ -215,15 +212,15 @@ pub fn new_light<B, E, Block: BlockT, RA, F: Fetcher<Block>>(
|
||||
}
|
||||
|
||||
/// Chain API with subscriptions support.
|
||||
pub struct Chain<B, E, Block: BlockT, RA> {
|
||||
backend: Box<dyn ChainBackend<B, E, Block, RA>>,
|
||||
pub struct Chain<Block: BlockT, Client> {
|
||||
backend: Box<dyn ChainBackend<Client, Block>>,
|
||||
}
|
||||
|
||||
impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, SignedBlock<Block>> for Chain<B, E, Block, RA> where
|
||||
Block: BlockT + 'static,
|
||||
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
|
||||
E: sc_client::CallExecutor<Block> + Send + Sync + 'static,
|
||||
RA: Send + Sync + 'static
|
||||
impl<Block, Client> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, SignedBlock<Block>> for
|
||||
Chain<Block, Client>
|
||||
where
|
||||
Block: BlockT + 'static,
|
||||
Client: HeaderBackend<Block> + BlockchainEvents<Block> + 'static,
|
||||
{
|
||||
type Metadata = crate::metadata::Metadata;
|
||||
|
||||
@@ -281,16 +278,15 @@ impl<B, E, Block, RA> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, Sig
|
||||
}
|
||||
|
||||
/// Subscribe to new headers.
|
||||
fn subscribe_headers<B, E, Block, RA, F, G, S, ERR>(
|
||||
client: &Arc<Client<B, E, Block, RA>>,
|
||||
fn subscribe_headers<Block, Client, F, G, S, ERR>(
|
||||
client: &Arc<Client>,
|
||||
subscriptions: &Subscriptions,
|
||||
subscriber: Subscriber<Block::Header>,
|
||||
best_block_hash: G,
|
||||
stream: F,
|
||||
) where
|
||||
Block: BlockT + 'static,
|
||||
B: sc_client_api::backend::Backend<Block> + Send + Sync + 'static,
|
||||
E: sc_client::CallExecutor<Block> + Send + Sync + 'static,
|
||||
Client: HeaderBackend<Block> + 'static,
|
||||
F: FnOnce() -> S,
|
||||
G: FnOnce() -> Block::Hash,
|
||||
ERR: ::std::fmt::Debug,
|
||||
@@ -298,7 +294,7 @@ fn subscribe_headers<B, E, Block, RA, F, G, S, ERR>(
|
||||
{
|
||||
subscriptions.add(subscriber, |sink| {
|
||||
// send current head right at the start.
|
||||
let header = client.header(&BlockId::Hash(best_block_hash()))
|
||||
let header = client.header(BlockId::Hash(best_block_hash()))
|
||||
.map_err(client_err)
|
||||
.and_then(|header| {
|
||||
header.ok_or_else(|| "Best header missing.".to_owned().into())
|
||||
|
||||
Reference in New Issue
Block a user