mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 11:01:01 +00:00
e47f1e42e0
* Simplify submit_and_watch_signed_extrinsic The way submit_and_watch_signed_extrinsic is used now, we can always derive the SignParam from other params. If in the future we need more customization possibilities, we can define a new method. * Simplify submit_signed_extrinsic * Send maybe_batch_tx as a parameter Send `maybe_batch_tx` as a parameter to `submit_proof()`. This way we can deduplicate the logic that submits the extrinsic for `messages_source and `messages_target` and we can simplify the logic in the race loop a bit. * Define BatchProofTransaction Deduplicate BatchConfirmationTransaction and BatchDeliveryTransaction by replacing both of them with BatchProofTransaction * Define ChainWithUtilityPallet and BatchCallBuilderConstructor - Define `ChainWithUtilityPallet` in order to be able to associate the batching functionality with chains - Defining `BatchCallBuilderConstructor` in order to have a more reliable way of checking whether an end of a messages pipeline supports batching or no. `BatchCallBuilderConstructor::new_builder()` returns an `Option<BatchCallBuilder>`.This is a bit safer because each time a caller tries to start creating a batch call, it will call `new_builder()` and will be required to handle the returned `Option`. Before we only had a bool `BATCH_CALL_SUPPORTED` the caller could have forgetten to check.
132 lines
3.9 KiB
Rust
132 lines
3.9 KiB
Rust
// 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 <http://www.gnu.org/licenses/>.
|
|
|
|
//! The library of substrate relay. contains some public codes to provide to substrate relay.
|
|
|
|
#![warn(missing_docs)]
|
|
|
|
use relay_substrate_client::{Chain, ChainWithUtilityPallet, UtilityPallet};
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
pub mod error;
|
|
pub mod finality;
|
|
pub mod messages_lane;
|
|
pub mod messages_metrics;
|
|
pub mod messages_source;
|
|
pub mod messages_target;
|
|
pub mod on_demand;
|
|
pub mod parachains;
|
|
|
|
/// Transaction creation parameters.
|
|
#[derive(Clone, Debug)]
|
|
pub struct TransactionParams<TS> {
|
|
/// Transactions author.
|
|
pub signer: TS,
|
|
/// Transactions mortality.
|
|
pub mortality: Option<u32>,
|
|
}
|
|
|
|
/// Tagged relay account, which balance may be exposed as metrics by the relay.
|
|
#[derive(Clone, Debug)]
|
|
pub enum TaggedAccount<AccountId> {
|
|
/// Account, used to sign headers relay transactions from given bridged chain.
|
|
Headers {
|
|
/// Account id.
|
|
id: AccountId,
|
|
/// Name of the bridged chain, which headers are relayed.
|
|
bridged_chain: String,
|
|
},
|
|
/// Account, used to sign parachains relay transactions from given bridged relay chain.
|
|
Parachains {
|
|
/// Account id.
|
|
id: AccountId,
|
|
/// Name of the bridged relay chain with parachain heads.
|
|
bridged_chain: String,
|
|
},
|
|
/// Account, used to sign message relay transactions from given bridged chain.
|
|
Messages {
|
|
/// Account id.
|
|
id: AccountId,
|
|
/// Name of the bridged chain, which sends us messages or delivery confirmations.
|
|
bridged_chain: String,
|
|
},
|
|
}
|
|
|
|
impl<AccountId> TaggedAccount<AccountId> {
|
|
/// Returns reference to the account id.
|
|
pub fn id(&self) -> &AccountId {
|
|
match *self {
|
|
TaggedAccount::Headers { ref id, .. } => id,
|
|
TaggedAccount::Parachains { ref id, .. } => id,
|
|
TaggedAccount::Messages { ref id, .. } => id,
|
|
}
|
|
}
|
|
|
|
/// Returns stringified account tag.
|
|
pub fn tag(&self) -> String {
|
|
match *self {
|
|
TaggedAccount::Headers { ref bridged_chain, .. } => format!("{bridged_chain}Headers"),
|
|
TaggedAccount::Parachains { ref bridged_chain, .. } => {
|
|
format!("{bridged_chain}Parachains")
|
|
},
|
|
TaggedAccount::Messages { ref bridged_chain, .. } => {
|
|
format!("{bridged_chain}Messages")
|
|
},
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Batch call builder.
|
|
pub trait BatchCallBuilder<Call>: Send {
|
|
/// Create batch call from given calls vector.
|
|
fn build_batch_call(&self, _calls: Vec<Call>) -> Call;
|
|
}
|
|
|
|
/// Batch call builder constructor.
|
|
pub trait BatchCallBuilderConstructor<Call> {
|
|
/// Create a new instance of a batch call builder.
|
|
fn new_builder() -> Option<Box<dyn BatchCallBuilder<Call>>>;
|
|
}
|
|
|
|
/// Batch call builder based on `pallet-utility`.
|
|
pub struct UtilityPalletBatchCallBuilder<C: Chain>(PhantomData<C>);
|
|
|
|
impl<C: Chain> BatchCallBuilder<C::Call> for UtilityPalletBatchCallBuilder<C>
|
|
where
|
|
C: ChainWithUtilityPallet,
|
|
{
|
|
fn build_batch_call(&self, calls: Vec<C::Call>) -> C::Call {
|
|
C::UtilityPallet::build_batch_call(calls)
|
|
}
|
|
}
|
|
|
|
impl<C: Chain> BatchCallBuilderConstructor<C::Call> for UtilityPalletBatchCallBuilder<C>
|
|
where
|
|
C: ChainWithUtilityPallet,
|
|
{
|
|
fn new_builder() -> Option<Box<dyn BatchCallBuilder<C::Call>>> {
|
|
Some(Box::new(Self(Default::default())))
|
|
}
|
|
}
|
|
|
|
/// A `BatchCallBuilderConstructor` that always returns `None`.
|
|
impl<Call> BatchCallBuilderConstructor<Call> for () {
|
|
fn new_builder() -> Option<Box<dyn BatchCallBuilder<Call>>> {
|
|
None
|
|
}
|
|
}
|