// Copyright 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 .
//! Blockchain API backend for full nodes.
use std::sync::Arc;
use rpc::futures::future::result;
use sc_rpc_api::Subscriptions;
use sc_client_api::{CallExecutor, backend::Backend};
use sc_client::Client;
use sp_core::{H256, Blake2Hasher};
use sp_runtime::{
generic::{BlockId, SignedBlock},
traits::{Block as BlockT},
};
use super::{ChainBackend, client_err, error::FutureResult};
/// Blockchain API backend for full nodes. Reads all the data from local database.
pub struct FullChain {
/// Substrate client.
client: Arc>,
/// Current subscriptions.
subscriptions: Subscriptions,
}
impl FullChain {
/// Create new Chain API RPC handler.
pub fn new(client: Arc>, subscriptions: Subscriptions) -> Self {
Self {
client,
subscriptions,
}
}
}
impl ChainBackend for FullChain where
Block: BlockT + 'static,
B: Backend + Send + Sync + 'static,
E: CallExecutor + Send + Sync + 'static,
RA: Send + Sync + 'static,
{
fn client(&self) -> &Arc> {
&self.client
}
fn subscriptions(&self) -> &Subscriptions {
&self.subscriptions
}
fn header(&self, hash: Option) -> FutureResult