Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Companion of SignedExtension refactor (#5540)
Browse files Browse the repository at this point in the history
  • Loading branch information
athei committed Apr 7, 2020
1 parent cda8004 commit cf9dc8b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
9 changes: 5 additions & 4 deletions runtime/common/src/parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use sp_runtime::{
traits::{
Hash as HashT, BlakeTwo256, Saturating, One, Zero, Dispatchable,
AccountIdConversion, BadOrigin, Convert, SignedExtension, AppVerify,
DispatchInfoOf,
},
transaction_validity::{TransactionValidityError, ValidTransaction, TransactionValidity},
};
Expand All @@ -35,7 +36,7 @@ use sp_staking::{
use frame_support::{
traits::KeyOwnerProofSystem,
dispatch::{IsSubType},
weights::{DispatchInfo, SimpleDispatchInfo, Weight, WeighData},
weights::{SimpleDispatchInfo, Weight, WeighData},
};
use primitives::{
Balance,
Expand Down Expand Up @@ -1456,7 +1457,6 @@ impl<T: Trait + Send + Sync> SignedExtension for ValidateDoubleVoteReports<T> wh
type Call = <T as system::Trait>::Call;
type AdditionalSigned = ();
type Pre = ();
type DispatchInfo = DispatchInfo;

fn additional_signed(&self)
-> sp_std::result::Result<Self::AdditionalSigned, TransactionValidityError>
Expand All @@ -1468,7 +1468,7 @@ impl<T: Trait + Send + Sync> SignedExtension for ValidateDoubleVoteReports<T> wh
&self,
_who: &Self::AccountId,
call: &Self::Call,
_info: DispatchInfo,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
let r = ValidTransaction::default();
Expand Down Expand Up @@ -1538,6 +1538,7 @@ mod tests {
use frame_support::{
impl_outer_origin, impl_outer_dispatch, assert_ok, assert_err, parameter_types,
traits::{OnInitialize, OnFinalize},
weights::DispatchInfo,
};
use crate::parachains;
use crate::registrar;
Expand Down Expand Up @@ -1900,7 +1901,7 @@ mod tests {
let call = Call::Parachains(inner.clone());

ValidateDoubleVoteReports::<Test>(sp_std::marker::PhantomData)
.validate(&0, &call, DispatchInfo::default(), 0)?;
.validate(&0, &call, &DispatchInfo::default(), 0)?;

Ok(inner)
}
Expand Down
14 changes: 7 additions & 7 deletions runtime/common/src/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ use codec::{Encode, Decode};

use sp_runtime::{
transaction_validity::{TransactionValidityError, ValidTransaction, TransactionValidity},
traits::{Hash as HashT, SignedExtension}
traits::{Hash as HashT, SignedExtension, DispatchInfoOf},
};

use frame_support::{
decl_storage, decl_module, decl_event, decl_error, ensure,
dispatch::{DispatchResult, IsSubType}, traits::{Get, Currency, ReservableCurrency},
weights::{SimpleDispatchInfo, DispatchInfo, Weight, WeighData},
weights::{SimpleDispatchInfo, Weight, WeighData},
};
use system::{self, ensure_root, ensure_signed};
use primitives::parachain::{
Expand Down Expand Up @@ -588,7 +588,6 @@ impl<T: Trait + Send + Sync> SignedExtension for LimitParathreadCommits<T> where
type Call = <T as system::Trait>::Call;
type AdditionalSigned = ();
type Pre = ();
type DispatchInfo = DispatchInfo;

fn additional_signed(&self)
-> sp_std::result::Result<Self::AdditionalSigned, TransactionValidityError>
Expand All @@ -600,7 +599,7 @@ impl<T: Trait + Send + Sync> SignedExtension for LimitParathreadCommits<T> where
&self,
_who: &Self::AccountId,
call: &Self::Call,
_info: DispatchInfo,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
let mut r = ValidTransaction::default();
Expand Down Expand Up @@ -673,6 +672,7 @@ mod tests {
use frame_support::{
traits::{KeyOwnerProofSystem, OnInitialize, OnFinalize},
impl_outer_origin, impl_outer_dispatch, assert_ok, parameter_types, assert_noop,
weights::DispatchInfo,
};
use keyring::Sr25519Keyring;

Expand Down Expand Up @@ -969,7 +969,7 @@ mod tests {
let inner_call = super::Call::select_parathread(id, col.clone(), hdh);
let call = Call::Registrar(inner_call);
let origin = 4u64;
assert!(tx.validate(&origin, &call, Default::default(), 0).is_ok());
assert!(tx.validate(&origin, &call, &Default::default(), 0).is_ok());
assert_ok!(call.dispatch(Origin::signed(origin)));
}

Expand Down Expand Up @@ -1416,7 +1416,7 @@ mod tests {
let bad_para_id = user_id(1);
let bad_head_hash = <Test as system::Trait>::Hashing::hash(&vec![1, 2, 1]);
let good_head_hash = <Test as system::Trait>::Hashing::hash(&vec![1, 1, 1]);
let info = DispatchInfo::default();
let info = &DispatchInfo::default();

// Allow for threads
assert_ok!(Registrar::set_thread_count(Origin::ROOT, 10));
Expand Down Expand Up @@ -1481,7 +1481,7 @@ mod tests {
let head_hash = <Test as system::Trait>::Hashing::hash(&vec![x; 3]);
let inner = super::Call::select_parathread(para_id, collator_id, head_hash);
let call = Call::Registrar(inner);
let info = DispatchInfo::default();
let info = &DispatchInfo::default();

// First 3 transactions win a slot
if x < 3 {
Expand Down
15 changes: 11 additions & 4 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ use sp_runtime::{
TransactionValidity, InvalidTransaction, TransactionValidityError, TransactionSource,
},
curve::PiecewiseLinear,
traits::{BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto, IdentityLookup},
traits::{
BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto, IdentityLookup,
DispatchInfoOf,
},
};
#[cfg(feature = "runtime-benchmarks")]
use sp_runtime::RuntimeString;
Expand All @@ -51,7 +54,6 @@ use sp_core::OpaqueMetadata;
use sp_staking::SessionIndex;
use frame_support::{
parameter_types, construct_runtime, traits::{KeyOwnerProofSystem, SplitTwoWays, Randomness},
weights::DispatchInfo,
};
use im_online::sr25519::AuthorityId as ImOnlineId;
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
Expand Down Expand Up @@ -104,11 +106,16 @@ impl SignedExtension for RestrictFunctionality {
type Call = Call;
type AdditionalSigned = ();
type Pre = ();
type DispatchInfo = DispatchInfo;

fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> { Ok(()) }

fn validate(&self, _: &Self::AccountId, call: &Self::Call, _: DispatchInfo, _: usize)
fn validate(
&self,
_: &Self::AccountId,
call: &Self::Call,
_: &DispatchInfoOf<Self::Call>,
_: usize
)
-> TransactionValidity
{
match call {
Expand Down
12 changes: 8 additions & 4 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use sp_runtime::{
curve::PiecewiseLinear,
traits::{
BlakeTwo256, Block as BlockT, SignedExtension, OpaqueKeys, ConvertInto,
IdentityLookup
IdentityLookup, DispatchInfoOf,
},
};
#[cfg(feature = "runtime-benchmarks")]
Expand All @@ -55,7 +55,6 @@ use sp_core::OpaqueMetadata;
use sp_staking::SessionIndex;
use frame_support::{
parameter_types, construct_runtime, traits::{KeyOwnerProofSystem, SplitTwoWays, Randomness},
weights::DispatchInfo,
};
use im_online::sr25519::AuthorityId as ImOnlineId;
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
Expand Down Expand Up @@ -112,11 +111,16 @@ impl SignedExtension for OnlyStakingAndClaims {
type Call = Call;
type AdditionalSigned = ();
type Pre = ();
type DispatchInfo = DispatchInfo;

fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> { Ok(()) }

fn validate(&self, _: &Self::AccountId, call: &Self::Call, _: DispatchInfo, _: usize)
fn validate(
&self, _:
&Self::AccountId,
call: &Self::Call,
_: &DispatchInfoOf<Self::Call>,
_: usize
)
-> TransactionValidity
{
match call {
Expand Down
15 changes: 11 additions & 4 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ use sp_runtime::{
TransactionValidity, InvalidTransaction, TransactionValidityError, TransactionSource,
},
curve::PiecewiseLinear,
traits::{BlakeTwo256, Block as BlockT, StaticLookup, SignedExtension, OpaqueKeys, ConvertInto},
traits::{
BlakeTwo256, Block as BlockT, StaticLookup, SignedExtension, OpaqueKeys, ConvertInto,
DispatchInfoOf,
},
};
use version::RuntimeVersion;
use grandpa::{AuthorityId as GrandpaId, fg_primitives};
Expand All @@ -50,7 +53,6 @@ use sp_staking::SessionIndex;
use frame_support::{
parameter_types, construct_runtime,
traits::{KeyOwnerProofSystem, Randomness},
weights::DispatchInfo,
};
use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
use session::historical as session_historical;
Expand Down Expand Up @@ -100,11 +102,16 @@ impl SignedExtension for RestrictFunctionality {
type Call = Call;
type AdditionalSigned = ();
type Pre = ();
type DispatchInfo = DispatchInfo;

fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) }

fn validate(&self, _: &Self::AccountId, call: &Self::Call, _: DispatchInfo, _: usize)
fn validate(
&self,
_: &Self::AccountId,
call: &Self::Call,
_: &DispatchInfoOf<Self::Call>,
_: usize
)
-> TransactionValidity
{
match call {
Expand Down

0 comments on commit cf9dc8b

Please sign in to comment.