substrate_relay_helper/
lib.rs1#![warn(missing_docs)]
20
21use relay_substrate_client::{Chain, ChainWithUtilityPallet, UtilityPallet};
22
23use std::marker::PhantomData;
24
25pub use finality_relay::HeadersToRelay;
27
28pub mod cli;
29pub mod equivocation;
30pub mod error;
31pub mod finality;
32pub mod finality_base;
33pub mod messages;
34pub mod on_demand;
35pub mod parachains;
36
37#[derive(Clone, Debug)]
39pub struct TransactionParams<TS> {
40 pub signer: TS,
42 pub mortality: Option<u32>,
44}
45
46#[derive(Clone, Debug)]
48pub enum TaggedAccount<AccountId> {
49 Messages {
52 id: AccountId,
54 bridged_chain: String,
56 },
57}
58
59impl<AccountId> TaggedAccount<AccountId> {
60 pub fn id(&self) -> &AccountId {
62 match *self {
63 TaggedAccount::Messages { ref id, .. } => id,
64 }
65 }
66
67 pub fn tag(&self) -> String {
69 match *self {
70 TaggedAccount::Messages { ref bridged_chain, .. } => {
71 format!("{bridged_chain}Messages")
72 },
73 }
74 }
75}
76
77pub trait BatchCallBuilder<Call>: Clone + Send + Sync {
79 fn build_batch_call(&self, _calls: Vec<Call>) -> Call;
81}
82
83pub trait BatchCallBuilderConstructor<Call>: Clone {
85 type CallBuilder: BatchCallBuilder<Call>;
87 fn new_builder() -> Option<Self::CallBuilder>;
89}
90
91#[derive(Clone)]
93pub struct UtilityPalletBatchCallBuilder<C: Chain>(PhantomData<C>);
94
95impl<C: Chain> BatchCallBuilder<C::Call> for UtilityPalletBatchCallBuilder<C>
96where
97 C: ChainWithUtilityPallet,
98{
99 fn build_batch_call(&self, calls: Vec<C::Call>) -> C::Call {
100 C::UtilityPallet::build_batch_call(calls)
101 }
102}
103
104impl<C: Chain> BatchCallBuilderConstructor<C::Call> for UtilityPalletBatchCallBuilder<C>
105where
106 C: ChainWithUtilityPallet,
107{
108 type CallBuilder = Self;
109
110 fn new_builder() -> Option<Self::CallBuilder> {
111 Some(Self(Default::default()))
112 }
113}
114
115impl<Call> BatchCallBuilderConstructor<Call> for () {
117 type CallBuilder = ();
118 fn new_builder() -> Option<Self::CallBuilder> {
119 None
120 }
121}
122
123impl<Call> BatchCallBuilder<Call> for () {
126 fn build_batch_call(&self, _calls: Vec<Call>) -> Call {
127 unreachable!("never called, because ()::new_builder() returns None; qed")
128 }
129}
130
131pub mod proofs {
133 use bp_runtime::{HashOf, RawStorageProof};
134 use relay_substrate_client::Chain;
135 use sp_trie::StorageProof;
136
137 pub fn to_raw_storage_proof<SourceChain: Chain>(
139 proof: (StorageProof, HashOf<SourceChain>),
140 ) -> RawStorageProof {
141 proof.0.into_iter_nodes().collect()
142 }
143}