Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Prev Previous commit
Next Next commit
Extract payment stuff from balances
  • Loading branch information
kianenigma committed Oct 12, 2019
commit fac73b7a6402e394ad150baff06a3059c0c50cdc
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions core/sr-primitives/src/sr_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,6 @@ impl Fixed64 {
Self(int.saturating_mul(DIV))
}

pub fn one() -> Self {
Self(DIV)
}

/// Return the accuracy of the type. Given that this function returns the value `X`, it means
/// that an instance composed of `X` parts (`Fixed64::from_parts(X)`) is equal to `1`.
pub fn accuracy() -> i64 {
Expand Down
19 changes: 14 additions & 5 deletions node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ impl system::Trait for Runtime {
type Origin = Origin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
/// Maximum weight of each block. With a default weight system of 1byte == 1weight, 4mb is ok.
/// Maximum weight of each block.
type MaximumBlockWeight = MaximumBlockWeight;
/// Maximum size of all encoded transactions (in bytes) that are allowed in one block.
type MaximumBlockLength = MaximumBlockLength;
/// Portion of the block weight that is available to all normal transactions.
type AvailableBlockRatio = AvailableBlockRatio;
/// Version of the runtime.
type Version = Version;
}

Expand Down Expand Up @@ -223,8 +224,6 @@ parameter_types! {
pub const ExistentialDeposit: u128 = 500;
pub const TransferFee: u128 = 0;
pub const CreationFee: u128 = 0;
pub const TransactionBaseFee: u128 = 0;
pub const TransactionByteFee: u128 = 1;
}

impl balances::Trait for Runtime {
Expand All @@ -236,15 +235,25 @@ impl balances::Trait for Runtime {
type OnNewAccount = Indices;
/// The ubiquitous event type.
type Event = Event;
type TransactionPayment = ();
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
}

parameter_types! {
pub const TransactionBaseFee: Balance = 0;
pub const TransactionByteFee: Balance = 1;
}

impl transaction_payment::Trait for Runtime {
type Currency = balances::Module<Runtime>;
type OnTransactionPayment = ();
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = ConvertInto;
type FeeMultiplierUpdate = ();
}

impl sudo::Trait for Runtime {
Expand Down Expand Up @@ -293,7 +302,7 @@ pub type SignedExtra = (
system::CheckEra<Runtime>,
system::CheckNonce<Runtime>,
system::CheckWeight<Runtime>,
balances::TakeFees<Runtime>
transaction_payment::ChargeTransactionPayment<Runtime>
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
Expand Down
1 change: 1 addition & 0 deletions node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ finality_tracker = { package = "srml-finality-tracker", path = "../../srml/final
contracts = { package = "srml-contracts", path = "../../srml/contracts" }
system = { package = "srml-system", path = "../../srml/system" }
balances = { package = "srml-balances", path = "../../srml/balances" }
transaction-payment = { package = "srml-transaction-payment", path = "../../srml/transaction-payment" }
support = { package = "srml-support", path = "../../srml/support", default-features = false }
im_online = { package = "srml-im-online", path = "../../srml/im-online", default-features = false }
sr-authority-discovery = { package = "srml-authority-discovery", path = "../../srml/authority-discovery", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion node/cli/src/factory_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<Number> FactoryState<Number> {
system::CheckEra::from(Era::mortal(256, phase)),
system::CheckNonce::from(index),
system::CheckWeight::new(),
balances::TakeFees::from(0),
transaction_payment::ChargeTransactionPayment::from(0),
Default::default(),
)
}
Expand Down
4 changes: 2 additions & 2 deletions node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,14 +528,14 @@ mod tests {
let check_era = system::CheckEra::from(Era::Immortal);
let check_nonce = system::CheckNonce::from(index);
let check_weight = system::CheckWeight::new();
let take_fees = balances::TakeFees::from(0);
let payment = transaction_payment::ChargeTransactionPayment::from(0);
let extra = (
check_version,
check_genesis,
check_era,
check_nonce,
check_weight,
take_fees,
payment,
Default::default(),
);
let raw_payload = SignedPayload::from_raw(
Expand Down
1 change: 1 addition & 0 deletions node/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ test-client = { package = "substrate-test-client", path = "../../core/test-clien
sr-primitives = { path = "../../core/sr-primitives" }
runtime_support = { package = "srml-support", path = "../../srml/support" }
balances = { package = "srml-balances", path = "../../srml/balances" }
transaction-payment = { package = "srml-transaction-payment", path = "../../srml/transaction-payment" }
session = { package = "srml-session", path = "../../srml/session" }
system = { package = "srml-system", path = "../../srml/system" }
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp" }
Expand Down
2 changes: 1 addition & 1 deletion node/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mod tests {
// NOTE: this is really hard to apply, since the multiplier of each block needs to be fetched
// before the block, while we compute this after the block.
// weight = <system::Module<Runtime>>::next_weight_multiplier().apply_to(weight);
let weight_fee = <Runtime as balances::Trait>::WeightToFee::convert(weight);
let weight_fee = <Runtime as transaction_payment::Trait>::WeightToFee::convert(weight);
length_fee + weight_fee + TransferFee::get()
}

Expand Down
2 changes: 2 additions & 0 deletions node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ system = { package = "srml-system", path = "../../srml/system", default-features
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp", default-features = false }
treasury = { package = "srml-treasury", path = "../../srml/treasury", default-features = false }
utility = { package = "srml-utility", path = "../../srml/utility", default-features = false }
transaction-payment = { package = "srml-transaction-payment", path = "../../srml/transaction-payment", default-features = false }

[build-dependencies]
wasm-builder-runner = { package = "substrate-wasm-builder-runner", version = "1.0.2", path = "../../core/utils/wasm-builder-runner" }
Expand Down Expand Up @@ -96,5 +97,6 @@ std = [
"timestamp/std",
"treasury/std",
"utility/std",
"transaction-payment/std",
"version/std",
]
2 changes: 1 addition & 1 deletion node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ mod tests {
if wm == next { break; }
wm = next;
iterations += 1;
let fee = <Runtime as balances::Trait>::WeightToFee::convert(wm.apply_to(tx_weight));
let fee = <Runtime as transaction_payment::Trait>::WeightToFee::convert(wm.apply_to(tx_weight));
println!(
"iteration {}, new wm = {:?}. Fee at this point is: {} millicents, {} cents, {} dollars",
iterations,
Expand Down
18 changes: 13 additions & 5 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,24 +161,32 @@ parameter_types! {
pub const ExistentialDeposit: Balance = 1 * DOLLARS;
pub const TransferFee: Balance = 1 * CENTS;
pub const CreationFee: Balance = 1 * CENTS;
pub const TransactionBaseFee: Balance = 1 * CENTS;
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
}

impl balances::Trait for Runtime {
type Balance = Balance;
type OnFreeBalanceZero = ((Staking, Contracts), Session);
type OnNewAccount = Indices;
type Event = Event;
type TransactionPayment = DealWithFees;
type DustRemoval = ();
type TransferPayment = ();
type ExistentialDeposit = ExistentialDeposit;
type TransferFee = TransferFee;
type CreationFee = CreationFee;
}

parameter_types! {
pub const TransactionBaseFee: Balance = 1 * CENTS;
pub const TransactionByteFee: Balance = 10 * MILLICENTS;
}

impl transaction_payment::Trait for Runtime {
type Currency = Balances;
type OnTransactionPayment = DealWithFees;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = WeightToFee;
type FeeMultiplierUpdate = ();
}

parameter_types! {
Expand Down Expand Up @@ -480,7 +488,7 @@ impl system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for Runtim
system::CheckEra::<Runtime>::from(generic::Era::mortal(period, current_block)),
system::CheckNonce::<Runtime>::from(index),
system::CheckWeight::<Runtime>::new(),
balances::TakeFees::<Runtime>::from(tip),
transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
Default::default(),
);
let raw_payload = SignedPayload::new(call, extra).ok()?;
Expand Down Expand Up @@ -540,7 +548,7 @@ pub type SignedExtra = (
system::CheckEra<Runtime>,
system::CheckNonce<Runtime>,
system::CheckWeight<Runtime>,
balances::TakeFees<Runtime>,
transaction_payment::ChargeTransactionPayment<Runtime>,
contracts::CheckBlockGasLimit<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
Expand Down
1 change: 1 addition & 0 deletions node/testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ system = { package = "srml-system", path = "../../srml/system" }
test-client = { package = "substrate-test-client", path = "../../core/test-client" }
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp" }
treasury = { package = "srml-treasury", path = "../../srml/treasury" }
transaction-payment = { package = "srml-transaction-payment", path = "../../srml/transaction-payment" }
wabt = "0.9.2"
2 changes: 1 addition & 1 deletion node/testing/src/keyring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn signed_extra(nonce: Index, extra_fee: Balance) -> SignedExtra {
system::CheckEra::from(Era::mortal(256, 0)),
system::CheckNonce::from(nonce),
system::CheckWeight::new(),
balances::TakeFees::from(extra_fee),
transaction_payment::ChargeTransactionPayment::from(extra_fee),
Default::default(),
)
}
Expand Down
1 change: 1 addition & 0 deletions srml/balances/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ system = { package = "srml-system", path = "../system", default-features = false
[dev-dependencies]
runtime-io = { package = "sr-io", path = "../../core/sr-io" }
primitives = { package = "substrate-primitives", path = "../../core/primitives" }
transaction-payment = { package = "srml-transaction-payment", path = "../transaction-payment" }

[features]
default = ["std"]
Expand Down
Loading