From 3cb5e43c69bb03bd7540dcda98b9ea0c0da393b2 Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Thu, 07 Jul 2022 14:12:58 +0000 Subject: [PATCH] CORE-410 Implement token_owner for Refungible token --- --- a/pallets/refungible/src/common.rs +++ b/pallets/refungible/src/common.rs @@ -413,8 +413,8 @@ TokenId(>::get(self.id)) } - fn token_owner(&self, _token: TokenId) -> Option { - None + fn token_owner(&self, token: TokenId) -> Option { + >::token_owner(self.id, token) } fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option { --- 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 { + let mut owner = None; + let mut count = 0; + for key in Balance::::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 { >::try_get((collection_id, token_id)).ok() } -- gitstuff