mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 16:17:59 +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:
@@ -61,14 +61,12 @@ pub trait Inspect<AccountId> {
|
||||
|
||||
/// Interface for enumerating assets in existence or owned by a given account over a collection
|
||||
/// of NFTs.
|
||||
///
|
||||
/// WARNING: These may be a heavy operations. Do not use when execution time is limited.
|
||||
pub trait InspectEnumerable<AccountId>: Inspect<AccountId> {
|
||||
/// Returns the instances of an asset `class` in existence.
|
||||
fn instances() -> Vec<Self::InstanceId>;
|
||||
/// Returns an iterator of the instances of an asset `class` in existence.
|
||||
fn instances() -> Box<dyn Iterator<Item = Self::InstanceId>>;
|
||||
|
||||
/// Returns the asset instances of all classes owned by `who`.
|
||||
fn owned(who: &AccountId) -> Vec<Self::InstanceId>;
|
||||
/// Returns an iterator of the asset instances of all classes owned by `who`.
|
||||
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = Self::InstanceId>>;
|
||||
}
|
||||
|
||||
/// Trait for providing an interface for NFT-like assets which may be minted, burned and/or have
|
||||
@@ -148,10 +146,10 @@ impl<
|
||||
A: Get<<F as nonfungibles::Inspect<AccountId>>::ClassId>,
|
||||
AccountId,
|
||||
> InspectEnumerable<AccountId> for ItemOf<F, A, AccountId> {
|
||||
fn instances() -> Vec<Self::InstanceId> {
|
||||
fn instances() -> Box<dyn Iterator<Item = Self::InstanceId>> {
|
||||
<F as nonfungibles::InspectEnumerable<AccountId>>::instances(&A::get())
|
||||
}
|
||||
fn owned(who: &AccountId) -> Vec<Self::InstanceId> {
|
||||
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = Self::InstanceId>> {
|
||||
<F as nonfungibles::InspectEnumerable<AccountId>>::owned_in_class(&A::get(), who)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,20 +95,18 @@ pub trait Inspect<AccountId> {
|
||||
|
||||
/// Interface for enumerating assets in existence or owned by a given account over many collections
|
||||
/// of NFTs.
|
||||
///
|
||||
/// WARNING: These may be a heavy operations. Do not use when execution time is limited.
|
||||
pub trait InspectEnumerable<AccountId>: Inspect<AccountId> {
|
||||
/// Returns the asset classes in existence.
|
||||
fn classes() -> Vec<Self::ClassId>;
|
||||
/// Returns an iterator of the asset classes in existence.
|
||||
fn classes() -> Box<dyn Iterator<Item = Self::ClassId>>;
|
||||
|
||||
/// Returns the instances of an asset `class` in existence.
|
||||
fn instances(class: &Self::ClassId) -> Vec<Self::InstanceId>;
|
||||
/// Returns an iterator of the instances of an asset `class` in existence.
|
||||
fn instances(class: &Self::ClassId) -> Box<dyn Iterator<Item = Self::InstanceId>>;
|
||||
|
||||
/// Returns the asset instances of all classes owned by `who`.
|
||||
fn owned(who: &AccountId) -> Vec<(Self::ClassId, Self::InstanceId)>;
|
||||
/// Returns an iterator of the asset instances of all classes owned by `who`.
|
||||
fn owned(who: &AccountId) -> Box<dyn Iterator<Item = (Self::ClassId, Self::InstanceId)>>;
|
||||
|
||||
/// Returns the asset instances of `class` owned by `who`.
|
||||
fn owned_in_class(class: &Self::ClassId, who: &AccountId) -> Vec<Self::InstanceId>;
|
||||
/// Returns an iterator of the asset instances of `class` owned by `who`.
|
||||
fn owned_in_class(class: &Self::ClassId, who: &AccountId) -> Box<dyn Iterator<Item = Self::InstanceId>>;
|
||||
}
|
||||
|
||||
/// Trait for providing an interface for multiple classes of NFT-like assets which may be minted,
|
||||
|
||||
Reference in New Issue
Block a user