Transactions resubmitter (#1083)

* resubmit transactions: start

* resubmit transactions: continue

* enable resubmitter in deployments

* clippy

* spellcheck

* Update relays/client-substrate/src/chain.rs

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* fix compilation

* fix compilation

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
Svyatoslav Nikolsky
2021-09-09 10:26:10 +03:00
committed by Bastian Köcher
parent d59d442e93
commit 1df7076c4f
28 changed files with 682 additions and 151 deletions
+27 -6
View File
@@ -17,7 +17,9 @@
//! Types used to connect to the Rococo-Substrate chain.
use codec::Encode;
use relay_substrate_client::{Chain, ChainBase, ChainWithBalances, TransactionSignScheme};
use relay_substrate_client::{
Chain, ChainBase, ChainWithBalances, TransactionEraOf, TransactionSignScheme, UnsignedTransaction,
};
use sp_core::{storage::StorageKey, Pair};
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
use std::time::Duration;
@@ -69,13 +71,12 @@ impl TransactionSignScheme for Rococo {
fn sign_transaction(
genesis_hash: <Self::Chain as ChainBase>::Hash,
signer: &Self::AccountKeyPair,
era: relay_substrate_client::TransactionEraOf<Self::Chain>,
signer_nonce: <Self::Chain as Chain>::Index,
call: <Self::Chain as Chain>::Call,
era: TransactionEraOf<Self::Chain>,
unsigned: UnsignedTransaction<Self::Chain>,
) -> Self::SignedTransaction {
let raw_payload = SignedPayload::new(
call,
bp_rococo::SignedExtensions::new(bp_rococo::VERSION, era, genesis_hash, signer_nonce, 0),
unsigned.call,
bp_rococo::SignedExtensions::new(bp_rococo::VERSION, era, genesis_hash, unsigned.nonce, unsigned.tip),
)
.expect("SignedExtension never fails.");
@@ -90,6 +91,26 @@ impl TransactionSignScheme for Rococo {
extra,
)
}
fn is_signed(tx: &Self::SignedTransaction) -> bool {
tx.signature.is_some()
}
fn is_signed_by(signer: &Self::AccountKeyPair, tx: &Self::SignedTransaction) -> bool {
tx.signature
.as_ref()
.map(|(address, _, _)| *address == bp_rococo::AccountId::from(*signer.public().as_array_ref()).into())
.unwrap_or(false)
}
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self::Chain>> {
let extra = &tx.signature.as_ref()?.2;
Some(UnsignedTransaction {
call: tx.function,
nonce: extra.nonce(),
tip: extra.tip(),
})
}
}
/// Rococo signing params.