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 1 commit
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
Prev Previous commit
Next Next commit
Renaming and documentation update.
  • Loading branch information
shaunxw committed Feb 6, 2019
commit d9b951a1c92b0bab408017e60d55937e0e8a567c
18 changes: 9 additions & 9 deletions core/sr-primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub trait BlockNumberToHash {
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, len: usize) -> Result<(), &'static str>;
fn charge_base_bytes_fee(transactor: &AccountId, encoded_len: usize) -> Result<(), &'static str>;
}

/// Charge fee trait
Expand All @@ -139,7 +139,7 @@ pub trait ChargeFee<AccountId>: ChargeBytesFee<AccountId> {
/// 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`.
/// 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>;
}

Expand All @@ -148,14 +148,14 @@ pub trait TransferAsset<AccountId> {
/// The type of asset amount.
type Amount;

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

/// Transfer asset from `who` account by deducing `amount` in the account balances
fn transfer_from(who: &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>;

/// Transfer asset to `who` account by incresing `amount` in the account balances
fn transfer_to(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 () {
Expand All @@ -173,8 +173,8 @@ impl<T> TransferAsset<T> for () {
type Amount = ();

fn transfer(_: &T, _: &T, _: Self::Amount) -> Result<(), &'static str> { Ok(()) }
fn transfer_from(_: &T, _: Self::Amount) -> Result<(), &'static str> { Ok(()) }
fn transfer_to(_: &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
4 changes: 2 additions & 2 deletions srml/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ impl<T: Trait> TransferAsset<T::AccountId> for Module<T> {
Self::make_transfer(from, to, amount)
}

fn transfer_from(who: &T::AccountId, value: T::Balance) -> Result {
fn remove_from(who: &T::AccountId, value: T::Balance) -> Result {
T::EnsureAccountLiquid::ensure_account_liquid(who)?;
let b = Self::free_balance(who);
if b < value {
Expand All @@ -552,7 +552,7 @@ impl<T: Trait> TransferAsset<T::AccountId> for Module<T> {
Ok(())
}

fn transfer_to(who: &T::AccountId, value: T::Balance) -> Result {
fn add_to(who: &T::AccountId, value: T::Balance) -> Result {
Self::set_free_balance_creating(who, Self::free_balance(who) + value);
Self::increase_total_stake_by(value);
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions srml/fees/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<T: Trait> ChargeFee<T::AccountId> for Module<T> {
type Amount = T::Amount;

fn charge_fee(transactor: &T::AccountId, amount: T::Amount) -> Result {
T::TransferAsset::transfer_from(transactor, amount).and_then(|_| {
T::TransferAsset::remove_from(transactor, amount).and_then(|_| {
match <system::Module<T>>::extrinsic_index() {
Some(extrinsic_index) => {
let current_fee = Self::current_transaction_fee(extrinsic_index);
Expand All @@ -103,7 +103,7 @@ impl<T: Trait> ChargeFee<T::AccountId> for Module<T> {
}

fn refund_fee(transactor: &T::AccountId, amount: T::Amount) -> Result {
T::TransferAsset::transfer_to(transactor, amount).and_then(|_| {
T::TransferAsset::add_to(transactor, amount).and_then(|_| {
match <system::Module<T>>::extrinsic_index() {
Some(extrinsic_index) => {
let current_fee = Self::current_transaction_fee(extrinsic_index);
Expand Down