Skip to content

Commit

Permalink
update refund trait
Browse files Browse the repository at this point in the history
  • Loading branch information
muharem committed Apr 15, 2024
1 parent ab196b6 commit 290c0f1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 20 deletions.
2 changes: 0 additions & 2 deletions substrate/frame/assets/src/impl_fungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,6 @@ impl<T: Config<I>, I: 'static> fungibles::InspectEnumerable<T::AccountId> for Pa
}

impl<T: Config<I>, I: 'static> fungibles::Refund<T::AccountId> for Pallet<T, I> {
type AssetId = T::AssetId;
type Balance = DepositBalanceOf<T, I>;
fn deposit_held(id: Self::AssetId, who: T::AccountId) -> Option<(T::AccountId, Self::Balance)> {
use ExistenceReason::*;
match Account::<T, I>::get(&id, &who).ok_or(Error::<T, I>::NoDeposit).ok()?.reason {
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ pub mod pallet {

/// The currency mechanism.
#[pallet::no_default]
type Currency: ReservableCurrency<Self::AccountId>;
type Currency: ReservableCurrency<Self::AccountId, Balance = Self::Balance>;

/// Standard asset class creation is only allowed if the origin attempting it and the
/// asset class are in this set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -928,15 +928,12 @@ impl<

impl<
Left: fungible::Inspect<AccountId>,
Right: fungibles::Inspect<AccountId> + fungibles::Refund<AccountId>,
Criterion: Convert<AssetKind, Either<(), <Right as fungibles::Refund<AccountId>>::AssetId>>,
Right: fungibles::Inspect<AccountId, Balance = Left::Balance> + fungibles::Refund<AccountId>,
Criterion: Convert<AssetKind, Either<(), <Right as fungibles::Inspect<AccountId>>::AssetId>>,
AssetKind: AssetId,
AccountId,
> fungibles::Refund<AccountId> for UnionOf<Left, Right, Criterion, AssetKind, AccountId>
{
type AssetId = AssetKind;
type Balance = <Right as fungibles::Refund<AccountId>>::Balance;

fn deposit_held(asset: AssetKind, who: AccountId) -> Option<(AccountId, Self::Balance)> {
match Criterion::convert(asset) {
Left(()) => None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ pub trait Create<AccountId>: Inspect<AccountId> {
}

/// Trait for refunding the deposit of a target asset account.
pub trait Refund<AccountId> {
/// Means of identifying one asset class from another.
type AssetId: AssetId;
/// Scalar type for representing balance of an account.
type Balance: Balance;
pub trait Refund<AccountId>: Inspect<AccountId> {
/// Returns the amount of account deposit and depositor address, if any.
fn deposit_held(id: Self::AssetId, who: AccountId) -> Option<(AccountId, Self::Balance)>;
/// Return the deposit (if any) of a target asset account.
Expand Down
10 changes: 3 additions & 7 deletions substrate/frame/support/src/traits/tokens/fungibles/union_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,22 +907,18 @@ impl<

impl<
Left: fungibles::Inspect<AccountId> + fungibles::Refund<AccountId>,
Right: fungibles::Inspect<AccountId>
+ fungibles::Refund<AccountId, Balance = <Left as fungibles::Refund<AccountId>>::Balance>,
Right: fungibles::Inspect<AccountId, Balance = Left::Balance> + fungibles::Refund<AccountId>,
Criterion: Convert<
AssetKind,
Either<
<Left as fungibles::Refund<AccountId>>::AssetId,
<Right as fungibles::Refund<AccountId>>::AssetId,
<Left as fungibles::Inspect<AccountId>>::AssetId,
<Right as fungibles::Inspect<AccountId>>::AssetId,
>,
>,
AssetKind: AssetId,
AccountId,
> fungibles::Refund<AccountId> for UnionOf<Left, Right, Criterion, AssetKind, AccountId>
{
type AssetId = AssetKind;
type Balance = <Left as fungibles::Refund<AccountId>>::Balance;

fn deposit_held(asset: AssetKind, who: AccountId) -> Option<(AccountId, Self::Balance)> {
match Criterion::convert(asset) {
Left(a) => <Left as fungibles::Refund<AccountId>>::deposit_held(a, who),
Expand Down

0 comments on commit 290c0f1

Please sign in to comment.