mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 12:11:02 +00:00
Extract unsigned tx from the SignParam structure (#1561)
* change sign_transaction method * clippy * rustup update && clippy * remove redudnant clone
This commit is contained in:
committed by
Bastian Köcher
parent
effe0f11c8
commit
f35b4f4897
@@ -71,14 +71,15 @@ mod tests {
|
||||
fn rialto_tx_extra_bytes_constant_is_correct() {
|
||||
let rialto_call =
|
||||
rialto_runtime::Call::System(rialto_runtime::SystemCall::remark { remark: vec![] });
|
||||
let rialto_tx = Rialto::sign_transaction(SignParam {
|
||||
spec_version: 1,
|
||||
transaction_version: 1,
|
||||
genesis_hash: Default::default(),
|
||||
signer: sp_keyring::AccountKeyring::Alice.pair(),
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(rialto_call.clone().into(), 0),
|
||||
})
|
||||
let rialto_tx = Rialto::sign_transaction(
|
||||
SignParam {
|
||||
spec_version: 1,
|
||||
transaction_version: 1,
|
||||
genesis_hash: Default::default(),
|
||||
signer: sp_keyring::AccountKeyring::Alice.pair(),
|
||||
},
|
||||
UnsignedTransaction::new(rialto_call.clone().into(), 0),
|
||||
)
|
||||
.unwrap();
|
||||
let extra_bytes_in_transaction = rialto_tx.encode().len() - rialto_call.encode().len();
|
||||
assert!(
|
||||
@@ -93,14 +94,15 @@ mod tests {
|
||||
fn millau_tx_extra_bytes_constant_is_correct() {
|
||||
let millau_call =
|
||||
millau_runtime::Call::System(millau_runtime::SystemCall::remark { remark: vec![] });
|
||||
let millau_tx = Millau::sign_transaction(SignParam {
|
||||
spec_version: 0,
|
||||
transaction_version: 0,
|
||||
genesis_hash: Default::default(),
|
||||
signer: sp_keyring::AccountKeyring::Alice.pair(),
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(millau_call.clone().into(), 0),
|
||||
})
|
||||
let millau_tx = Millau::sign_transaction(
|
||||
SignParam {
|
||||
spec_version: 0,
|
||||
transaction_version: 0,
|
||||
genesis_hash: Default::default(),
|
||||
signer: sp_keyring::AccountKeyring::Alice.pair(),
|
||||
},
|
||||
UnsignedTransaction::new(millau_call.clone().into(), 0),
|
||||
)
|
||||
.unwrap();
|
||||
let extra_bytes_in_transaction = millau_tx.encode().len() - millau_call.encode().len();
|
||||
assert!(
|
||||
|
||||
@@ -26,11 +26,8 @@ use crate::{
|
||||
cli::{bridge::CliBridgeBase, chain_schema::*},
|
||||
};
|
||||
use bp_runtime::Chain as ChainBase;
|
||||
use codec::Encode;
|
||||
use relay_substrate_client::{
|
||||
AccountKeyPairOf, Chain, SignParam, TransactionSignScheme, UnsignedTransaction,
|
||||
};
|
||||
use sp_core::{Bytes, Pair};
|
||||
use relay_substrate_client::{AccountKeyPairOf, Chain, SignParam, UnsignedTransaction};
|
||||
use sp_core::Pair;
|
||||
use structopt::StructOpt;
|
||||
use strum::{EnumString, EnumVariantNames, VariantNames};
|
||||
use substrate_relay_helper::finality::engine::{Engine, Grandpa as GrandpaFinalityEngine};
|
||||
@@ -82,20 +79,16 @@ where
|
||||
source_client,
|
||||
target_client.clone(),
|
||||
target_sign.public().into(),
|
||||
SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: *target_client.genesis_hash(),
|
||||
signer: target_sign,
|
||||
},
|
||||
move |transaction_nonce, initialization_data| {
|
||||
Ok(Bytes(
|
||||
Self::Target::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: *target_client.genesis_hash(),
|
||||
signer: target_sign,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(
|
||||
Self::encode_init_bridge(initialization_data).into(),
|
||||
transaction_nonce,
|
||||
),
|
||||
})?
|
||||
.encode(),
|
||||
Ok(UnsignedTransaction::new(
|
||||
Self::encode_init_bridge(initialization_data).into(),
|
||||
transaction_nonce,
|
||||
))
|
||||
},
|
||||
)
|
||||
|
||||
@@ -223,13 +223,6 @@ impl std::fmt::Display for HexBytes {
|
||||
}
|
||||
}
|
||||
|
||||
impl HexBytes {
|
||||
/// Encode given object and wrap into nicely formatted bytes.
|
||||
pub fn encode<T: Encode>(t: &T) -> Self {
|
||||
Self(t.encode())
|
||||
}
|
||||
}
|
||||
|
||||
/// Prometheus metrics params.
|
||||
#[derive(Clone, Debug, PartialEq, StructOpt)]
|
||||
pub struct PrometheusParams {
|
||||
|
||||
@@ -27,13 +27,13 @@ use polkadot_runtime_common::{
|
||||
};
|
||||
use polkadot_runtime_parachains::paras::ParaLifecycle;
|
||||
use relay_substrate_client::{
|
||||
AccountIdOf, CallOf, Chain, Client, HashOf, SignParam, Subscription, TransactionSignScheme,
|
||||
TransactionStatusOf, UnsignedTransaction,
|
||||
AccountIdOf, CallOf, Chain, Client, HashOf, SignParam, Subscription, TransactionStatusOf,
|
||||
UnsignedTransaction,
|
||||
};
|
||||
use rialto_runtime::SudoCall;
|
||||
use sp_core::{
|
||||
storage::{well_known_keys::CODE, StorageKey},
|
||||
Bytes, Pair,
|
||||
Pair,
|
||||
};
|
||||
use structopt::StructOpt;
|
||||
use strum::{EnumString, EnumVariantNames, VariantNames};
|
||||
@@ -120,20 +120,16 @@ impl RegisterParachain {
|
||||
relay_client
|
||||
.submit_and_watch_signed_extrinsic(
|
||||
relay_sudo_account.clone(),
|
||||
SignParam::<Relaychain> {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: relay_genesis_hash,
|
||||
signer: reserve_parachain_signer,
|
||||
},
|
||||
move |_, transaction_nonce| {
|
||||
Ok(Bytes(
|
||||
Relaychain::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: relay_genesis_hash,
|
||||
signer: reserve_parachain_signer,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(
|
||||
reserve_parachain_id_call.into(),
|
||||
transaction_nonce,
|
||||
),
|
||||
})?
|
||||
.encode(),
|
||||
Ok(UnsignedTransaction::new(
|
||||
reserve_parachain_id_call.into(),
|
||||
transaction_nonce,
|
||||
))
|
||||
},
|
||||
)
|
||||
@@ -169,20 +165,16 @@ impl RegisterParachain {
|
||||
relay_client
|
||||
.submit_and_watch_signed_extrinsic(
|
||||
relay_sudo_account.clone(),
|
||||
SignParam::<Relaychain> {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: relay_genesis_hash,
|
||||
signer: register_parathread_signer,
|
||||
},
|
||||
move |_, transaction_nonce| {
|
||||
Ok(Bytes(
|
||||
Relaychain::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: relay_genesis_hash,
|
||||
signer: register_parathread_signer,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(
|
||||
register_parathread_call.into(),
|
||||
transaction_nonce,
|
||||
),
|
||||
})?
|
||||
.encode(),
|
||||
Ok(UnsignedTransaction::new(
|
||||
register_parathread_call.into(),
|
||||
transaction_nonce,
|
||||
))
|
||||
},
|
||||
)
|
||||
@@ -231,22 +223,18 @@ impl RegisterParachain {
|
||||
.into();
|
||||
let force_lease_signer = relay_sign.clone();
|
||||
relay_client
|
||||
.submit_signed_extrinsic(relay_sudo_account.clone(), move |_, transaction_nonce| {
|
||||
Ok(Bytes(
|
||||
Relaychain::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: relay_genesis_hash,
|
||||
signer: force_lease_signer,
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(
|
||||
force_lease_call.into(),
|
||||
transaction_nonce,
|
||||
),
|
||||
})?
|
||||
.encode(),
|
||||
))
|
||||
})
|
||||
.submit_signed_extrinsic(
|
||||
relay_sudo_account,
|
||||
SignParam::<Relaychain> {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: relay_genesis_hash,
|
||||
signer: force_lease_signer,
|
||||
},
|
||||
move |_, transaction_nonce| {
|
||||
Ok(UnsignedTransaction::new(force_lease_call.into(), transaction_nonce))
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
log::info!(target: "bridge", "Registered parachain leases: {:?}. Waiting for onboarding", para_id);
|
||||
|
||||
|
||||
@@ -425,14 +425,15 @@ async fn update_transaction_tip<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
current_priority = client
|
||||
.validate_transaction(
|
||||
at_block.1,
|
||||
S::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: *client.genesis_hash(),
|
||||
signer: transaction_params.signer.clone(),
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: unsigned_tx.clone(),
|
||||
})?,
|
||||
S::sign_transaction(
|
||||
SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: *client.genesis_hash(),
|
||||
signer: transaction_params.signer.clone(),
|
||||
},
|
||||
unsigned_tx.clone(),
|
||||
)?,
|
||||
)
|
||||
.await??
|
||||
.priority;
|
||||
@@ -448,17 +449,18 @@ async fn update_transaction_tip<C: Chain, S: TransactionSignScheme<Chain = C>>(
|
||||
|
||||
Ok((
|
||||
old_tip != unsigned_tx.tip,
|
||||
S::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: *client.genesis_hash(),
|
||||
signer: transaction_params.signer.clone(),
|
||||
era: relay_substrate_client::TransactionEra::new(
|
||||
S::sign_transaction(
|
||||
SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: *client.genesis_hash(),
|
||||
signer: transaction_params.signer.clone(),
|
||||
},
|
||||
unsigned_tx.era(relay_substrate_client::TransactionEra::new(
|
||||
at_block,
|
||||
transaction_params.mortality,
|
||||
),
|
||||
unsigned: unsigned_tx,
|
||||
})?,
|
||||
)),
|
||||
)?,
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ use crate::{
|
||||
chain_schema::*,
|
||||
encode_message::{self, CliEncodeMessage, RawMessage},
|
||||
estimate_fee::{estimate_message_delivery_and_dispatch_fee, ConversionRateOverride},
|
||||
Balance, CliChain, HexBytes, HexLaneId,
|
||||
Balance, CliChain, HexLaneId,
|
||||
},
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
@@ -146,55 +146,50 @@ where
|
||||
let (spec_version, transaction_version) = source_client.simple_runtime_version().await?;
|
||||
let estimated_transaction_fee = source_client
|
||||
.estimate_extrinsic_fee(Bytes(
|
||||
Self::Source::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: source_genesis_hash,
|
||||
signer: source_sign.clone(),
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(send_message_call.clone(), 0),
|
||||
})?
|
||||
Self::Source::sign_transaction(
|
||||
SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: source_genesis_hash,
|
||||
signer: source_sign.clone(),
|
||||
},
|
||||
UnsignedTransaction::new(send_message_call.clone(), 0),
|
||||
)?
|
||||
.encode(),
|
||||
))
|
||||
.await?;
|
||||
source_client
|
||||
.submit_signed_extrinsic(source_sign.public().into(), move |_, transaction_nonce| {
|
||||
let signed_source_call = Self::Source::sign_transaction(SignParam {
|
||||
.submit_signed_extrinsic(
|
||||
source_sign.public().into(),
|
||||
SignParam::<Self::Source> {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: source_genesis_hash,
|
||||
signer: source_sign.clone(),
|
||||
era: relay_substrate_client::TransactionEra::immortal(),
|
||||
unsigned: UnsignedTransaction::new(send_message_call, transaction_nonce),
|
||||
})?
|
||||
.encode();
|
||||
},
|
||||
move |_, transaction_nonce| {
|
||||
let unsigned = UnsignedTransaction::new(send_message_call, transaction_nonce);
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
"Sending message to {}. Lane: {:?}. Size: {}. Fee: {}",
|
||||
Self::Target::NAME,
|
||||
lane,
|
||||
payload_len,
|
||||
fee,
|
||||
);
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
"The source account ({:?}) balance will be reduced by (at most) {} (message fee)
|
||||
+ {} (tx fee ) = {} {} tokens", AccountId32::from(source_sign.public()),
|
||||
fee.0,
|
||||
estimated_transaction_fee.inclusion_fee(),
|
||||
fee.0.saturating_add(estimated_transaction_fee.inclusion_fee().into()),
|
||||
Self::Source::NAME,
|
||||
);
|
||||
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
"Sending message to {}. Lane: {:?}. Size: {}. Fee: {}",
|
||||
Self::Target::NAME,
|
||||
lane,
|
||||
payload_len,
|
||||
fee,
|
||||
);
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
"The source account ({:?}) balance will be reduced by (at most) {} (message fee)
|
||||
+ {} (tx fee ) = {} {} tokens", AccountId32::from(source_sign.public()),
|
||||
fee.0,
|
||||
estimated_transaction_fee.inclusion_fee(),
|
||||
fee.0.saturating_add(estimated_transaction_fee.inclusion_fee().into()),
|
||||
Self::Source::NAME,
|
||||
);
|
||||
log::info!(
|
||||
target: "bridge",
|
||||
"Signed {} Call: {:?}",
|
||||
Self::Source::NAME,
|
||||
HexBytes::encode(&signed_source_call)
|
||||
);
|
||||
|
||||
Ok(Bytes(signed_source_call))
|
||||
})
|
||||
Ok(unsigned)
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
@@ -230,7 +225,7 @@ fn decode_xcm(message: RawMessage) -> anyhow::Result<xcm::VersionedXcm<()>> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::cli::ExplicitOrMaximal;
|
||||
use crate::cli::{ExplicitOrMaximal, HexBytes};
|
||||
|
||||
#[test]
|
||||
fn send_raw_rialto_to_millau() {
|
||||
|
||||
Reference in New Issue
Block a user