mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 06:08:00 +00:00
Implement InspectEnumerable for Uniques (#9117)
* implement InspectEnumerable in pallet_uniques * use `iter_keys` and `iter_key_prefix` * return an iterator instead of constructing a vec * update comments * additional warning about storage reads Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
use super::*;
|
||||
use sp_std::convert::TryFrom;
|
||||
use frame_support::traits::tokens::nonfungibles::{Inspect, Mutate, Transfer};
|
||||
use frame_support::traits::tokens::nonfungibles::{Inspect, InspectEnumerable, Mutate, Transfer};
|
||||
use frame_support::BoundedSlice;
|
||||
use sp_runtime::DispatchResult;
|
||||
|
||||
@@ -106,3 +106,33 @@ impl<T: Config<I>, I: 'static> Transfer<T::AccountId> for Pallet<T, I> {
|
||||
Self::do_transfer(class.clone(), instance.clone(), destination.clone(), |_, _| Ok(()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: 'static> InspectEnumerable<T::AccountId> for Pallet<T, I> {
|
||||
/// Returns an iterator of the asset classes in existence.
|
||||
///
|
||||
/// NOTE: iterating this list invokes a storage read per item.
|
||||
fn classes() -> Box<dyn Iterator<Item = Self::ClassId>> {
|
||||
Box::new(ClassMetadataOf::<T, I>::iter_keys())
|
||||
}
|
||||
|
||||
/// Returns an iterator of the instances of an asset `class` in existence.
|
||||
///
|
||||
/// NOTE: iterating this list invokes a storage read per item.
|
||||
fn instances(class: &Self::ClassId) -> Box<dyn Iterator<Item = Self::InstanceId>> {
|
||||
Box::new(InstanceMetadataOf::<T, I>::iter_key_prefix(class))
|
||||
}
|
||||
|
||||
/// Returns an iterator of the asset instances of all classes owned by `who`.
|
||||
///
|
||||
/// NOTE: iterating this list invokes a storage read per item.
|
||||
fn owned(who: &T::AccountId) -> Box<dyn Iterator<Item = (Self::ClassId, Self::InstanceId)>> {
|
||||
Box::new(Account::<T, I>::iter_key_prefix((who,)))
|
||||
}
|
||||
|
||||
/// Returns an iterator of the asset instances of `class` owned by `who`.
|
||||
///
|
||||
/// NOTE: iterating this list invokes a storage read per item.
|
||||
fn owned_in_class(class: &Self::ClassId, who: &T::AccountId) -> Box<dyn Iterator<Item = Self::InstanceId>> {
|
||||
Box::new(Account::<T, I>::iter_key_prefix((who, class)))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user