Skip to content

Commit

Permalink
clean up ugly phantom
Browse files Browse the repository at this point in the history
  • Loading branch information
weichweich committed Aug 17, 2020
1 parent 27eaf3a commit e0ab2cc
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
5 changes: 3 additions & 2 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -246,7 +247,7 @@ parameter_types! {

impl pallet_transaction_payment::Trait for Runtime {
type Balance = Balance;
type OnChargeTransaction = (PhantomData<pallet_balances::Module<Runtime>>, PhantomData<()>);
type OnChargeTransaction = CurrencyAdapter<pallet_balances::Module<Runtime>, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ();
Expand Down
6 changes: 3 additions & 3 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -337,7 +337,7 @@ parameter_types! {

impl pallet_transaction_payment::Trait for Runtime {
type Balance = Balance;
type OnChargeTransaction = (PhantomData<pallet_balances::Module<Runtime>>, PhantomData<DealWithFees>);
type OnChargeTransaction = CurrencyAdapter<pallet_balances::Module<Runtime>, DealWithFees>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate =
Expand Down
5 changes: 3 additions & 2 deletions frame/balances/src/tests_composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,7 +99,7 @@ parameter_types! {
}
impl pallet_transaction_payment::Trait for Test {
type Balance = u64;
type OnChargeTransaction = (PhantomData<Module<Test>>, PhantomData<()>);
type OnChargeTransaction = CurrencyAdapter<Module<Test>, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<u64>;
type FeeMultiplierUpdate = ();
Expand Down
5 changes: 3 additions & 2 deletions frame/balances/src/tests_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!{
Expand Down Expand Up @@ -98,7 +99,7 @@ parameter_types! {
}
impl pallet_transaction_payment::Trait for Test {
type Balance = u64;
type OnChargeTransaction = (PhantomData<Module<Test>>, PhantomData<()>);
type OnChargeTransaction = CurrencyAdapter<Module<Test>, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<u64>;
type FeeMultiplierUpdate = ();
Expand Down
3 changes: 2 additions & 1 deletion frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:";
Expand Down Expand Up @@ -592,7 +593,7 @@ mod tests {
}
impl pallet_transaction_payment::Trait for Runtime {
type Balance = Balance;
type OnChargeTransaction = (PhantomData<pallet_balances::Module<Runtime>>, PhantomData<()>);
type OnChargeTransaction = CurrencyAdapter<pallet_balances::Module<Runtime>, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ();
Expand Down
6 changes: 4 additions & 2 deletions frame/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ pub trait OnChargeTransaction<T: Trait> {
) -> Result<(), TransactionValidityError>;
}

pub struct CurrencyAdapter<C, OU>(PhantomData<C>, PhantomData<OU>);

/// Default implementation for a Currency and an OnUnbalanced handler.
impl<T, C, OU, B> OnChargeTransaction<T> for (PhantomData<C>, PhantomData<OU>)
impl<T, C, OU, B> OnChargeTransaction<T> for CurrencyAdapter<C, OU>
where
B: AtLeast32BitUnsigned
+ FullCodec
Expand Down Expand Up @@ -775,7 +777,7 @@ mod tests {

impl Trait for Runtime {
type Balance = u64;
type OnChargeTransaction = (PhantomData<pallet_balances::Module<Runtime>>, PhantomData<()>);
type OnChargeTransaction = CurrencyAdapter<pallet_balances::Module<Runtime>, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = WeightToFee;
type FeeMultiplierUpdate = ();
Expand Down

0 comments on commit e0ab2cc

Please sign in to comment.