refactor transaction sign scheme (#1621)

This commit is contained in:
Svyatoslav Nikolsky
2022-11-02 14:36:48 +03:00
committed by Bastian Köcher
parent 01538bc5fa
commit a979340e49
36 changed files with 188 additions and 269 deletions
+6 -11
View File
@@ -21,7 +21,7 @@ use codec::{Compact, Decode, Encode};
use frame_support::weights::Weight;
use relay_substrate_client::{
BalanceOf, Chain, ChainBase, ChainWithBalances, ChainWithGrandpa, ChainWithMessages,
Error as SubstrateError, IndexOf, SignParam, TransactionSignScheme, UnsignedTransaction,
ChainWithTransactions, Error as SubstrateError, IndexOf, SignParam, UnsignedTransaction,
};
use sp_core::{storage::StorageKey, Pair};
use sp_runtime::{generic::SignedPayload, traits::IdentifyAccount};
@@ -97,14 +97,13 @@ impl ChainWithBalances for Millau {
}
}
impl TransactionSignScheme for Millau {
type Chain = Millau;
impl ChainWithTransactions for Millau {
type AccountKeyPair = sp_core::sr25519::Pair;
type SignedTransaction = millau_runtime::UncheckedExtrinsic;
fn sign_transaction(
param: SignParam<Self>,
unsigned: UnsignedTransaction<Self::Chain>,
unsigned: UnsignedTransaction<Self>,
) -> Result<Self::SignedTransaction, SubstrateError> {
let raw_payload = SignedPayload::from_raw(
unsigned.call.clone(),
@@ -156,18 +155,14 @@ impl TransactionSignScheme for Millau {
.unwrap_or(false)
}
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self::Chain>> {
fn parse_transaction(tx: Self::SignedTransaction) -> Option<UnsignedTransaction<Self>> {
let extra = &tx.signature.as_ref()?.2;
Some(
UnsignedTransaction::new(
tx.function.into(),
Compact::<IndexOf<Self::Chain>>::decode(&mut &extra.5.encode()[..]).ok()?.into(),
Compact::<IndexOf<Self>>::decode(&mut &extra.5.encode()[..]).ok()?.into(),
)
.tip(
Compact::<BalanceOf<Self::Chain>>::decode(&mut &extra.7.encode()[..])
.ok()?
.into(),
),
.tip(Compact::<BalanceOf<Self>>::decode(&mut &extra.7.encode()[..]).ok()?.into()),
)
}
}