Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Assets: impl ContainsPair for asset and account IDs #14119

Merged
merged 2 commits into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ impl<AssetId, AccountId> AssetsCallback<AssetId, AccountId> for () {}
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::{pallet_prelude::*, traits::AccountTouch};
use frame_support::{
pallet_prelude::*,
traits::{AccountTouch, ContainsPair},
};
use frame_system::pallet_prelude::*;

/// The current storage version.
Expand Down Expand Up @@ -1645,7 +1648,7 @@ pub mod pallet {
}
}

/// Implements [AccountTouch] trait.
/// Implements [`AccountTouch`] trait.
/// Note that a depositor can be any account, without any specific privilege.
/// This implementation is supposed to be used only for creation of system accounts.
impl<T: Config<I>, I: 'static> AccountTouch<T::AssetId, T::AccountId> for Pallet<T, I> {
Expand All @@ -1659,6 +1662,14 @@ pub mod pallet {
Self::do_touch(asset, who, depositor, false)
}
}

/// Implements [`ContainsPair`] trait for a pair of asset and account IDs.
impl<T: Config<I>, I: 'static> ContainsPair<T::AssetId, T::AccountId> for Pallet<T, I> {
/// Check if an account with the given asset ID and account address exists.
fn contains(asset: &T::AssetId, who: &T::AccountId) -> bool {
Account::<T, I>::contains_key(asset, who)
}
}
}

sp_core::generate_feature_enabled_macro!(runtime_benchmarks_enabled, feature = "runtime-benchmarks", $);