From d4149b5fdc00975d73f7a666222b98bf10a4a316 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Mon, 08 Aug 2022 08:26:11 +0000 Subject: [PATCH] feat(pallet-refungible): implement property RPC --- --- a/pallets/refungible/src/common.rs +++ b/pallets/refungible/src/common.rs @@ -33,7 +33,7 @@ use crate::{ AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle, - SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted, TotalSupply, CreateItemData, + SelfWeightOf, weights::WeightInfo, TokensMinted, TotalSupply, CreateItemData, }; macro_rules! max_weight_of { @@ -457,16 +457,31 @@ >::token_owners(self.id, token).unwrap_or_default() } - fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option { - None + fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option { + >::token_properties((self.id, token_id)) + .get(key) + .cloned() } - fn token_properties( - &self, - _token_id: TokenId, - _keys: Option>, - ) -> Vec { - Vec::new() + fn token_properties(&self, token_id: TokenId, keys: Option>) -> Vec { + let properties = >::token_properties((self.id, token_id)); + + keys.map(|keys| { + keys.into_iter() + .filter_map(|key| { + properties.get(&key).map(|value| Property { + key, + value: value.clone(), + }) + }) + .collect() + }) + .unwrap_or_else(|| { + properties + .into_iter() + .map(|(key, value)| Property { key, value }) + .collect() + }) } fn total_supply(&self) -> u32 { --- a/pallets/refungible/src/erc.rs +++ b/pallets/refungible/src/erc.rs @@ -27,7 +27,7 @@ convert::TryInto, }; use evm_coder::{ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*, weight}; -use frame_support::{BoundedBTreeMap, BoundedVec}; +use frame_support::BoundedBTreeMap; use pallet_common::{ CollectionHandle, CollectionPropertyPermissions, erc::{ -- gitstuff