mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 09:51:02 +00:00
Replace BATCH_CALL_SUPPORTED (#1733)
* 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.
This commit is contained in:
committed by
Bastian Köcher
parent
df1aed01c4
commit
e47f1e42e0
@@ -23,8 +23,8 @@ use crate::{
|
||||
SubstrateFrameSystemClient, SubstrateStateClient, SubstrateSystemClient,
|
||||
SubstrateTransactionPaymentClient,
|
||||
},
|
||||
transaction_stall_timeout, ConnectionParams, Error, HashOf, HeaderIdOf, Result, SignParam,
|
||||
TransactionTracker, UnsignedTransaction,
|
||||
transaction_stall_timeout, AccountKeyPairOf, ConnectionParams, Error, HashOf, HeaderIdOf,
|
||||
Result, SignParam, TransactionTracker, UnsignedTransaction,
|
||||
};
|
||||
|
||||
use async_std::sync::{Arc, Mutex};
|
||||
@@ -43,7 +43,7 @@ use pallet_transaction_payment::InclusionFee;
|
||||
use relay_utils::{relay_loop::RECONNECT_DELAY, STALL_TIMEOUT};
|
||||
use sp_core::{
|
||||
storage::{StorageData, StorageKey},
|
||||
Bytes, Hasher,
|
||||
Bytes, Hasher, Pair,
|
||||
};
|
||||
use sp_runtime::{
|
||||
traits::Header as HeaderT,
|
||||
@@ -426,6 +426,19 @@ impl<C: Chain> Client<C> {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn build_sign_params(&self, signer: AccountKeyPairOf<C>) -> Result<SignParam<C>>
|
||||
where
|
||||
C: ChainWithTransactions,
|
||||
{
|
||||
let (spec_version, transaction_version) = self.simple_runtime_version().await?;
|
||||
Ok(SignParam::<C> {
|
||||
spec_version,
|
||||
transaction_version,
|
||||
genesis_hash: self.genesis_hash,
|
||||
signer,
|
||||
})
|
||||
}
|
||||
|
||||
/// Submit an extrinsic signed by given account.
|
||||
///
|
||||
/// All calls of this method are synchronized, so there can't be more than one active
|
||||
@@ -435,18 +448,19 @@ impl<C: Chain> Client<C> {
|
||||
/// Note: The given transaction needs to be SCALE encoded beforehand.
|
||||
pub async fn submit_signed_extrinsic(
|
||||
&self,
|
||||
extrinsic_signer: C::AccountId,
|
||||
signing_data: SignParam<C>,
|
||||
signer: &AccountKeyPairOf<C>,
|
||||
prepare_extrinsic: impl FnOnce(HeaderIdOf<C>, C::Index) -> Result<UnsignedTransaction<C>>
|
||||
+ Send
|
||||
+ 'static,
|
||||
) -> Result<C::Hash>
|
||||
where
|
||||
C: ChainWithTransactions,
|
||||
C::AccountId: From<<C::AccountKeyPair as Pair>::Public>,
|
||||
{
|
||||
let _guard = self.submit_signed_extrinsic_lock.lock().await;
|
||||
let transaction_nonce = self.next_account_index(extrinsic_signer).await?;
|
||||
let transaction_nonce = self.next_account_index(signer.public().into()).await?;
|
||||
let best_header = self.best_header().await?;
|
||||
let signing_data = self.build_sign_params(signer.clone()).await?;
|
||||
|
||||
// By using parent of best block here, we are protecing again best-block reorganizations.
|
||||
// E.g. transaction may have been submitted when the best block was `A[num=100]`. Then it
|
||||
@@ -475,18 +489,19 @@ impl<C: Chain> Client<C> {
|
||||
/// after submission.
|
||||
pub async fn submit_and_watch_signed_extrinsic(
|
||||
&self,
|
||||
extrinsic_signer: C::AccountId,
|
||||
signing_data: SignParam<C>,
|
||||
signer: &AccountKeyPairOf<C>,
|
||||
prepare_extrinsic: impl FnOnce(HeaderIdOf<C>, C::Index) -> Result<UnsignedTransaction<C>>
|
||||
+ Send
|
||||
+ 'static,
|
||||
) -> Result<TransactionTracker<C, Self>>
|
||||
where
|
||||
C: ChainWithTransactions,
|
||||
C::AccountId: From<<C::AccountKeyPair as Pair>::Public>,
|
||||
{
|
||||
let self_clone = self.clone();
|
||||
let signing_data = self.build_sign_params(signer.clone()).await?;
|
||||
let _guard = self.submit_signed_extrinsic_lock.lock().await;
|
||||
let transaction_nonce = self.next_account_index(extrinsic_signer).await?;
|
||||
let transaction_nonce = self.next_account_index(signer.public().into()).await?;
|
||||
let best_header = self.best_header().await?;
|
||||
let best_header_id = best_header.id();
|
||||
let (sender, receiver) = futures::channel::mpsc::channel(MAX_SUBSCRIPTION_CAPACITY);
|
||||
|
||||
Reference in New Issue
Block a user