Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions chain-extensions/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use core::num::NonZeroU64;

use frame_support::dispatch::DispatchResult;
use frame_support::traits::{Contains, Everything, InherentBuilder, InsideBoth};
use frame_support::traits::{Contains, Everything, InsideBoth};
use frame_support::weights::Weight;
use frame_support::weights::constants::RocksDbWeight;
use frame_support::{PalletId, derive_impl};
use frame_support::{assert_ok, parameter_types, traits::PrivilegeCmp};
use frame_system as system;
use frame_system::{EnsureRoot, RawOrigin, limits, offchain::CreateTransactionBase};
use frame_system::{EnsureRoot, RawOrigin, limits};
use pallet_contracts::HoldReason as ContractsHoldReason;
use pallet_subtensor::*;
use pallet_subtensor_proxy as pallet_proxy;
Expand Down Expand Up @@ -603,28 +603,12 @@ where
type RuntimeCall = RuntimeCall;
}

impl<LocalCall> frame_system::offchain::CreateInherent<LocalCall> for Test
impl<LocalCall> frame_system::offchain::CreateBare<LocalCall> for Test
where
RuntimeCall: From<LocalCall>,
{
fn create_bare(call: Self::RuntimeCall) -> Self::Extrinsic {
UncheckedExtrinsic::new_inherent(call)
}
}

impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Test
where
RuntimeCall: From<LocalCall>,
{
fn create_signed_transaction<
C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>,
>(
call: <Self as CreateTransactionBase<LocalCall>>::RuntimeCall,
_public: Self::Public,
_account: Self::AccountId,
nonce: Self::Nonce,
) -> Option<Self::Extrinsic> {
Some(UncheckedExtrinsic::new_signed(call, nonce.into(), (), ()))
UncheckedExtrinsic::new_bare(call)
}
}

Expand Down
24 changes: 4 additions & 20 deletions pallets/admin-utils/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use core::num::NonZeroU64;

use frame_support::{
PalletId, assert_ok, derive_impl, parameter_types,
traits::{Everything, Hooks, InherentBuilder, PrivilegeCmp},
traits::{Everything, Hooks, PrivilegeCmp},
};
use frame_system::{self as system, offchain::CreateTransactionBase};
use frame_system::{self as system};
use frame_system::{EnsureRoot, limits};
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_consensus_grandpa::AuthorityList as GrandpaAuthorityList;
Expand Down Expand Up @@ -455,28 +455,12 @@ where
type RuntimeCall = RuntimeCall;
}

impl<LocalCall> frame_system::offchain::CreateInherent<LocalCall> for Test
impl<LocalCall> frame_system::offchain::CreateBare<LocalCall> for Test
where
RuntimeCall: From<LocalCall>,
{
fn create_bare(call: Self::RuntimeCall) -> Self::Extrinsic {
UncheckedExtrinsic::new_inherent(call)
}
}

impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Test
where
RuntimeCall: From<LocalCall>,
{
fn create_signed_transaction<
C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>,
>(
call: <Self as CreateTransactionBase<LocalCall>>::RuntimeCall,
_public: Self::Public,
_account: Self::AccountId,
nonce: Self::Nonce,
) -> Option<Self::Extrinsic> {
Some(UncheckedExtrinsic::new_signed(call, nonce, (), ()))
UncheckedExtrinsic::new_bare(call)
}
}

Expand Down
32 changes: 3 additions & 29 deletions pallets/commitments/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use crate as pallet_commitments;
use frame_support::{
derive_impl,
pallet_prelude::{Get, TypeInfo},
traits::{ConstU32, ConstU64, InherentBuilder},
traits::{ConstU32, ConstU64},
};
use frame_system::offchain::CreateTransactionBase;
use sp_core::H256;
use sp_runtime::{
BuildStorage,
Expand Down Expand Up @@ -167,37 +166,12 @@ where
type RuntimeCall = RuntimeCall;
}

impl<LocalCall> frame_system::offchain::CreateInherent<LocalCall> for Test
impl<LocalCall> frame_system::offchain::CreateBare<LocalCall> for Test
where
RuntimeCall: From<LocalCall>,
{
fn create_bare(call: Self::RuntimeCall) -> Self::Extrinsic {
UncheckedExtrinsic::new_inherent(call)
}
}

impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Test
where
RuntimeCall: From<LocalCall>,
{
fn create_signed_transaction<
C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>,
>(
call: <Self as CreateTransactionBase<LocalCall>>::RuntimeCall,
_public: Self::Public,
_account: Self::AccountId,
nonce: Self::Nonce,
) -> Option<Self::Extrinsic> {
// Create a dummy sr25519 signature from a raw byte array
let dummy_raw = [0u8; 64];
let dummy_signature = sp_core::sr25519::Signature::from(dummy_raw);
let signature = test_crypto::Signature::from(dummy_signature);
Some(UncheckedExtrinsic::new_signed(
call,
nonce.into(),
signature,
(),
))
UncheckedExtrinsic::new_bare(call)
}
}

Expand Down
7 changes: 2 additions & 5 deletions pallets/drand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ use codec::Encode;
use frame_support::{pallet_prelude::*, traits::Randomness};
use frame_system::{
offchain::{
AppCrypto, CreateInherent, CreateSignedTransaction, SendUnsignedTransaction, SignedPayload,
Signer, SigningTypes,
AppCrypto, CreateBare, SendUnsignedTransaction, SignedPayload, Signer, SigningTypes,
},
pallet_prelude::BlockNumberFor,
};
Expand Down Expand Up @@ -159,9 +158,7 @@ pub mod pallet {
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config:
CreateSignedTransaction<Call<Self>> + CreateInherent<Call<Self>> + frame_system::Config
{
pub trait Config: CreateBare<Call<Self>> + SigningTypes + frame_system::Config {
/// The identifier type for an offchain worker.
type AuthorityId: AppCrypto<Self::Public, Self::Signature>;
/// something that knows how to verify beacon pulses
Expand Down
25 changes: 4 additions & 21 deletions pallets/drand/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use crate::verifier::*;
use crate::*;
use frame_support::{
derive_impl, parameter_types,
traits::{ConstU16, ConstU64, InherentBuilder},
traits::{ConstU16, ConstU64},
};
use sp_core::{H256, sr25519::Signature};
use sp_keystore::{KeystoreExt, testing::MemoryKeystore};
use sp_runtime::{
BuildStorage,
testing::TestXt,
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify},
traits::{BlakeTwo256, IdentityLookup, Verify},
};

type Block = frame_system::mocking::MockBlock<Test>;
Expand Down Expand Up @@ -52,7 +52,6 @@ impl frame_system::Config for Test {
}

type Extrinsic = TestXt<RuntimeCall, ()>;
type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;

impl frame_system::offchain::SigningTypes for Test {
type Public = <Signature as Verify>::Signer;
Expand All @@ -67,28 +66,12 @@ where
type Extrinsic = Extrinsic;
}

impl<LocalCall> frame_system::offchain::CreateInherent<LocalCall> for Test
impl<LocalCall> frame_system::offchain::CreateBare<LocalCall> for Test
where
RuntimeCall: From<LocalCall>,
{
fn create_bare(call: RuntimeCall) -> Self::Extrinsic {
Extrinsic::new_inherent(call)
}
}

impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Test
where
RuntimeCall: From<LocalCall>,
{
fn create_signed_transaction<
C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>,
>(
call: RuntimeCall,
_public: <Signature as Verify>::Signer,
_account: AccountId,
nonce: u64,
) -> Option<Self::Extrinsic> {
Some(Extrinsic::new_signed(call, nonce, (), ()))
Extrinsic::new_bare(call)
}
}

Expand Down
24 changes: 4 additions & 20 deletions pallets/subtensor/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core::num::NonZeroU64;

use crate::utils::rate_limiting::TransactionType;
use crate::*;
use frame_support::traits::{Contains, Everything, InherentBuilder, InsideBoth, InstanceFilter};
use frame_support::traits::{Contains, Everything, InsideBoth, InstanceFilter};
use frame_support::weights::Weight;
use frame_support::weights::constants::RocksDbWeight;
use frame_support::{PalletId, derive_impl};
Expand All @@ -17,7 +17,7 @@ use frame_support::{
traits::{Hooks, PrivilegeCmp},
};
use frame_system as system;
use frame_system::{EnsureRoot, RawOrigin, limits, offchain::CreateTransactionBase};
use frame_system::{EnsureRoot, RawOrigin, limits};
use pallet_subtensor_proxy as pallet_proxy;
use pallet_subtensor_utility as pallet_utility;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
Expand Down Expand Up @@ -542,28 +542,12 @@ where
type RuntimeCall = RuntimeCall;
}

impl<LocalCall> frame_system::offchain::CreateInherent<LocalCall> for Test
impl<LocalCall> frame_system::offchain::CreateBare<LocalCall> for Test
where
RuntimeCall: From<LocalCall>,
{
fn create_bare(call: Self::RuntimeCall) -> Self::Extrinsic {
UncheckedExtrinsic::new_inherent(call)
}
}

impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Test
where
RuntimeCall: From<LocalCall>,
{
fn create_signed_transaction<
C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>,
>(
call: <Self as CreateTransactionBase<LocalCall>>::RuntimeCall,
_public: Self::Public,
_account: Self::AccountId,
nonce: Self::Nonce,
) -> Option<Self::Extrinsic> {
Some(UncheckedExtrinsic::new_signed(call, nonce.into(), (), ()))
UncheckedExtrinsic::new_bare(call)
}
}

Expand Down
37 changes: 4 additions & 33 deletions pallets/transaction-fee/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ use core::num::NonZeroU64;
use crate::TransactionFeeHandler;
use frame_support::{
PalletId, assert_ok, derive_impl, parameter_types,
traits::{Everything, Hooks, InherentBuilder, PrivilegeCmp},
traits::{Everything, Hooks, PrivilegeCmp},
weights::IdentityFee,
};
use frame_system::{
self as system, EnsureRoot, RawOrigin, limits, offchain::CreateTransactionBase,
};
use frame_system::{self as system, EnsureRoot, RawOrigin, limits};
pub use pallet_subtensor::*;
pub use sp_core::U256;
use sp_core::{ConstU64, H256};
Expand Down Expand Up @@ -506,39 +504,12 @@ where
type RuntimeCall = RuntimeCall;
}

impl<LocalCall> frame_system::offchain::CreateInherent<LocalCall> for Test
impl<LocalCall> frame_system::offchain::CreateBare<LocalCall> for Test
where
RuntimeCall: From<LocalCall>,
{
fn create_bare(call: Self::RuntimeCall) -> Self::Extrinsic {
UncheckedExtrinsic::new_inherent(call)
}
}

impl<LocalCall> frame_system::offchain::CreateSignedTransaction<LocalCall> for Test
where
RuntimeCall: From<LocalCall>,
{
fn create_signed_transaction<
C: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>,
>(
call: <Self as CreateTransactionBase<LocalCall>>::RuntimeCall,
_public: Self::Public,
_account: Self::AccountId,
nonce: Self::Nonce,
) -> Option<Self::Extrinsic> {
let extra: TransactionExtensions = (
frame_system::CheckNonZeroSender::<Test>::new(),
frame_system::CheckWeight::<Test>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Test>::from(0),
);

Some(UncheckedExtrinsic::new_signed(
call,
nonce.into(),
(),
extra,
))
UncheckedExtrinsic::new_bare(call)
}
}

Expand Down
39 changes: 0 additions & 39 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ use sp_core::{
crypto::{ByteArray, KeyTypeId},
};
use sp_runtime::Cow;
use sp_runtime::generic::Era;
use sp_runtime::{
AccountId32, ApplyExtrinsicResult, ConsensusEngineId, Percent, generic, impl_opaque_keys,
traits::{
Expand Down Expand Up @@ -153,44 +152,6 @@ impl frame_system::offchain::CreateBare<pallet_drand::Call<Runtime>> for Runtime
}
}

impl frame_system::offchain::CreateSignedTransaction<pallet_drand::Call<Runtime>> for Runtime {
fn create_signed_transaction<
S: frame_system::offchain::AppCrypto<Self::Public, Self::Signature>,
>(
call: RuntimeCall,
public: Self::Public,
account: Self::AccountId,
nonce: Self::Nonce,
) -> Option<Self::Extrinsic> {
use sp_runtime::traits::StaticLookup;

let address = <Runtime as frame_system::Config>::Lookup::unlookup(account.clone());
let extra: TransactionExtensions = (
frame_system::CheckNonZeroSender::<Runtime>::new(),
frame_system::CheckSpecVersion::<Runtime>::new(),
frame_system::CheckTxVersion::<Runtime>::new(),
frame_system::CheckGenesis::<Runtime>::new(),
frame_system::CheckEra::<Runtime>::from(Era::Immortal),
check_nonce::CheckNonce::<Runtime>::from(nonce).into(),
frame_system::CheckWeight::<Runtime>::new(),
ChargeTransactionPaymentWrapper::new(
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(0),
),
SudoTransactionExtension::<Runtime>::new(),
pallet_subtensor::SubtensorTransactionExtension::<Runtime>::new(),
pallet_drand::drand_priority::DrandPriority::<Runtime>::new(),
frame_metadata_hash_extension::CheckMetadataHash::<Runtime>::new(true),
);

let raw_payload = SignedPayload::new(call.clone(), extra.clone()).ok()?;
let signature = raw_payload.using_encoded(|payload| S::sign(payload, public))?;

Some(UncheckedExtrinsic::new_signed(
call, address, signature, extra,
))
}
}

// Subtensor module
pub use pallet_scheduler;
pub use pallet_subtensor;
Expand Down
Loading