// This file is part of Substrate.
// Copyright (C) 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 .
//! Blockchain API backend for full nodes.
use super::{client_err, ChainBackend, Error};
use crate::{
utils::{pipe_from_stream, spawn_subscription_task},
SubscriptionTaskExecutor,
};
use std::{marker::PhantomData, sync::Arc};
use futures::{
future::{self},
stream::{self, Stream, StreamExt},
};
use jsonrpsee::{core::async_trait, PendingSubscriptionSink};
use sc_client_api::{BlockBackend, BlockchainEvents};
use sp_blockchain::HeaderBackend;
use sp_runtime::{generic::SignedBlock, traits::Block as BlockT};
/// Blockchain API backend for full nodes. Reads all the data from local database.
pub struct FullChain {
/// Substrate client.
client: Arc,
/// phantom member to pin the block type
_phantom: PhantomData,
/// Subscription executor.
executor: SubscriptionTaskExecutor,
}
impl FullChain {
/// Create new Chain API RPC handler.
pub fn new(client: Arc, executor: SubscriptionTaskExecutor) -> Self {
Self { client, executor, _phantom: PhantomData }
}
}
#[async_trait]
impl ChainBackend for FullChain
where
Block: BlockT + 'static,
Block::Header: Unpin,
Client: BlockBackend + HeaderBackend + BlockchainEvents + 'static,
{
fn client(&self) -> &Arc {
&self.client
}
fn header(&self, hash: Option) -> Result