mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 13:31:10 +00:00
Transaction Fee Module (#1648)
* wip * Split bytes fee charging and charging by amount into different traits. * Move to edition 2018. * Implemented charge fee traits for fees module. * Implemented 'on_finalise' for fee module. * Updated fees finalize impl. * Renaming and documentation update. * Added overflow & underflow check for fee calculation. * Added mock and unit tests for fee module. * More unit tests for fees module. * Fixed srml-executive unit tests. * Remove transaction base/bytes fee from balances module, fix unit tests. * fix compile error * Fixed unit test. * Minor fixes. * Bump spec version. * Bump spec version. * Updated fees module and runtime wasm. * Fees module code style improvement; updated runtime wasm. * Bump spec and impl version.
This commit is contained in:
committed by
Bastian Köcher
parent
6a6c3155a6
commit
fafffdb771
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user