mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 06:21: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;
|
type DispatchPayload: Decode;
|
||||||
|
|
||||||
/// Fine-grained result of single message dispatch (for better diagnostic purposes)
|
/// 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.
|
/// Estimate dispatch weight.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use codec::Encode;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
chains::{
|
chains::{
|
||||||
@@ -46,6 +47,9 @@ pub struct InitBridge {
|
|||||||
target: TargetConnectionParams,
|
target: TargetConnectionParams,
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
target_sign: TargetSigningParams,
|
target_sign: TargetSigningParams,
|
||||||
|
/// Generates all required data, but does not submit extrinsic
|
||||||
|
#[structopt(long)]
|
||||||
|
dry_run: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, EnumString, EnumVariantNames)]
|
#[derive(Debug, EnumString, EnumVariantNames)]
|
||||||
@@ -77,6 +81,7 @@ where
|
|||||||
let source_client = data.source.into_client::<Self::Source>().await?;
|
let source_client = data.source.into_client::<Self::Source>().await?;
|
||||||
let target_client = data.target.into_client::<Self::Target>().await?;
|
let target_client = data.target.into_client::<Self::Target>().await?;
|
||||||
let target_sign = data.target_sign.to_keypair::<Self::Target>()?;
|
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?;
|
let (spec_version, transaction_version) = target_client.simple_runtime_version().await?;
|
||||||
substrate_relay_helper::finality::initialize::initialize::<Self::Engine, _, _, _>(
|
substrate_relay_helper::finality::initialize::initialize::<Self::Engine, _, _, _>(
|
||||||
@@ -90,11 +95,15 @@ where
|
|||||||
signer: target_sign,
|
signer: target_sign,
|
||||||
},
|
},
|
||||||
move |transaction_nonce, initialization_data| {
|
move |transaction_nonce, initialization_data| {
|
||||||
Ok(UnsignedTransaction::new(
|
let call = Self::encode_init_bridge(initialization_data);
|
||||||
Self::encode_init_bridge(initialization_data).into(),
|
log::info!(
|
||||||
transaction_nonce,
|
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;
|
.await;
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ pub async fn initialize<
|
|||||||
target_transactions_signer: TargetChain::AccountId,
|
target_transactions_signer: TargetChain::AccountId,
|
||||||
target_signing_data: SignParam<TargetChain>,
|
target_signing_data: SignParam<TargetChain>,
|
||||||
prepare_initialize_transaction: F,
|
prepare_initialize_transaction: F,
|
||||||
|
dry_run: bool,
|
||||||
) where
|
) where
|
||||||
F: FnOnce(
|
F: FnOnce(
|
||||||
TargetChain::Index,
|
TargetChain::Index,
|
||||||
@@ -54,6 +55,7 @@ pub async fn initialize<
|
|||||||
target_transactions_signer,
|
target_transactions_signer,
|
||||||
target_signing_data,
|
target_signing_data,
|
||||||
prepare_initialize_transaction,
|
prepare_initialize_transaction,
|
||||||
|
dry_run,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@@ -88,6 +90,7 @@ async fn do_initialize<
|
|||||||
target_transactions_signer: TargetChain::AccountId,
|
target_transactions_signer: TargetChain::AccountId,
|
||||||
target_signing_data: SignParam<TargetChain>,
|
target_signing_data: SignParam<TargetChain>,
|
||||||
prepare_initialize_transaction: F,
|
prepare_initialize_transaction: F,
|
||||||
|
dry_run: bool,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
Option<TargetChain::Hash>,
|
Option<TargetChain::Hash>,
|
||||||
Error<SourceChain::Hash, <SourceChain::Header as HeaderT>::Number>,
|
Error<SourceChain::Hash, <SourceChain::Header as HeaderT>::Number>,
|
||||||
@@ -110,8 +113,10 @@ where
|
|||||||
SourceChain::NAME,
|
SourceChain::NAME,
|
||||||
TargetChain::NAME,
|
TargetChain::NAME,
|
||||||
);
|
);
|
||||||
|
if !dry_run {
|
||||||
return Ok(None)
|
return Ok(None)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let initialization_data = E::prepare_initialization_data(source_client).await?;
|
let initialization_data = E::prepare_initialization_data(source_client).await?;
|
||||||
log::info!(
|
log::info!(
|
||||||
@@ -127,7 +132,14 @@ where
|
|||||||
target_transactions_signer,
|
target_transactions_signer,
|
||||||
target_signing_data,
|
target_signing_data,
|
||||||
move |_, transaction_nonce| {
|
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
|
.await
|
||||||
|
|||||||
Reference in New Issue
Block a user