Fungibles trait and impl for Assets pallet (#8425)

* Fungibles trait and impl for Assets pallet

* Comment & whitespace

* Fixes

* Fix up CI/CD for the new labels.

* New labels.

* Fix labels

* Fix labels

* Whitespace

* Bump impl version.

* Fix accidental change

* Fixes

* Questionable fix.

* Better benchmark
This commit is contained in:
Gavin Wood
2021-03-23 14:10:36 +01:00
committed by GitHub
parent 956262a182
commit b5b0ef592e
5 changed files with 192 additions and 107 deletions
+16
View File
@@ -1128,6 +1128,22 @@ pub trait Currency<AccountId> {
) -> SignedImbalance<Self::Balance, Self::PositiveImbalance>;
}
/// Trait for providing an ERC-20 style set of named fungible assets.
pub trait Fungibles<AccountId> {
/// Means of identifying one asset class from another.
type AssetId: FullCodec + Copy + Default;
/// Scalar type for storing balance of an account.
type Balance: AtLeast32BitUnsigned + FullCodec + Copy + Default;
/// Get the `asset` balance of `who`.
fn balance(asset: Self::AssetId, who: &AccountId) -> Self::Balance;
/// Returns `true` if the `asset` balance of `who` may be increased by `amount`.
fn can_deposit(asset: Self::AssetId, who: &AccountId, amount: Self::Balance) -> bool;
/// Increase the `asset` balance of `who` by `amount`.
fn deposit(asset: Self::AssetId, who: AccountId, amount: Self::Balance) -> DispatchResult;
/// Attempt to reduce the `asset` balance of `who` by `amount`.
fn withdraw(asset: Self::AssetId, who: AccountId, amount: Self::Balance) -> DispatchResult;
}
/// Status of funds.
#[derive(PartialEq, Eq, Clone, Copy, Encode, Decode, RuntimeDebug)]
pub enum BalanceStatus {