Revert "Use Subscription Manager from jsonrpc-pubsub (#6208)" (#6252)

This reverts commit ea1eb4e57f.
This commit is contained in:
André Silva
2020-06-04 15:39:57 +01:00
committed by GitHub
parent 3fef099893
commit 8f5a52fe1a
31 changed files with 285 additions and 196 deletions
+4 -4
View File
@@ -18,8 +18,8 @@
use std::sync::Arc;
use rpc::futures::future::result;
use jsonrpc_pubsub::manager::SubscriptionManager;
use sc_rpc_api::Subscriptions;
use sc_client_api::{BlockchainEvents, BlockBackend};
use sp_runtime::{generic::{BlockId, SignedBlock}, traits::{Block as BlockT}};
@@ -32,14 +32,14 @@ pub struct FullChain<Block: BlockT, Client> {
/// Substrate client.
client: Arc<Client>,
/// Current subscriptions.
subscriptions: SubscriptionManager,
subscriptions: Subscriptions,
/// phantom member to pin the block type
_phantom: PhantomData<Block>,
}
impl<Block: BlockT, Client> FullChain<Block, Client> {
/// Create new Chain API RPC handler.
pub fn new(client: Arc<Client>, subscriptions: SubscriptionManager) -> Self {
pub fn new(client: Arc<Client>, subscriptions: Subscriptions) -> Self {
Self {
client,
subscriptions,
@@ -56,7 +56,7 @@ impl<Block, Client> ChainBackend<Client, Block> for FullChain<Block, Client> whe
&self.client
}
fn subscriptions(&self) -> &SubscriptionManager {
fn subscriptions(&self) -> &Subscriptions {
&self.subscriptions
}
@@ -19,8 +19,8 @@
use std::sync::Arc;
use futures::{future::ready, FutureExt, TryFutureExt};
use rpc::futures::future::{result, Future, Either};
use jsonrpc_pubsub::manager::SubscriptionManager;
use sc_rpc_api::Subscriptions;
use sc_client_api::light::{Fetcher, RemoteBodyRequest, RemoteBlockchain};
use sp_runtime::{
generic::{BlockId, SignedBlock},
@@ -37,7 +37,7 @@ pub struct LightChain<Block: BlockT, Client, F> {
/// Substrate client.
client: Arc<Client>,
/// Current subscriptions.
subscriptions: SubscriptionManager,
subscriptions: Subscriptions,
/// Remote blockchain reference
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
/// Remote fetcher reference.
@@ -48,7 +48,7 @@ impl<Block: BlockT, Client, F: Fetcher<Block>> LightChain<Block, Client, F> {
/// Create new Chain API RPC handler.
pub fn new(
client: Arc<Client>,
subscriptions: SubscriptionManager,
subscriptions: Subscriptions,
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
fetcher: Arc<F>,
) -> Self {
@@ -70,7 +70,7 @@ impl<Block, Client, F> ChainBackend<Client, Block> for LightChain<Block, Client,
&self.client
}
fn subscriptions(&self) -> &SubscriptionManager {
fn subscriptions(&self) -> &Subscriptions {
&self.subscriptions
}
+6 -5
View File
@@ -32,8 +32,9 @@ use rpc::{
futures::{stream, Future, Sink, Stream},
};
use sc_rpc_api::Subscriptions;
use sc_client_api::{BlockchainEvents, light::{Fetcher, RemoteBlockchain}};
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId, manager::SubscriptionManager};
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
use sp_rpc::{number::NumberOrHex, list::ListOrValue};
use sp_runtime::{
generic::{BlockId, SignedBlock},
@@ -56,7 +57,7 @@ trait ChainBackend<Client, Block: BlockT>: Send + Sync + 'static
fn client(&self) -> &Arc<Client>;
/// Get subscriptions reference.
fn subscriptions(&self) -> &SubscriptionManager;
fn subscriptions(&self) -> &Subscriptions;
/// Tries to unwrap passed block hash, or uses best block hash otherwise.
fn unwrap_or_best(&self, hash: Option<Block::Hash>) -> Block::Hash {
@@ -176,7 +177,7 @@ trait ChainBackend<Client, Block: BlockT>: Send + Sync + 'static
/// Create new state API that works on full node.
pub fn new_full<Block: BlockT, Client>(
client: Arc<Client>,
subscriptions: SubscriptionManager,
subscriptions: Subscriptions,
) -> Chain<Block, Client>
where
Block: BlockT + 'static,
@@ -190,7 +191,7 @@ pub fn new_full<Block: BlockT, Client>(
/// Create new state API that works on light node.
pub fn new_light<Block: BlockT, Client, F: Fetcher<Block>>(
client: Arc<Client>,
subscriptions: SubscriptionManager,
subscriptions: Subscriptions,
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
fetcher: Arc<F>,
) -> Chain<Block, Client>
@@ -278,7 +279,7 @@ impl<Block, Client> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, Signe
/// Subscribe to new headers.
fn subscribe_headers<Block, Client, F, G, S, ERR>(
client: &Arc<Client>,
subscriptions: &SubscriptionManager,
subscriptions: &Subscriptions,
subscriber: Subscriber<Block::Header>,
best_block_hash: G,
stream: F,
+10 -19
View File
@@ -31,7 +31,7 @@ use crate::testing::TaskExecutor;
#[test]
fn should_return_header() {
let client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
assert_matches!(
api.header(Some(client.genesis_hash()).into()).wait(),
@@ -63,7 +63,7 @@ fn should_return_header() {
#[test]
fn should_return_a_block() {
let mut client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
let block_hash = block.hash();
@@ -114,7 +114,7 @@ fn should_return_a_block() {
#[test]
fn should_return_block_hash() {
let mut client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
assert_matches!(
api.block_hash(None.into()),
@@ -158,7 +158,7 @@ fn should_return_block_hash() {
#[test]
fn should_return_finalized_hash() {
let mut client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
assert_matches!(
api.finalized_head(),
@@ -188,15 +188,12 @@ fn should_notify_about_latest_block() {
{
let mut client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
api.subscribe_all_heads(Default::default(), subscriber);
// assert id assigned
assert!(matches!(
executor::block_on(id.compat()),
Ok(Ok(SubscriptionId::String(_)))
));
assert_eq!(executor::block_on(id.compat()), Ok(Ok(SubscriptionId::Number(1))));
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
client.import(BlockOrigin::Own, block).unwrap();
@@ -218,15 +215,12 @@ fn should_notify_about_best_block() {
{
let mut client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
api.subscribe_new_heads(Default::default(), subscriber);
// assert id assigned
assert!(matches!(
executor::block_on(id.compat()),
Ok(Ok(SubscriptionId::String(_)))
));
assert_eq!(executor::block_on(id.compat()), Ok(Ok(SubscriptionId::Number(1))));
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
client.import(BlockOrigin::Own, block).unwrap();
@@ -248,15 +242,12 @@ fn should_notify_about_finalized_block() {
{
let mut client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
api.subscribe_finalized_heads(Default::default(), subscriber);
// assert id assigned
assert!(matches!(
executor::block_on(id.compat()),
Ok(Ok(SubscriptionId::String(_)))
));
assert_eq!(executor::block_on(id.compat()), Ok(Ok(SubscriptionId::Number(1))));
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
client.import(BlockOrigin::Own, block).unwrap();