Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nftsByOwner getter #48

Closed
ilionic opened this issue Jan 11, 2022 · 5 comments
Closed

fix nftsByOwner getter #48

ilionic opened this issue Jan 11, 2022 · 5 comments
Labels
bug Something isn't working
Milestone

Comments

@ilionic
Copy link
Contributor

ilionic commented Jan 11, 2022

After merging #31 nftsByOwner requires rework. Currently not reflecting correctly

@ilionic ilionic added the bug Something isn't working label Jan 11, 2022
@HashWarlock
Copy link
Contributor

Currently NftsByOwner is a StorageMap with a key of AccountId mapped to Vec<CollectionId, NftId>. We could use a StorageNMap similar to how uniques pallet handles their assets owned by an account:
Account

#[pallet::storage]
/// The assets held by any given account; set out this way so that assets owned by a single
/// account can be enumerated.
pub(super) type Account<T: Config<I>, I: 'static = ()> = StorageNMap<
	_,
	(
		NMapKey<Blake2_128Concat, T::AccountId>, // owner
		NMapKey<Blake2_128Concat, T::ClassId>,
		NMapKey<Blake2_128Concat, T::InstanceId>,
	),
	(),
	OptionQuery,
>;

remove & insert from the StorageNMap

Account::<T, I>::remove((&details.owner, &class, &instance));
Account::<T, I>::insert((&dest, &class, &instance), ());

owned

/// 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,)))
}

owned_in_class

/// 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)))
}

@h4x3rotab
Copy link
Contributor

h4x3rotab commented Jan 14, 2022

Given there's already a reverse index available in uniques, I suggest to just keep using the upstream's. Very clever design: there's no Vec<>, and therefore the performance problem was walked around.

@ilionic ilionic added this to the rmrk-core milestone Jan 18, 2022
@ilionic ilionic moved this to Todo in rmrk-substrate Jan 18, 2022
@bmacer
Copy link
Contributor

bmacer commented Mar 17, 2022

@h4x3rotab what is this reverse indexing available in uniques?

@h4x3rotab
Copy link
Contributor

@h4x3rotab what is this reverse indexing available in uniques?

This one. You can go through all the NFTs root-owned by its owner:

https://github.com/paritytech/substrate/blob/57bf92e42c2ca7f3444567b5ce50d2744fe90b4d/frame/uniques/src/lib.rs#L136

@bmacer
Copy link
Contributor

bmacer commented May 3, 2022

NFtsByOwner removed in #91

@bmacer bmacer closed this as completed May 3, 2022
Repository owner moved this from Todo to Done in rmrk-substrate May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Status: Done
Development

No branches or pull requests

4 participants