mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 05:11:02 +00:00
dry-run mode for init bridge command (#1690)
* `dry-run` mode for init bridge command * fix clippy
This commit is contained in:
committed by
Bastian Köcher
parent
02ef3a1a25
commit
9cea69349f
@@ -90,7 +90,7 @@ pub trait MessageDispatch<AccountId> {
|
||||
type DispatchPayload: Decode;
|
||||
|
||||
/// Fine-grained result of single message dispatch (for better diagnostic purposes)
|
||||
type DispatchLevelResult: Clone + Decode + sp_std::fmt::Debug + Eq;
|
||||
type DispatchLevelResult: Clone + sp_std::fmt::Debug + Eq;
|
||||
|
||||
/// Estimate dispatch weight.
|
||||
///
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use codec::Encode;
|
||||
|
||||
use crate::{
|
||||
chains::{
|
||||
@@ -46,6 +47,9 @@ pub struct InitBridge {
|
||||
target: TargetConnectionParams,
|
||||
#[structopt(flatten)]
|
||||
target_sign: TargetSigningParams,
|
||||
/// Generates all required data, but does not submit extrinsic
|
||||
#[structopt(long)]
|
||||
dry_run: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, EnumString, EnumVariantNames)]
|
||||
@@ -77,6 +81,7 @@ where
|
||||
let source_client = data.source.into_client::<Self::Source>().await?;
|
||||
let target_client = data.target.into_client::<Self::Target>().await?;
|
||||
let target_sign = data.target_sign.to_keypair::<Self::Target>()?;
|
||||
let dry_run = data.dry_run;
|
||||
|
||||
let (spec_version, transaction_version) = target_client.simple_runtime_version().await?;
|
||||
substrate_relay_helper::finality::initialize::initialize::<Self::Engine, _, _, _>(
|
||||
@@ -90,11 +95,15 @@ where
|
||||
signer: target_sign,
|
||||
},
|
||||
move |transaction_nonce, initialization_data| {
|
||||
Ok(UnsignedTransaction::new(
|
||||
Self::encode_init_bridge(initialization_data).into(),
|
||||
transaction_nonce,
|
||||
))
|
||||
let call = Self::encode_init_bridge(initialization_data);
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
"Initialize bridge call encoded as hex string: {:?}",
|
||||
format!("0x{}", hex::encode(call.encode()))
|
||||
);
|
||||
Ok(UnsignedTransaction::new(call.into(), transaction_nonce))
|
||||
},
|
||||
dry_run,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ pub async fn initialize<
|
||||
target_transactions_signer: TargetChain::AccountId,
|
||||
target_signing_data: SignParam<TargetChain>,
|
||||
prepare_initialize_transaction: F,
|
||||
dry_run: bool,
|
||||
) where
|
||||
F: FnOnce(
|
||||
TargetChain::Index,
|
||||
@@ -54,6 +55,7 @@ pub async fn initialize<
|
||||
target_transactions_signer,
|
||||
target_signing_data,
|
||||
prepare_initialize_transaction,
|
||||
dry_run,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -88,6 +90,7 @@ async fn do_initialize<
|
||||
target_transactions_signer: TargetChain::AccountId,
|
||||
target_signing_data: SignParam<TargetChain>,
|
||||
prepare_initialize_transaction: F,
|
||||
dry_run: bool,
|
||||
) -> Result<
|
||||
Option<TargetChain::Hash>,
|
||||
Error<SourceChain::Hash, <SourceChain::Header as HeaderT>::Number>,
|
||||
@@ -110,7 +113,9 @@ where
|
||||
SourceChain::NAME,
|
||||
TargetChain::NAME,
|
||||
);
|
||||
return Ok(None)
|
||||
if !dry_run {
|
||||
return Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
let initialization_data = E::prepare_initialization_data(source_client).await?;
|
||||
@@ -127,7 +132,14 @@ where
|
||||
target_transactions_signer,
|
||||
target_signing_data,
|
||||
move |_, transaction_nonce| {
|
||||
prepare_initialize_transaction(transaction_nonce, initialization_data)
|
||||
let tx = prepare_initialize_transaction(transaction_nonce, initialization_data);
|
||||
if dry_run {
|
||||
Err(SubstrateError::Custom(
|
||||
"Not submitting extrinsic in `dry-run` mode!".to_string(),
|
||||
))
|
||||
} else {
|
||||
tx
|
||||
}
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user