// Copyright 2017-2019 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 .
//! Substrate blockchain API.
mod chain_full;
mod chain_light;
#[cfg(test)]
mod tests;
use std::sync::Arc;
use futures::{future, StreamExt, TryStreamExt};
use log::warn;
use rpc::{
Result as RpcResult,
futures::{stream, Future, Sink, Stream},
};
use api::Subscriptions;
use client::{
self, Client, BlockchainEvents,
light::{fetcher::Fetcher, blockchain::RemoteBlockchain},
};
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
use primitives::{H256, Blake2Hasher};
use rpc_primitives::{number::NumberOrHex, list::ListOrValue};
use sr_primitives::{
generic::{BlockId, SignedBlock},
traits::{Block as BlockT, Header, NumberFor},
};
use self::error::{Result, Error, FutureResult};
pub use api::chain::*;
/// Blockchain backend API
trait ChainBackend: Send + Sync + 'static
where
Block: BlockT + 'static,
B: client_api::backend::Backend + Send + Sync + 'static,
E: client::CallExecutor + Send + Sync + 'static,
{
/// Get client reference.
fn client(&self) -> &Arc>;
/// Get subscriptions reference.
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 {
match hash.into() {
None => self.client().info().chain.best_hash,
Some(hash) => hash,
}
}
/// Get header of a relay chain block.
fn header(&self, hash: Option) -> FutureResult