// Copyright 2019-2021 Parity Technologies (UK) Ltd.
// This file is part of Parity Bridges Common.
// Parity Bridges Common 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.
// Parity Bridges Common 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 Parity Bridges Common. If not, see .
//! Parachain heads source.
use crate::parachains::{ParachainsPipelineAdapter, SubstrateParachainsPipeline};
use async_std::sync::{Arc, Mutex};
use async_trait::async_trait;
use bp_parachains::parachain_head_storage_key_at_source;
use bp_polkadot_core::parachains::{ParaHash, ParaHead, ParaHeadsProof, ParaId};
use codec::Decode;
use parachains_relay::parachains_loop::{ParaHashAtSource, SourceClient};
use relay_substrate_client::{
Chain, Client, Error as SubstrateError, HeaderIdOf, HeaderOf, RelayChain,
};
use relay_utils::relay_loop::Client as RelayClient;
use sp_runtime::traits::Header as HeaderT;
/// Shared updatable reference to the maximal parachain header id that we want to sync from the
/// source.
pub type RequiredHeaderIdRef = Arc>>>;
/// Substrate client as parachain heads source.
#[derive(Clone)]
pub struct ParachainsSource {
client: Client,
maximal_header_id: Option>,
}
impl ParachainsSource
{
/// Creates new parachains source client.
pub fn new(
client: Client,
maximal_header_id: Option>,
) -> Self {
ParachainsSource { client, maximal_header_id }
}
/// Returns reference to the underlying RPC client.
pub fn client(&self) -> &Client {
&self.client
}
/// Return decoded head of given parachain.
pub async fn on_chain_parachain_header(
&self,
at_block: HeaderIdOf,
para_id: ParaId,
) -> Result