mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 20:57:59 +00:00
This PR reverts #2280 which introduced `TransactionExtension` to replace `SignedExtension`. As a result of the discussion [here](https://github.com/paritytech/polkadot-sdk/pull/3623#issuecomment-1986789700), the changes will be reverted for now with plans to reintroduce the concept in the future. --------- Signed-off-by: georgepisaltu <george.pisaltu@parity.io>
This commit is contained in:
@@ -25,7 +25,7 @@ use codec::Encode;
|
||||
use frame_system::{CheckNonce, CheckWeight};
|
||||
use sp_core::crypto::Pair as TraitPair;
|
||||
use sp_keyring::AccountKeyring;
|
||||
use sp_runtime::{generic::Preamble, transaction_validity::TransactionPriority, Perbill};
|
||||
use sp_runtime::{transaction_validity::TransactionPriority, Perbill};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
/// Transfer used in test substrate pallet. Extrinsic is created and signed using this data.
|
||||
@@ -66,11 +66,11 @@ impl TryFrom<&Extrinsic> for TransferData {
|
||||
match uxt {
|
||||
Extrinsic {
|
||||
function: RuntimeCall::Balances(BalancesCall::transfer_allow_death { dest, value }),
|
||||
preamble: Preamble::Signed(from, _, ((CheckNonce(nonce), ..), ..)),
|
||||
signature: Some((from, _, (CheckNonce(nonce), ..))),
|
||||
} => Ok(TransferData { from: *from, to: *dest, amount: *value, nonce: *nonce }),
|
||||
Extrinsic {
|
||||
function: RuntimeCall::SubstrateTest(PalletCall::bench_call { transfer }),
|
||||
preamble: Preamble::Bare,
|
||||
signature: None,
|
||||
} => Ok(transfer.clone()),
|
||||
_ => Err(()),
|
||||
}
|
||||
@@ -190,17 +190,18 @@ impl ExtrinsicBuilder {
|
||||
/// Build `Extrinsic` using embedded parameters
|
||||
pub fn build(self) -> Extrinsic {
|
||||
if let Some(signer) = self.signer {
|
||||
let tx_ext = (
|
||||
(CheckNonce::from(self.nonce.unwrap_or(0)), CheckWeight::new()),
|
||||
let extra = (
|
||||
CheckNonce::from(self.nonce.unwrap_or(0)),
|
||||
CheckWeight::new(),
|
||||
CheckSubstrateCall {},
|
||||
);
|
||||
let raw_payload =
|
||||
SignedPayload::from_raw(self.function.clone(), tx_ext.clone(), (((), ()), ()));
|
||||
SignedPayload::from_raw(self.function.clone(), extra.clone(), ((), (), ()));
|
||||
let signature = raw_payload.using_encoded(|e| signer.sign(e));
|
||||
|
||||
Extrinsic::new_signed(self.function, signer.public(), signature, tx_ext)
|
||||
Extrinsic::new_signed(self.function, signer.public(), signature, extra)
|
||||
} else {
|
||||
Extrinsic::new_bare(self.function)
|
||||
Extrinsic::new_unsigned(self.function)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,11 +58,9 @@ use sp_api::{decl_runtime_apis, impl_runtime_apis};
|
||||
pub use sp_core::hash::H256;
|
||||
use sp_inherents::{CheckInherentsResult, InherentData};
|
||||
use sp_runtime::{
|
||||
create_runtime_str, impl_opaque_keys, impl_tx_ext_default,
|
||||
traits::{BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, NumberFor, Verify},
|
||||
transaction_validity::{
|
||||
TransactionSource, TransactionValidity, TransactionValidityError, ValidTransaction,
|
||||
},
|
||||
create_runtime_str, impl_opaque_keys,
|
||||
traits::{BlakeTwo256, Block as BlockT, DispatchInfoOf, NumberFor, Verify},
|
||||
transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError},
|
||||
ApplyExtrinsicResult, ExtrinsicInclusionMode, Perbill,
|
||||
};
|
||||
#[cfg(any(feature = "std", test))]
|
||||
@@ -144,14 +142,13 @@ pub type Signature = sr25519::Signature;
|
||||
#[cfg(feature = "std")]
|
||||
pub type Pair = sp_core::sr25519::Pair;
|
||||
|
||||
// TODO: Remove after the Checks are migrated to TxExtension.
|
||||
/// The extension to the basic transaction logic.
|
||||
pub type TxExtension = ((CheckNonce<Runtime>, CheckWeight<Runtime>), CheckSubstrateCall);
|
||||
/// The SignedExtension to the basic transaction logic.
|
||||
pub type SignedExtra = (CheckNonce<Runtime>, CheckWeight<Runtime>, CheckSubstrateCall);
|
||||
/// The payload being signed in transactions.
|
||||
pub type SignedPayload = sp_runtime::generic::SignedPayload<RuntimeCall, TxExtension>;
|
||||
pub type SignedPayload = sp_runtime::generic::SignedPayload<RuntimeCall, SignedExtra>;
|
||||
/// Unchecked extrinsic type as expected by this runtime.
|
||||
pub type Extrinsic =
|
||||
sp_runtime::generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
|
||||
sp_runtime::generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
|
||||
|
||||
/// An identifier for an account on this system.
|
||||
pub type AccountId = <Signature as Verify>::Signer;
|
||||
@@ -246,7 +243,7 @@ impl sp_runtime::traits::Printable for CheckSubstrateCall {
|
||||
}
|
||||
|
||||
impl sp_runtime::traits::Dispatchable for CheckSubstrateCall {
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeOrigin = CheckSubstrateCall;
|
||||
type Config = CheckSubstrateCall;
|
||||
type Info = CheckSubstrateCall;
|
||||
type PostInfo = CheckSubstrateCall;
|
||||
@@ -259,37 +256,42 @@ impl sp_runtime::traits::Dispatchable for CheckSubstrateCall {
|
||||
}
|
||||
}
|
||||
|
||||
impl sp_runtime::traits::TransactionExtensionBase for CheckSubstrateCall {
|
||||
const IDENTIFIER: &'static str = "CheckSubstrateCall";
|
||||
type Implicit = ();
|
||||
}
|
||||
impl<Context> sp_runtime::traits::TransactionExtension<RuntimeCall, Context>
|
||||
for CheckSubstrateCall
|
||||
{
|
||||
impl sp_runtime::traits::SignedExtension for CheckSubstrateCall {
|
||||
type AccountId = AccountId;
|
||||
type Call = RuntimeCall;
|
||||
type AdditionalSigned = ();
|
||||
type Pre = ();
|
||||
type Val = ();
|
||||
impl_tx_ext_default!(RuntimeCall; Context; prepare);
|
||||
const IDENTIFIER: &'static str = "CheckSubstrateCall";
|
||||
|
||||
fn additional_signed(
|
||||
&self,
|
||||
) -> sp_std::result::Result<Self::AdditionalSigned, TransactionValidityError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate(
|
||||
&self,
|
||||
origin: <RuntimeCall as Dispatchable>::RuntimeOrigin,
|
||||
call: &RuntimeCall,
|
||||
_info: &DispatchInfoOf<RuntimeCall>,
|
||||
_who: &Self::AccountId,
|
||||
call: &Self::Call,
|
||||
_info: &DispatchInfoOf<Self::Call>,
|
||||
_len: usize,
|
||||
_context: &mut Context,
|
||||
_self_implicit: Self::Implicit,
|
||||
_inherited_implication: &impl Encode,
|
||||
) -> Result<
|
||||
(ValidTransaction, Self::Val, <RuntimeCall as Dispatchable>::RuntimeOrigin),
|
||||
TransactionValidityError,
|
||||
> {
|
||||
) -> TransactionValidity {
|
||||
log::trace!(target: LOG_TARGET, "validate");
|
||||
let v = match call {
|
||||
match call {
|
||||
RuntimeCall::SubstrateTest(ref substrate_test_call) =>
|
||||
substrate_test_pallet::validate_runtime_call(substrate_test_call)?,
|
||||
_ => Default::default(),
|
||||
};
|
||||
Ok((v, (), origin))
|
||||
substrate_test_pallet::validate_runtime_call(substrate_test_call),
|
||||
_ => Ok(Default::default()),
|
||||
}
|
||||
}
|
||||
|
||||
fn pre_dispatch(
|
||||
self,
|
||||
who: &Self::AccountId,
|
||||
call: &Self::Call,
|
||||
info: &sp_runtime::traits::DispatchInfoOf<Self::Call>,
|
||||
len: usize,
|
||||
) -> Result<Self::Pre, TransactionValidityError> {
|
||||
self.validate(who, call, info, len).map(drop)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,7 +364,6 @@ impl frame_system::pallet::Config for Runtime {
|
||||
type OnNewAccount = ();
|
||||
type OnKilledAccount = ();
|
||||
type SystemWeightInfo = ();
|
||||
type ExtensionsWeightInfo = ();
|
||||
type SS58Prefix = ();
|
||||
type OnSetCode = ();
|
||||
type MaxConsumers = ConstU32<16>;
|
||||
@@ -671,7 +672,7 @@ impl_runtime_apis! {
|
||||
|
||||
impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
|
||||
fn offchain_worker(header: &<Block as BlockT>::Header) {
|
||||
let ext = Extrinsic::new_bare(
|
||||
let ext = Extrinsic::new_unsigned(
|
||||
substrate_test_pallet::pallet::Call::storage_change{
|
||||
key:b"some_key".encode(),
|
||||
value:Some(header.number.encode())
|
||||
@@ -1024,7 +1025,7 @@ mod tests {
|
||||
use sp_core::{storage::well_known_keys::HEAP_PAGES, traits::CallContext};
|
||||
use sp_keyring::AccountKeyring;
|
||||
use sp_runtime::{
|
||||
traits::{DispatchTransaction, Hash as _},
|
||||
traits::{Hash as _, SignedExtension},
|
||||
transaction_validity::{InvalidTransaction, ValidTransaction},
|
||||
};
|
||||
use substrate_test_runtime_client::{
|
||||
@@ -1173,33 +1174,31 @@ mod tests {
|
||||
fn check_substrate_check_signed_extension_works() {
|
||||
sp_tracing::try_init_simple();
|
||||
new_test_ext().execute_with(|| {
|
||||
let x: AccountId = sp_keyring::AccountKeyring::Alice.into();
|
||||
let x = sp_keyring::AccountKeyring::Alice.into();
|
||||
let info = DispatchInfo::default();
|
||||
let len = 0_usize;
|
||||
assert_eq!(
|
||||
CheckSubstrateCall {}
|
||||
.validate_only(
|
||||
Some(x).into(),
|
||||
.validate(
|
||||
&x,
|
||||
&ExtrinsicBuilder::new_call_with_priority(16).build().function,
|
||||
&info,
|
||||
len,
|
||||
len
|
||||
)
|
||||
.unwrap()
|
||||
.0
|
||||
.priority,
|
||||
16
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
CheckSubstrateCall {}
|
||||
.validate_only(
|
||||
Some(x).into(),
|
||||
.validate(
|
||||
&x,
|
||||
&ExtrinsicBuilder::new_call_do_not_propagate().build().function,
|
||||
&info,
|
||||
len,
|
||||
len
|
||||
)
|
||||
.unwrap()
|
||||
.0
|
||||
.propagate,
|
||||
false
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user