difftreelog
feature(rmrk-rpc): new nftChildren RPC
in: master
2 files changed
pallets/proxy-rmrk-core/src/misc.rsdiffbeforeafterboth26 }26 }27}27}2829pub trait RmrkRebind<T, S> {30 fn rebind(&self) -> BoundedVec<u8, S>;31}3233impl<T, S> RmrkRebind<T, S> for BoundedVec<u8, T> where BoundedVec<u8, S>: TryFrom<Vec<u8>> {34 fn rebind(&self) -> BoundedVec<u8, S> {35 BoundedVec::<u8, S>::try_from(36 self.clone().into_inner()37 ).unwrap_or_default()38 }39}284029#[derive(Encode, Decode, PartialEq, Eq)]41#[derive(Encode, Decode, PartialEq, Eq)]30pub enum CollectionType {42pub enum CollectionType {runtime/common/src/runtime_apis.rsdiffbeforeafterboth142 }142 }143143144 fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {144 fn collection_by_id(collection_id: RmrkCollectionId) -> Result<Option<RmrkCollectionInfo<AccountId>>, DispatchError> {145 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, RmrkDecode}};145 use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, RmrkDecode, RmrkRebind}};146146147 let collection_id = CollectionId(collection_id);147 let collection_id = CollectionId(collection_id);148 let collection = match RmrkCore::get_typed_nft_collection(collection_id, CollectionType::Regular) {148 let collection = match RmrkCore::get_typed_nft_collection(collection_id, CollectionType::Regular) {156 issuer: collection.owner.clone(),156 issuer: collection.owner.clone(),157 metadata: RmrkCore::get_collection_property(collection_id, RmrkProperty::Metadata)?.decode_or_default(),157 metadata: RmrkCore::get_collection_property(collection_id, RmrkProperty::Metadata)?.decode_or_default(),158 max: collection.limits.token_limit,158 max: collection.limits.token_limit,159 symbol: collection.token_prefix.decode_or_default(),159 symbol: collection.token_prefix.rebind(),160 nfts_count160 nfts_count161 }))161 }))162 }162 }204 }204 }205205206 fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {206 fn nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Result<Vec<RmrkNftChild>, DispatchError> {207 use up_data_structs::mapping::TokenAddressMapping;208209 let collection_id = CollectionId(collection_id);207 let collection_id = CollectionId(collection_id);210 let nft_id = TokenId(nft_id);208 let nft_id = TokenId(nft_id);211 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(Vec::new()); }209 if !RmrkCore::nft_exists(collection_id, nft_id) { return Ok(Vec::new()); }212213 let cross_account_id = CrossAccountId::from_eth(214 EvmTokenAddressMapping::token_to_address(collection_id, nft_id)215 );216210217 Ok(211 Ok(218 pallet_nonfungible::Owned::<Runtime>::iter_prefix((collection_id, cross_account_id))212 pallet_nonfungible::TokenChildren::<Runtime>::iter_prefix((collection_id, nft_id))219 .map(|(child_id, _)| RmrkNftChild {213 .filter_map(|(child_id, is_child)| 214 match is_child {215 true => Some(RmrkNftChild {220 collection_id: collection_id.0, // todo make sure they're always from this collection // spoiler: they're not216 collection_id: child_id.0.0,221 nft_id: child_id.0,217 nft_id: child_id.1.0,222 }).collect()218 }),219 false => None,220 }221 ).collect()223 )222 )224 }223 }332331333 fn base(base_id: RmrkBaseId) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {332 fn base(base_id: RmrkBaseId) -> Result<Option<RmrkBaseInfo<AccountId>>, DispatchError> {334 use pallet_proxy_rmrk_core::{333 use pallet_proxy_rmrk_core::{335 RmrkProperty, misc::{CollectionType, RmrkDecode},334 RmrkProperty, misc::{CollectionType, RmrkDecode, RmrkRebind},336 };335 };337336338 let collection_id = CollectionId(base_id);337 let collection_id = CollectionId(base_id);344 Ok(Some(RmrkBaseInfo {343 Ok(Some(RmrkBaseInfo {345 issuer: collection.owner.clone(),344 issuer: collection.owner.clone(),346 base_type: RmrkCore::get_collection_property(collection_id, RmrkProperty::BaseType)?.decode_or_default(),345 base_type: RmrkCore::get_collection_property(collection_id, RmrkProperty::BaseType)?.decode_or_default(),347 symbol: collection.token_prefix.decode_or_default(),346 symbol: collection.token_prefix.rebind(),348 }))347 }))349 }348 }350349