// This file is part of Substrate.
// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program 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.
// This program 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 this program. If not, see .
//! Substrate blockchain API.
mod chain_full;
#[cfg(test)]
mod tests;
use futures::{future, StreamExt, TryStreamExt};
use log::warn;
use rpc::{
futures::{stream, FutureExt, SinkExt, Stream},
Result as RpcResult,
};
use std::sync::Arc;
use jsonrpc_pubsub::{manager::SubscriptionManager, typed::Subscriber, SubscriptionId};
use sc_client_api::BlockchainEvents;
use sp_rpc::{list::ListOrValue, number::NumberOrHex};
use sp_runtime::{
generic::{BlockId, SignedBlock},
traits::{Block as BlockT, Header, NumberFor},
};
use self::error::{Error, FutureResult, Result};
use sc_client_api::BlockBackend;
pub use sc_rpc_api::chain::*;
use sp_blockchain::HeaderBackend;
/// Blockchain backend API
trait ChainBackend: Send + Sync + 'static
where
Block: BlockT + 'static,
Block::Header: Unpin,
Client: HeaderBackend + BlockchainEvents + 'static,
{
/// Get client reference.
fn client(&self) -> &Arc;
/// Get subscriptions reference.
fn subscriptions(&self) -> &SubscriptionManager;
/// Tries to unwrap passed block hash, or uses best block hash otherwise.
fn unwrap_or_best(&self, hash: Option) -> Block::Hash {
match hash {
None => self.client().info().best_hash,
Some(hash) => hash,
}
}
/// Get header of a relay chain block.
fn header(&self, hash: Option) -> FutureResult