soil_client/client_api/
mod.rs1#![warn(missing_docs)]
9
10pub mod backend;
11pub mod call_executor;
12pub mod client;
13pub mod execution_extensions;
14pub mod in_mem;
15pub mod leaves;
16pub mod notifications;
17pub mod proof_provider;
18
19pub use crate::blockchain;
20pub use crate::blockchain::HeaderBackend;
21pub use backend::*;
22pub use call_executor::*;
23pub use client::*;
24pub use notifications::*;
25pub use proof_provider::*;
26
27pub use subsoil::state_machine::{CompactProof, StorageProof};
28pub use subsoil::storage::{ChildInfo, PrefixedStorageKey, StorageData, StorageKey};
29
30pub trait UsageProvider<Block: subsoil::runtime::traits::Block> {
32 fn usage_info(&self) -> ClientInfo<Block>;
34}
35
36pub mod utils {
38 use crate::blockchain::{Error, HeaderBackend, HeaderMetadata};
39 use subsoil::runtime::traits::Block as BlockT;
40
41 pub fn is_descendent_of<Block: BlockT, T>(
48 client: &T,
49 current: Option<(Block::Hash, Block::Hash)>,
50 ) -> impl Fn(&Block::Hash, &Block::Hash) -> Result<bool, Error> + '_
51 where
52 T: HeaderBackend<Block> + HeaderMetadata<Block, Error = Error>,
53 {
54 move |base, hash| {
55 if base == hash {
56 return Ok(false);
57 }
58
59 let mut hash = hash;
60 if let Some((current_hash, current_parent_hash)) = ¤t {
61 if base == current_hash {
62 return Ok(false);
63 }
64 if hash == current_hash {
65 if base == current_parent_hash {
66 return Ok(true);
67 } else {
68 hash = current_parent_hash;
69 }
70 }
71 }
72
73 let ancestor = crate::blockchain::lowest_common_ancestor(client, *hash, *base)?;
74
75 Ok(ancestor.hash == *base)
76 }
77 }
78}