From e0ab2cc88c1bd096a24fb886bf51bb8efff45a3a Mon Sep 17 00:00:00 2001 From: weichweich <14820950+weichweich@users.noreply.github.com> Date: Mon, 17 Aug 2020 13:19:11 +0200 Subject: [PATCH] clean up ugly phantom --- bin/node-template/runtime/src/lib.rs | 5 +++-- bin/node/runtime/src/lib.rs | 6 +++--- frame/balances/src/tests_composite.rs | 5 +++-- frame/balances/src/tests_local.rs | 5 +++-- frame/executive/src/lib.rs | 3 ++- frame/transaction-payment/src/lib.rs | 6 ++++-- 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index 334b5e7759963..7d01910916352 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -6,7 +6,7 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -use sp_std::{prelude::*, marker::PhantomData}; +use sp_std::prelude::*; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; use sp_runtime::{ ApplyExtrinsicResult, generic, create_runtime_str, impl_opaque_keys, MultiSignature, @@ -37,6 +37,7 @@ pub use frame_support::{ constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, }, }; +use pallet_transaction_payment::CurrencyAdapter; /// Import the template pallet. pub use template; @@ -246,7 +247,7 @@ parameter_types! { impl pallet_transaction_payment::Trait for Runtime { type Balance = Balance; - type OnChargeTransaction = (PhantomData>, PhantomData<()>); + type OnChargeTransaction = CurrencyAdapter, ()>; type TransactionByteFee = TransactionByteFee; type WeightToFee = IdentityFee; type FeeMultiplierUpdate = (); diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index d1c718eaa093b..47864a654cc41 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -22,7 +22,7 @@ // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit="256"] -use sp_std::{prelude::*, marker::PhantomData}; +use sp_std::prelude::*; use frame_support::{ construct_runtime, parameter_types, debug, RuntimeDebug, @@ -61,7 +61,7 @@ use pallet_grandpa::fg_primitives; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo; -pub use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment}; +pub use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment, CurrencyAdapter}; use pallet_contracts_rpc_runtime_api::ContractExecResult; use pallet_session::{historical as pallet_session_historical}; use sp_inherents::{InherentData, CheckInherentsResult}; @@ -337,7 +337,7 @@ parameter_types! { impl pallet_transaction_payment::Trait for Runtime { type Balance = Balance; - type OnChargeTransaction = (PhantomData>, PhantomData); + type OnChargeTransaction = CurrencyAdapter, DealWithFees>; type TransactionByteFee = TransactionByteFee; type WeightToFee = IdentityFee; type FeeMultiplierUpdate = diff --git a/frame/balances/src/tests_composite.rs b/frame/balances/src/tests_composite.rs index d334b30ff246a..924e03f1cd8d3 100644 --- a/frame/balances/src/tests_composite.rs +++ b/frame/balances/src/tests_composite.rs @@ -29,7 +29,8 @@ use sp_io; use frame_support::{impl_outer_origin, impl_outer_event, parameter_types}; use frame_support::traits::Get; use frame_support::weights::{Weight, DispatchInfo, IdentityFee}; -use std::{marker::PhantomData, cell::RefCell}; +use pallet_transaction_payment::CurrencyAdapter; +use std::cell::RefCell; use crate::{GenesisConfig, Module, Trait, decl_tests, tests::CallWithDispatchInfo}; use frame_system as system; @@ -98,7 +99,7 @@ parameter_types! { } impl pallet_transaction_payment::Trait for Test { type Balance = u64; - type OnChargeTransaction = (PhantomData>, PhantomData<()>); + type OnChargeTransaction = CurrencyAdapter, ()>; type TransactionByteFee = TransactionByteFee; type WeightToFee = IdentityFee; type FeeMultiplierUpdate = (); diff --git a/frame/balances/src/tests_local.rs b/frame/balances/src/tests_local.rs index d0f7320beeceb..fdc894716d6e2 100644 --- a/frame/balances/src/tests_local.rs +++ b/frame/balances/src/tests_local.rs @@ -29,8 +29,9 @@ use sp_io; use frame_support::{impl_outer_origin, impl_outer_event, parameter_types}; use frame_support::traits::{Get, StorageMapShim}; use frame_support::weights::{Weight, DispatchInfo, IdentityFee}; -use std::{marker::PhantomData, cell::RefCell}; +use std::cell::RefCell; use crate::{GenesisConfig, Module, Trait, decl_tests, tests::CallWithDispatchInfo}; +use pallet_transaction_payment::CurrencyAdapter; use frame_system as system; impl_outer_origin!{ @@ -98,7 +99,7 @@ parameter_types! { } impl pallet_transaction_payment::Trait for Test { type Balance = u64; - type OnChargeTransaction = (PhantomData>, PhantomData<()>); + type OnChargeTransaction = CurrencyAdapter, ()>; type TransactionByteFee = TransactionByteFee; type WeightToFee = IdentityFee; type FeeMultiplierUpdate = (); diff --git a/frame/executive/src/lib.rs b/frame/executive/src/lib.rs index 61005753e4d0e..1afc7a0e62ae1 100644 --- a/frame/executive/src/lib.rs +++ b/frame/executive/src/lib.rs @@ -465,6 +465,7 @@ mod tests { traits::{Currency, LockIdentifier, LockableCurrency, WithdrawReasons, WithdrawReason}, }; use frame_system::{self as system, Call as SystemCall, ChainContext, LastRuntimeUpgradeInfo}; + use pallet_transaction_payment::CurrencyAdapter; use pallet_balances::Call as BalancesCall; use hex_literal::hex; const TEST_KEY: &[u8] = &*b":test:key:"; @@ -592,7 +593,7 @@ mod tests { } impl pallet_transaction_payment::Trait for Runtime { type Balance = Balance; - type OnChargeTransaction = (PhantomData>, PhantomData<()>); + type OnChargeTransaction = CurrencyAdapter, ()>; type TransactionByteFee = TransactionByteFee; type WeightToFee = IdentityFee; type FeeMultiplierUpdate = (); diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 616bc7d8522ee..a10ed43290417 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -239,8 +239,10 @@ pub trait OnChargeTransaction { ) -> Result<(), TransactionValidityError>; } +pub struct CurrencyAdapter(PhantomData, PhantomData); + /// Default implementation for a Currency and an OnUnbalanced handler. -impl OnChargeTransaction for (PhantomData, PhantomData) +impl OnChargeTransaction for CurrencyAdapter where B: AtLeast32BitUnsigned + FullCodec @@ -775,7 +777,7 @@ mod tests { impl Trait for Runtime { type Balance = u64; - type OnChargeTransaction = (PhantomData>, PhantomData<()>); + type OnChargeTransaction = CurrencyAdapter, ()>; type TransactionByteFee = TransactionByteFee; type WeightToFee = WeightToFee; type FeeMultiplierUpdate = ();