Skip to content

Commit

Permalink
Add dummy impls of fungible and fungibles trait families (parityt…
Browse files Browse the repository at this point in the history
…ech#2695)

In `Currency`, we have a dummy impl that we can use for mocks or
examples where we only want to satisfy the trait bounds. I added the
same dummy implementations to `fungible` and `fungibles` regular traits.

---------

Co-authored-by: command-bot <>
  • Loading branch information
franciscoaguirre committed Dec 14, 2023
1 parent eecacd5 commit c896c76
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
44 changes: 44 additions & 0 deletions substrate/frame/support/src/traits/tokens/fungible/regular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,47 @@ pub trait Balanced<AccountId>: Inspect<AccountId> + Unbalanced<AccountId> {
fn done_deposit(_who: &AccountId, _amount: Self::Balance) {}
fn done_withdraw(_who: &AccountId, _amount: Self::Balance) {}
}

/// Dummy implementation of [`Inspect`]
#[cfg(feature = "std")]
impl<AccountId> Inspect<AccountId> for () {
type Balance = u32;
fn total_issuance() -> Self::Balance {
0
}
fn minimum_balance() -> Self::Balance {
0
}
fn total_balance(_: &AccountId) -> Self::Balance {
0
}
fn balance(_: &AccountId) -> Self::Balance {
0
}
fn reducible_balance(_: &AccountId, _: Preservation, _: Fortitude) -> Self::Balance {
0
}
fn can_deposit(_: &AccountId, _: Self::Balance, _: Provenance) -> DepositConsequence {
DepositConsequence::Success
}
fn can_withdraw(_: &AccountId, _: Self::Balance) -> WithdrawConsequence<Self::Balance> {
WithdrawConsequence::Success
}
}

/// Dummy implementation of [`Unbalanced`]
#[cfg(feature = "std")]
impl<AccountId> Unbalanced<AccountId> for () {
fn handle_dust(_: Dust<AccountId, Self>) {}
fn write_balance(
_: &AccountId,
_: Self::Balance,
) -> Result<Option<Self::Balance>, DispatchError> {
Ok(None)
}
fn set_total_issuance(_: Self::Balance) {}
}

/// Dummy implementation of [`Mutate`]
#[cfg(feature = "std")]
impl<AccountId: Eq> Mutate<AccountId> for () {}
63 changes: 63 additions & 0 deletions substrate/frame/support/src/traits/tokens/fungibles/regular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,3 +593,66 @@ pub trait Balanced<AccountId>: Inspect<AccountId> + Unbalanced<AccountId> {
fn done_deposit(_asset: Self::AssetId, _who: &AccountId, _amount: Self::Balance) {}
fn done_withdraw(_asset: Self::AssetId, _who: &AccountId, _amount: Self::Balance) {}
}

/// Dummy implementation of [`Inspect`]
#[cfg(feature = "std")]
impl<AccountId> Inspect<AccountId> for () {
type AssetId = u32;
type Balance = u32;
fn total_issuance(_: Self::AssetId) -> Self::Balance {
0
}
fn minimum_balance(_: Self::AssetId) -> Self::Balance {
0
}
fn total_balance(_: Self::AssetId, _: &AccountId) -> Self::Balance {
0
}
fn balance(_: Self::AssetId, _: &AccountId) -> Self::Balance {
0
}
fn reducible_balance(
_: Self::AssetId,
_: &AccountId,
_: Preservation,
_: Fortitude,
) -> Self::Balance {
0
}
fn can_deposit(
_: Self::AssetId,
_: &AccountId,
_: Self::Balance,
_: Provenance,
) -> DepositConsequence {
DepositConsequence::Success
}
fn can_withdraw(
_: Self::AssetId,
_: &AccountId,
_: Self::Balance,
) -> WithdrawConsequence<Self::Balance> {
WithdrawConsequence::Success
}
fn asset_exists(_: Self::AssetId) -> bool {
false
}
}

/// Dummy implementation of [`Unbalanced`]
#[cfg(feature = "std")]
impl<AccountId> Unbalanced<AccountId> for () {
fn handle_dust(_: Dust<AccountId, Self>) {}
fn write_balance(
_: Self::AssetId,
_: &AccountId,
_: Self::Balance,
) -> Result<Option<Self::Balance>, DispatchError> {
Ok(None)
}
fn set_total_issuance(_: Self::AssetId, _: Self::Balance) {}
}

/// Dummy implementation of [`Mutate`]
#[cfg(feature = "std")]
impl<AccountId: Eq> Mutate<AccountId> for () {}

0 comments on commit c896c76

Please sign in to comment.