git.delta.rocks / unique-network / refs/commits / 3cb5e43c69bb

difftreelog

CORE-410 Implement token_owner for Refungible token

Trubnikov Sergey2022-07-07parent: #0427b9a.patch.diff
in: master

2 files changed

modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
413 TokenId(<TokensMinted<T>>::get(self.id))413 TokenId(<TokensMinted<T>>::get(self.id))
414 }414 }
415415
416 fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {416 fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId> {
417 None417 <Pallet<T>>::token_owner(self.id, token)
418 }418 }
419419
420 fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option<PropertyValue> {420 fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option<PropertyValue> {
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -1094,6 +1094,19 @@
 		Ok(())
 	}
 
+	fn token_owner(collection_id: CollectionId, token_id: TokenId) -> Option<T::CrossAccountId> {
+		let mut owner = None;
+		let mut count = 0;
+		for key in Balance::<T>::iter_key_prefix((collection_id, token_id)) {
+			count += 1;
+			if count > 1 {
+				return None;
+			}
+			owner = Some(key);
+		}
+		owner
+	}
+
 	fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<u128> {
 		<TotalSupply<T>>::try_get((collection_id, token_id)).ok()
 	}