mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 21:58:06 +00:00
60e5011c72
* Adding first rough ouline of the repository structure * Remove old CI stuff * add title * formatting fixes * move node-exits job's script to scripts dir * Move docs into subdir * move to bin * move maintainence scripts, configs and helpers into its own dir * add .local to ignore * move core->client * start up 'test' area * move test client * move test runtime * make test move compile * Add dependencies rule enforcement. * Fix indexing. * Update docs to reflect latest changes * Moving /srml->/paint * update docs * move client/sr-* -> primitives/ * clean old readme * remove old broken code in rhd * update lock * Step 1. * starting to untangle client * Fix after merge. * start splitting out client interfaces * move children and blockchain interfaces * Move trie and state-machine to primitives. * Fix WASM builds. * fixing broken imports * more interface moves * move backend and light to interfaces * move CallExecutor * move cli off client * moving around more interfaces * re-add consensus crates into the mix * fix subkey path * relieve client from executor * starting to pull out client from grandpa * move is_decendent_of out of client * grandpa still depends on client directly * lemme tests pass * rename srml->paint * Make it compile. * rename interfaces->client-api * Move keyring to primitives. * fixup libp2p dep * fix broken use * allow dependency enforcement to fail * move fork-tree * Moving wasm-builder * make env * move build-script-utils * fixup broken crate depdencies and names * fix imports for authority discovery * fix typo * update cargo.lock * fixing imports * Fix paths and add missing crates * re-add missing crates
85 lines
2.6 KiB
Rust
85 lines
2.6 KiB
Rust
// 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 <http://www.gnu.org/licenses/>.
|
|
|
|
//! Substrate client interfaces.
|
|
|
|
// TODO: make internal
|
|
pub mod error;
|
|
pub mod backend;
|
|
pub mod blockchain;
|
|
pub mod light;
|
|
pub mod notifications;
|
|
pub mod call_executor;
|
|
pub mod client;
|
|
pub mod offchain;
|
|
|
|
pub use error::*;
|
|
pub use backend::*;
|
|
pub use blockchain::*;
|
|
pub use light::*;
|
|
pub use notifications::*;
|
|
pub use call_executor::*;
|
|
pub use offchain::*;
|
|
pub use client::*;
|
|
|
|
pub use state_machine::{StorageProof, ExecutionStrategy};
|
|
|
|
|
|
/// Utility methods for the client.
|
|
pub mod utils {
|
|
use super::HeaderBackend;
|
|
use header_metadata::HeaderMetadata;
|
|
use crate::error;
|
|
use primitives::H256;
|
|
use sr_primitives::traits::{Block as BlockT};
|
|
use std::borrow::Borrow;
|
|
|
|
/// Returns a function for checking block ancestry, the returned function will
|
|
/// return `true` if the given hash (second parameter) is a descendent of the
|
|
/// base (first parameter). If the `current` parameter is defined, it should
|
|
/// represent the current block `hash` and its `parent hash`, if given the
|
|
/// function that's returned will assume that `hash` isn't part of the local DB
|
|
/// yet, and all searches in the DB will instead reference the parent.
|
|
pub fn is_descendent_of<'a, Block: BlockT<Hash=H256>, T, H: Borrow<H256> + 'a>(
|
|
client: &'a T,
|
|
current: Option<(H, H)>,
|
|
) -> impl Fn(&H256, &H256) -> Result<bool, error::Error> + 'a
|
|
where T: HeaderBackend<Block> + HeaderMetadata<Block, Error=error::Error>,
|
|
{
|
|
move |base, hash| {
|
|
if base == hash { return Ok(false); }
|
|
|
|
let current = current.as_ref().map(|(c, p)| (c.borrow(), p.borrow()));
|
|
|
|
let mut hash = hash;
|
|
if let Some((current_hash, current_parent_hash)) = current {
|
|
if base == current_hash { return Ok(false); }
|
|
if hash == current_hash {
|
|
if base == current_parent_hash {
|
|
return Ok(true);
|
|
} else {
|
|
hash = current_parent_hash;
|
|
}
|
|
}
|
|
}
|
|
|
|
let ancestor = header_metadata::lowest_common_ancestor(client, *hash, *base)?;
|
|
|
|
Ok(ancestor.hash == *base)
|
|
}
|
|
}
|
|
}
|