mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
Encode and estimate Rococo/Wococo/Kusama/Polkadot messages (#1322)
* encode and estimate Rococo/Wococo/Kusama/Polkadot messages * allow send-message for non-bundled chains * weight -> dispatch-weight * fmt * fix spelling
This commit is contained in:
committed by
Bastian Köcher
parent
097a28418b
commit
efa3e97210
@@ -123,17 +123,17 @@ where
|
||||
.submit_signed_extrinsic(
|
||||
self.transaction_params.signer.public().into(),
|
||||
move |best_block_id, transaction_nonce| {
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
P::TransactionSignScheme::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash,
|
||||
signer: transaction_params.signer.clone(),
|
||||
era: TransactionEra::new(best_block_id, transaction_params.mortality),
|
||||
unsigned: UnsignedTransaction::new(call, transaction_nonce),
|
||||
})
|
||||
unsigned: UnsignedTransaction::new(call.into(), transaction_nonce),
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -31,7 +31,9 @@ use bp_header_chain::{
|
||||
use codec::Decode;
|
||||
use finality_grandpa::voter_set::VoterSet;
|
||||
use num_traits::{One, Zero};
|
||||
use relay_substrate_client::{BlockNumberOf, Chain, ChainWithGrandpa, Client, HashOf};
|
||||
use relay_substrate_client::{
|
||||
BlockNumberOf, Chain, ChainWithGrandpa, Client, Error as SubstrateError, HashOf,
|
||||
};
|
||||
use sp_core::Bytes;
|
||||
use sp_finality_grandpa::AuthorityList as GrandpaAuthoritiesSet;
|
||||
use sp_runtime::traits::Header as HeaderT;
|
||||
@@ -41,7 +43,10 @@ pub async fn initialize<SourceChain: ChainWithGrandpa, TargetChain: Chain>(
|
||||
source_client: Client<SourceChain>,
|
||||
target_client: Client<TargetChain>,
|
||||
target_transactions_signer: TargetChain::AccountId,
|
||||
prepare_initialize_transaction: impl FnOnce(TargetChain::Index, InitializationData<SourceChain::Header>) -> Bytes
|
||||
prepare_initialize_transaction: impl FnOnce(
|
||||
TargetChain::Index,
|
||||
InitializationData<SourceChain::Header>,
|
||||
) -> Result<Bytes, SubstrateError>
|
||||
+ Send
|
||||
+ 'static,
|
||||
) {
|
||||
@@ -77,7 +82,10 @@ async fn do_initialize<SourceChain: ChainWithGrandpa, TargetChain: Chain>(
|
||||
source_client: Client<SourceChain>,
|
||||
target_client: Client<TargetChain>,
|
||||
target_transactions_signer: TargetChain::AccountId,
|
||||
prepare_initialize_transaction: impl FnOnce(TargetChain::Index, InitializationData<SourceChain::Header>) -> Bytes
|
||||
prepare_initialize_transaction: impl FnOnce(
|
||||
TargetChain::Index,
|
||||
InitializationData<SourceChain::Header>,
|
||||
) -> Result<Bytes, SubstrateError>
|
||||
+ Send
|
||||
+ 'static,
|
||||
) -> Result<
|
||||
|
||||
@@ -282,8 +282,8 @@ where
|
||||
Ok(v) => v,
|
||||
Err(_) => return BalanceOf::<P::SourceChain>::max_value(),
|
||||
};
|
||||
self.client
|
||||
.estimate_extrinsic_fee(make_messages_delivery_proof_transaction::<P>(
|
||||
async {
|
||||
let dummy_tx = make_messages_delivery_proof_transaction::<P>(
|
||||
runtime_version.spec_version,
|
||||
runtime_version.transaction_version,
|
||||
self.client.genesis_hash(),
|
||||
@@ -292,10 +292,14 @@ where
|
||||
Zero::zero(),
|
||||
prepare_dummy_messages_delivery_proof::<P::SourceChain, P::TargetChain>(),
|
||||
false,
|
||||
))
|
||||
.await
|
||||
.map(|fee| fee.inclusion_fee())
|
||||
.unwrap_or_else(|_| BalanceOf::<P::SourceChain>::max_value())
|
||||
)?;
|
||||
self.client
|
||||
.estimate_extrinsic_fee(dummy_tx)
|
||||
.await
|
||||
.map(|fee| fee.inclusion_fee())
|
||||
}
|
||||
.await
|
||||
.unwrap_or_else(|_| BalanceOf::<P::SourceChain>::max_value())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,7 +332,7 @@ fn make_messages_delivery_proof_transaction<P: SubstrateMessageLane>(
|
||||
transaction_nonce: IndexOf<P::SourceChain>,
|
||||
proof: SubstrateMessagesDeliveryProof<P::TargetChain>,
|
||||
trace_call: bool,
|
||||
) -> Bytes
|
||||
) -> Result<Bytes, SubstrateError>
|
||||
where
|
||||
P::SourceTransactionSignScheme: TransactionSignScheme<Chain = P::SourceChain>,
|
||||
{
|
||||
@@ -336,17 +340,17 @@ where
|
||||
P::ReceiveMessagesDeliveryProofCallBuilder::build_receive_messages_delivery_proof_call(
|
||||
proof, trace_call,
|
||||
);
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
P::SourceTransactionSignScheme::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: *source_genesis_hash,
|
||||
signer: source_transaction_params.signer.clone(),
|
||||
era: TransactionEra::new(source_best_block_id, source_transaction_params.mortality),
|
||||
unsigned: UnsignedTransaction::new(call, transaction_nonce),
|
||||
})
|
||||
unsigned: UnsignedTransaction::new(call.into(), transaction_nonce),
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
/// Prepare 'dummy' messages delivery proof that will compose the delivery confirmation transaction.
|
||||
|
||||
@@ -298,7 +298,7 @@ where
|
||||
total_size,
|
||||
),
|
||||
false,
|
||||
);
|
||||
)?;
|
||||
let delivery_tx_fee = self.client.estimate_extrinsic_fee(delivery_tx).await?;
|
||||
let inclusion_fee_in_target_tokens = delivery_tx_fee.inclusion_fee();
|
||||
|
||||
@@ -323,25 +323,23 @@ where
|
||||
|
||||
let (spec_version, transaction_version) = self.client.simple_runtime_version().await?;
|
||||
let larger_dispatch_weight = total_dispatch_weight.saturating_add(WEIGHT_DIFFERENCE);
|
||||
let larger_delivery_tx_fee = self
|
||||
.client
|
||||
.estimate_extrinsic_fee(make_messages_delivery_transaction::<P>(
|
||||
spec_version,
|
||||
transaction_version,
|
||||
self.client.genesis_hash(),
|
||||
&self.transaction_params,
|
||||
HeaderId(Default::default(), Default::default()),
|
||||
Zero::zero(),
|
||||
self.relayer_id_at_source.clone(),
|
||||
let dummy_tx = make_messages_delivery_transaction::<P>(
|
||||
spec_version,
|
||||
transaction_version,
|
||||
self.client.genesis_hash(),
|
||||
&self.transaction_params,
|
||||
HeaderId(Default::default(), Default::default()),
|
||||
Zero::zero(),
|
||||
self.relayer_id_at_source.clone(),
|
||||
nonces.clone(),
|
||||
prepare_dummy_messages_proof::<P::SourceChain>(
|
||||
nonces.clone(),
|
||||
prepare_dummy_messages_proof::<P::SourceChain>(
|
||||
nonces.clone(),
|
||||
larger_dispatch_weight,
|
||||
total_size,
|
||||
),
|
||||
false,
|
||||
))
|
||||
.await?;
|
||||
larger_dispatch_weight,
|
||||
total_size,
|
||||
),
|
||||
false,
|
||||
)?;
|
||||
let larger_delivery_tx_fee = self.client.estimate_extrinsic_fee(dummy_tx).await?;
|
||||
|
||||
compute_prepaid_messages_refund::<P::TargetChain>(
|
||||
total_prepaid_nonces,
|
||||
@@ -402,7 +400,7 @@ fn make_messages_delivery_transaction<P: SubstrateMessageLane>(
|
||||
nonces: RangeInclusive<MessageNonce>,
|
||||
proof: SubstrateMessagesProof<P::SourceChain>,
|
||||
trace_call: bool,
|
||||
) -> Bytes
|
||||
) -> Result<Bytes, SubstrateError>
|
||||
where
|
||||
P::TargetTransactionSignScheme: TransactionSignScheme<Chain = P::TargetChain>,
|
||||
{
|
||||
@@ -415,17 +413,17 @@ where
|
||||
dispatch_weight,
|
||||
trace_call,
|
||||
);
|
||||
Bytes(
|
||||
Ok(Bytes(
|
||||
P::TargetTransactionSignScheme::sign_transaction(SignParam {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: *target_genesis_hash,
|
||||
signer: target_transaction_params.signer.clone(),
|
||||
era: TransactionEra::new(target_best_block_id, target_transaction_params.mortality),
|
||||
unsigned: UnsignedTransaction::new(call, transaction_nonce),
|
||||
})
|
||||
unsigned: UnsignedTransaction::new(call.into(), transaction_nonce),
|
||||
})?
|
||||
.encode(),
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
/// Prepare 'dummy' messages proof that will compose the delivery transaction.
|
||||
|
||||
Reference in New Issue
Block a user