mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +00:00
Split fees and tips between author and treasury independently (#5207)
* Split fees and tips between author and treasury independently * Docs and cleanup * Fix test
This commit is contained in:
@@ -24,7 +24,7 @@ use sp_std::prelude::*;
|
||||
use frame_support::{
|
||||
construct_runtime, parameter_types, debug,
|
||||
weights::Weight,
|
||||
traits::{SplitTwoWays, Currency, Randomness},
|
||||
traits::{Currency, Randomness, OnUnbalanced, Imbalance},
|
||||
};
|
||||
use sp_core::u32_trait::{_1, _2, _3, _4};
|
||||
pub use node_primitives::{AccountId, Signature};
|
||||
@@ -98,12 +98,21 @@ pub fn native_version() -> NativeVersion {
|
||||
|
||||
type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
|
||||
|
||||
pub type DealWithFees = SplitTwoWays<
|
||||
Balance,
|
||||
NegativeImbalance,
|
||||
_4, Treasury, // 4 parts (80%) goes to the treasury.
|
||||
_1, Author, // 1 part (20%) goes to the block author.
|
||||
>;
|
||||
pub struct DealWithFees;
|
||||
impl OnUnbalanced<NegativeImbalance> for DealWithFees {
|
||||
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item=NegativeImbalance>) {
|
||||
if let Some(fees) = fees_then_tips.next() {
|
||||
// for fees, 80% to treasury, 20% to author
|
||||
let mut split = fees.ration(80, 20);
|
||||
if let Some(tips) = fees_then_tips.next() {
|
||||
// for tips, if any, 80% to treasury, 20% to author (though this can be anything)
|
||||
tips.ration_merge_into(80, 20, &mut split);
|
||||
}
|
||||
Treasury::on_unbalanced(split.0);
|
||||
Author::on_unbalanced(split.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: BlockNumber = 250;
|
||||
|
||||
Reference in New Issue
Block a user