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

Implement InspectEnumerable for Uniques #9117

Merged
6 commits merged into from
Jul 1, 2021
Merged
Changes from 1 commit
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
24 changes: 23 additions & 1 deletion frame/uniques/src/impl_nonfungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -106,3 +106,25 @@ 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 the asset classes in existence.
fn classes() -> Vec<Self::ClassId> {
ClassMetadataOf::<T, I>::iter().map(|(k, _v)| k).collect()
}

/// Returns the instances of an asset `class` in existence.
fn instances(class: &Self::ClassId) -> Vec<Self::InstanceId> {
InstanceMetadataOf::<T, I>::iter_prefix(class).map(|(i, _v)| i).collect()
}
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved

/// Returns the asset instances of all classes owned by `who`.
fn owned(who: &T::AccountId) -> Vec<(Self::ClassId, Self::InstanceId)> {
Account::<T, I>::iter_prefix((who,)).map(|(p, _v)| p).collect()
}

/// Returns the asset instances of `class` owned by `who`.
fn owned_in_class(class: &Self::ClassId, who: &T::AccountId) -> Vec<Self::InstanceId> {
Account::<T, I>::iter_prefix((who, class)).map(|(i, _v)| i).collect()
}
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
}