mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-18 11:45:42 +00:00
9bd23e7f01
* Bump jsonrpc pubsub, core, http, and ws Right now these are the packages which _need_ to be updated so I can just the latest `jsonrpc-pubsub` code. Once a release it cut upstream the rest of the dependencies should be updated as well. * Use jsonrpc-pubsub's SubscriptionManager This places sc-rpc-api::Subscriptions * Bump jsonrpc-core outside of sc-rpc-* * Update client/rpc tests Right now one of the `author` tests is failing, I need to think a bit about how best to fix it. * Remove Subscriptions manager There's no need for this implementation since we're using the one from `jsonrpc-pubsub` now * Fix author RPC test This test used to check for a numerial subscription ID, whereas now it uses a string based ID which is the default provided by `jsonrpc-pubsub`'s subscription manager. * Remove unused NumericIdProvider * Add missing bracket Removed one too many with that last one, lol * Bump `jsonrpc` to v14.2 There's an exception though. `jsonrpc-derive` cannot be bumped past v14.0.5 just yet since it has a dependency on `quote` pinned to v1.0.1. This means that at the moment it won't build on Substrate since it's using v1.0.3. * Track `jsonrpc-derive` master branch * Bump `quote` version to v1.0.6 * Bump `jsonrpc-derive` to v14.2.1 This includes support for `quote` v1.0.6 * Use exact version for jsonrpc crates Doing this to make sure any updates in jsonrpc don't accidently trickle down to Polkadot. Co-authored-by: André Silva <andre.beat@gmail.com>
79 lines
2.4 KiB
Rust
79 lines
2.4 KiB
Rust
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
|
// This file is part of Substrate.
|
|
|
|
// Substrate is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Substrate is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//! Blockchain API backend for full nodes.
|
|
|
|
use std::sync::Arc;
|
|
use rpc::futures::future::result;
|
|
use jsonrpc_pubsub::manager::SubscriptionManager;
|
|
|
|
use sc_client_api::{BlockchainEvents, BlockBackend};
|
|
use sp_runtime::{generic::{BlockId, SignedBlock}, traits::{Block as BlockT}};
|
|
|
|
use super::{ChainBackend, client_err, error::FutureResult};
|
|
use std::marker::PhantomData;
|
|
use sp_blockchain::HeaderBackend;
|
|
|
|
/// Blockchain API backend for full nodes. Reads all the data from local database.
|
|
pub struct FullChain<Block: BlockT, Client> {
|
|
/// Substrate client.
|
|
client: Arc<Client>,
|
|
/// Current subscriptions.
|
|
subscriptions: SubscriptionManager,
|
|
/// 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 {
|
|
Self {
|
|
client,
|
|
subscriptions,
|
|
_phantom: PhantomData,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<Block, Client> ChainBackend<Client, Block> for FullChain<Block, Client> where
|
|
Block: BlockT + 'static,
|
|
Client: BlockBackend<Block> + HeaderBackend<Block> + BlockchainEvents<Block> + 'static,
|
|
{
|
|
fn client(&self) -> &Arc<Client> {
|
|
&self.client
|
|
}
|
|
|
|
fn subscriptions(&self) -> &SubscriptionManager {
|
|
&self.subscriptions
|
|
}
|
|
|
|
fn header(&self, hash: Option<Block::Hash>) -> FutureResult<Option<Block::Header>> {
|
|
Box::new(result(self.client
|
|
.header(BlockId::Hash(self.unwrap_or_best(hash)))
|
|
.map_err(client_err)
|
|
))
|
|
}
|
|
|
|
fn block(&self, hash: Option<Block::Hash>)
|
|
-> FutureResult<Option<SignedBlock<Block>>>
|
|
{
|
|
Box::new(result(self.client
|
|
.block(&BlockId::Hash(self.unwrap_or_best(hash)))
|
|
.map_err(client_err)
|
|
))
|
|
}
|
|
}
|