mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 23:07:57 +00:00
Balance to Asset Balance Conversion (#9076)
* add BalanceConversion trait and implementation * derive some useful traits on Imbalance * Update frame/support/src/traits/tokens/fungibles/imbalance.rs Co-authored-by: Xiliang Chen <xlchen1291@gmail.com> * make BalanceConversion error type configurable * add RuntimeDebug import and derive traits on other Imbalance * formatting * move BalanceConversion trait to frame-support * add necessary trait import Co-authored-by: Xiliang Chen <xlchen1291@gmail.com>
This commit is contained in:
@@ -25,6 +25,7 @@ pub mod nonfungible;
|
||||
pub mod nonfungibles;
|
||||
mod misc;
|
||||
pub use misc::{
|
||||
WithdrawConsequence, DepositConsequence, ExistenceRequirement, BalanceStatus, WithdrawReasons,
|
||||
BalanceConversion, BalanceStatus, DepositConsequence,
|
||||
ExistenceRequirement, WithdrawConsequence, WithdrawReasons,
|
||||
};
|
||||
pub use imbalance::Imbalance;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
use super::*;
|
||||
use sp_std::marker::PhantomData;
|
||||
use sp_runtime::traits::Zero;
|
||||
use sp_runtime::{RuntimeDebug, traits::Zero};
|
||||
use super::misc::Balance;
|
||||
use super::balanced::Balanced;
|
||||
use crate::traits::misc::{TryDrop, SameOrOther};
|
||||
@@ -39,6 +39,7 @@ pub trait HandleImbalanceDrop<Balance> {
|
||||
///
|
||||
/// Importantly, it has a special `Drop` impl, and cannot be created outside of this module.
|
||||
#[must_use]
|
||||
#[derive(RuntimeDebug, Eq, PartialEq)]
|
||||
pub struct Imbalance<
|
||||
B: Balance,
|
||||
OnDrop: HandleImbalanceDrop<B>,
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
use super::*;
|
||||
use sp_std::marker::PhantomData;
|
||||
use sp_runtime::traits::Zero;
|
||||
use sp_runtime::{RuntimeDebug, traits::Zero};
|
||||
use super::fungibles::{AssetId, Balance};
|
||||
use super::balanced::Balanced;
|
||||
use crate::traits::misc::{TryDrop, SameOrOther};
|
||||
@@ -37,6 +37,7 @@ pub trait HandleImbalanceDrop<AssetId, Balance> {
|
||||
///
|
||||
/// Importantly, it has a special `Drop` impl, and cannot be created outside of this module.
|
||||
#[must_use]
|
||||
#[derive(RuntimeDebug, Eq, PartialEq)]
|
||||
pub struct Imbalance<
|
||||
A: AssetId,
|
||||
B: Balance,
|
||||
|
||||
@@ -167,3 +167,9 @@ impl<T: FullCodec + Copy + Eq + PartialEq + Debug> AssetId for T {}
|
||||
/// Simple amalgamation trait to collect together properties for a Balance under one roof.
|
||||
pub trait Balance: AtLeast32BitUnsigned + FullCodec + Copy + Default + Debug {}
|
||||
impl<T: AtLeast32BitUnsigned + FullCodec + Copy + Default + Debug> Balance for T {}
|
||||
|
||||
/// Converts a balance value into an asset balance.
|
||||
pub trait BalanceConversion<InBalance, AssetId, OutBalance> {
|
||||
type Error;
|
||||
fn to_asset_balance(balance: InBalance, asset_id: AssetId) -> Result<OutBalance, Self::Error>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user