Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
85a1953
wip
xlc Jan 31, 2019
274801f
Split bytes fee charging and charging by amount into different traits.
shaunxw Jan 31, 2019
eccd12c
Move to edition 2018.
shaunxw Feb 1, 2019
81a3929
Implemented charge fee traits for fees module.
shaunxw Feb 1, 2019
5923d01
Implemented 'on_finalise' for fee module.
shaunxw Feb 4, 2019
dd504f8
Merge branch 'master' into fee
shaunxw Feb 4, 2019
50f2cd5
Updated fees finalize impl.
shaunxw Feb 6, 2019
d9b951a
Renaming and documentation update.
shaunxw Feb 6, 2019
02f6358
Added overflow & underflow check for fee calculation.
shaunxw Feb 7, 2019
25cbd29
Added mock and unit tests for fee module.
shaunxw Feb 7, 2019
13c31be
More unit tests for fees module.
shaunxw Feb 8, 2019
df8d4d1
Fixed srml-executive unit tests.
shaunxw Feb 8, 2019
f4ef7b5
Merge branch 'master' into fee
shaunxw Feb 8, 2019
ba58808
Remove transaction base/bytes fee from balances module, fix unit tests.
shaunxw Feb 9, 2019
b12405a
Merge remote-tracking branch 'upstream/master' into fee
xlc Feb 11, 2019
b23cd67
fix compile error
xlc Feb 11, 2019
544e18c
Merge branch 'fee' of github.com:xlc/substrate into fee
shaunxw Feb 11, 2019
670f431
Fixed unit test.
shaunxw Feb 12, 2019
a9a948a
Minor fixes.
shaunxw Feb 12, 2019
3b9faa4
Bump spec version.
shaunxw Feb 12, 2019
b420972
Merge branch 'master' into fee
shaunxw Feb 12, 2019
857d3dc
Bump spec version.
shaunxw Feb 12, 2019
d84c199
Updated fees module and runtime wasm.
shaunxw Feb 12, 2019
4908fbb
Fees module code style improvement; updated runtime wasm.
shaunxw Feb 13, 2019
a0af48d
Merge branch 'master' into fee
shaunxw Feb 13, 2019
70a14dc
Bump spec and impl version.
shaunxw Feb 13, 2019
4e6c4f8
Merge branch 'master' into fee
shaunxw Feb 13, 2019
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
20 changes: 20 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ members = [
"srml/democracy",
"srml/example",
"srml/executive",
"srml/fees",
"srml/grandpa",
"srml/indices",
"srml/metadata",
Expand Down
56 changes: 49 additions & 7 deletions core/sr-primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,57 @@ pub trait BlockNumberToHash {
}
}

/// Simple payment making trait, operating on a single generic `AccountId` type.
pub trait MakePayment<AccountId> {
/// Make some sort of payment concerning `who` for an extrinsic (transaction) of encoded length
/// `encoded_len` bytes. Return true iff the payment was successful.
fn make_payment(who: &AccountId, encoded_len: usize) -> Result<(), &'static str>;
/// Charge bytes fee trait
pub trait ChargeBytesFee<AccountId> {
/// Charge fees from `transactor` for an extrinsic (transaction) of encoded length
/// `encoded_len` bytes. Return Ok iff the payment was successful.
fn charge_base_bytes_fee(transactor: &AccountId, encoded_len: usize) -> Result<(), &'static str>;
}

impl<T> MakePayment<T> for () {
fn make_payment(_: &T, _: usize) -> Result<(), &'static str> { Ok(()) }
/// Charge fee trait
pub trait ChargeFee<AccountId>: ChargeBytesFee<AccountId> {
/// The type of fee amount.
type Amount;

/// Charge `amount` of fees from `transactor`. Return Ok iff the payment was successful.
fn charge_fee(transactor: &AccountId, amount: Self::Amount) -> Result<(), &'static str>;

/// Refund `amount` of previous charged fees from `transactor`. Return Ok iff the refund was successful.
fn refund_fee(transactor: &AccountId, amount: Self::Amount) -> Result<(), &'static str>;
}

/// Transfer fungible asset trait
pub trait TransferAsset<AccountId> {
/// The type of asset amount.
type Amount;

/// Transfer asset from `from` account to `to` account with `amount` of asset.
fn transfer(from: &AccountId, to: &AccountId, amount: Self::Amount) -> Result<(), &'static str>;

/// Remove asset from `who` account by deducing `amount` in the account balances.
fn remove_from(who: &AccountId, amount: Self::Amount) -> Result<(), &'static str>;

/// Add asset to `who` account by increasing `amount` in the account balances.
fn add_to(who: &AccountId, amount: Self::Amount) -> Result<(), &'static str>;
}

impl<T> ChargeBytesFee<T> for () {
fn charge_base_bytes_fee(_: &T, _: usize) -> Result<(), &'static str> { Ok(()) }
}

impl<T> ChargeFee<T> for () {
type Amount = ();

fn charge_fee(_: &T, _: Self::Amount) -> Result<(), &'static str> { Ok(()) }
fn refund_fee(_: &T, _: Self::Amount) -> Result<(), &'static str> { Ok(()) }
}

impl<T> TransferAsset<T> for () {
type Amount = ();

fn transfer(_: &T, _: &T, _: Self::Amount) -> Result<(), &'static str> { Ok(()) }
fn remove_from(_: &T, _: Self::Amount) -> Result<(), &'static str> { Ok(()) }
fn add_to(_: &T, _: Self::Amount) -> Result<(), &'static str> { Ok(()) }
}

/// Extensible conversion trait. Generic over both source and destination types.
Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions node-template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ version = { package = "sr-version", path = "../../core/sr-version", default_feat
srml-support = { path = "../../srml/support", default_features = false }
primitives = { package = "substrate-primitives", path = "../../core/primitives", default_features = false }
balances = { package = "srml-balances", path = "../../srml/balances", default_features = false }
fees = { package = "srml-fees", path = "../../srml/fees", default_features = false }
consensus = { package = "srml-consensus", path = "../../srml/consensus", default_features = false }
aura = { package = "srml-aura", path = "../../srml/aura", default_features = false }
executive = { package = "srml-executive", path = "../../srml/executive", default_features = false }
indices = { package = "srml-indices", path = "../../srml/indices", default_features = false }
system = { package = "srml-system", path = "../../srml/system", default_features = false }
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp", default_features = false }
sudo = { package = "srml-sudo", path = "../../srml/sudo", default_features = false }
fees = { package = "srml-fees", path = "../../srml/fees", default_features = false }
runtime-primitives = { package = "sr-primitives", path = "../../core/sr-primitives", default_features = false }
substrate-client = { path = "../../core/client", default_features = false }
consensus-aura = { package = "substrate-consensus-aura-primitives", path = "../../core/consensus/aura/primitives", default_features = false }
Expand All @@ -38,13 +40,15 @@ std = [
"runtime-io/std",
"srml-support/std",
"balances/std",
"fees/std",
"executive/std",
"aura/std",
"indices/std",
"primitives/std",
"system/std",
"timestamp/std",
"sudo/std",
"fees/std",
"version/std",
"serde_derive",
"serde/std",
Expand Down
15 changes: 14 additions & 1 deletion node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,24 @@ impl balances::Trait for Runtime {
type Event = Event;
}

impl fees::Trait for Runtime {
type Amount = u128;
type TransferAsset = Balances;
type Event = Event;
}

impl sudo::Trait for Runtime {
/// The uniquitous event type.
type Event = Event;
type Proposal = Call;
}

impl fees::Trait for Runtime {
type Event = Event;
type Amount = u128;
type TransferAsset = balances::Module<Runtime>;
}

construct_runtime!(
pub enum Runtime with Log(InternalLog: DigestItem<Hash, Ed25519AuthorityId>) where
Block = Block,
Expand All @@ -186,6 +198,7 @@ construct_runtime!(
Indices: indices,
Balances: balances,
Sudo: sudo,
Fees: fees::{Module, Storage, Config<T>, Event<T>},
}
);

Expand All @@ -204,7 +217,7 @@ pub type UncheckedExtrinsic = generic::UncheckedMortalCompactExtrinsic<Address,
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, Nonce, Call>;
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<Runtime, Block, Context, Balances, AllModules>;
pub type Executive = executive::Executive<Runtime, Block, Context, Fees, AllModules>;

// Implement our runtime API endpoints. This is just a bunch of proxying.
impl_runtime_apis! {
Expand Down
17 changes: 17 additions & 0 deletions node-template/runtime/wasm/Cargo.lock

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

8 changes: 5 additions & 3 deletions node-template/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use primitives::{Ed25519AuthorityId, ed25519};
use node_template_runtime::{
AccountId, GenesisConfig, ConsensusConfig, TimestampConfig, BalancesConfig,
SudoConfig, IndicesConfig
SudoConfig, IndicesConfig, FeesConfig,
};
use substrate_service;

Expand Down Expand Up @@ -90,8 +90,6 @@ fn testnet_genesis(initial_authorities: Vec<Ed25519AuthorityId>, endowed_account
ids: endowed_accounts.clone(),
}),
balances: Some(BalancesConfig {
transaction_base_fee: 1,
transaction_byte_fee: 0,
existential_deposit: 500,
transfer_fee: 0,
creation_fee: 0,
Expand All @@ -101,5 +99,9 @@ fn testnet_genesis(initial_authorities: Vec<Ed25519AuthorityId>, endowed_account
sudo: Some(SudoConfig {
key: root_key,
}),
fees: Some(FeesConfig {
transaction_base_fee: 1,
transaction_byte_fee: 0,
})
}
}
18 changes: 11 additions & 7 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use primitives::{Ed25519AuthorityId, ed25519};
use node_primitives::AccountId;
use node_runtime::{ConsensusConfig, CouncilSeatsConfig, CouncilVotingConfig, DemocracyConfig,
SessionConfig, StakingConfig, TimestampConfig, BalancesConfig, TreasuryConfig,
SudoConfig, ContractConfig, GrandpaConfig, IndicesConfig, Permill, Perbill};
SudoConfig, ContractConfig, GrandpaConfig, IndicesConfig, FeesConfig, Permill, Perbill};
pub use node_runtime::GenesisConfig;
use substrate_service;
use hex_literal::{hex, hex_impl};
Expand Down Expand Up @@ -64,8 +64,6 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
system: None,
balances: Some(BalancesConfig {
balances: endowed_accounts.iter().map(|&k| (k, 10_000_000 * DOLLARS)).collect(),
transaction_base_fee: 1 * CENTS,
transaction_byte_fee: 10 * MILLICENTS,
existential_deposit: 1 * DOLLARS,
transfer_fee: 1 * CENTS,
creation_fee: 1 * CENTS,
Expand Down Expand Up @@ -139,7 +137,11 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
}),
grandpa: Some(GrandpaConfig {
authorities: initial_authorities.clone().into_iter().map(|k| (k, 1)).collect(),
})
}),
fees: Some(FeesConfig {
transaction_base_fee: 1 * CENTS,
transaction_byte_fee: 10 * MILLICENTS,
}),
}
}

Expand Down Expand Up @@ -192,8 +194,6 @@ pub fn testnet_genesis(
ids: endowed_accounts.iter().map(|x| x.0.into()).collect(),
}),
balances: Some(BalancesConfig {
transaction_base_fee: 1,
transaction_byte_fee: 0,
existential_deposit: 500,
transfer_fee: 0,
creation_fee: 0,
Expand Down Expand Up @@ -267,7 +267,11 @@ pub fn testnet_genesis(
}),
grandpa: Some(GrandpaConfig {
authorities: initial_authorities.clone().into_iter().map(|k| (k, 1)).collect(),
})
}),
fees: Some(FeesConfig {
transaction_base_fee: 1,
transaction_byte_fee: 0,
}),
}
}

Expand Down
1 change: 1 addition & 0 deletions node/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ treasury = { package = "srml-treasury", path = "../../srml/treasury" }
contract = { package = "srml-contract", path = "../../srml/contract" }
grandpa = { package = "srml-grandpa", path = "../../srml/grandpa" }
indices = { package = "srml-indices", path = "../../srml/indices" }
fees = { package = "srml-fees", path = "../../srml/fees" }
wabt = "~0.7.4"

[features]
Expand Down
Loading