difftreelog
doc: minor fixes + typos
in: master
7 files changed
client/rpc/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original License18use std::sync::Arc;1920use codec::{Decode, Encode};21use jsonrpsee::{22 core::{RpcResult as Result},23 proc_macros::rpc,24};25use anyhow::anyhow;26use up_data_structs::{27 RpcCollection, CollectionId, CollectionStats, CollectionLimits, TokenId, Property,28 PropertyKeyPermission, TokenData, TokenChild,29};30use sp_api::{BlockId, BlockT, ProvideRuntimeApi, ApiExt};31use sp_blockchain::HeaderBackend;32use up_rpc::UniqueApi as UniqueRuntimeApi;3334// RMRK35use rmrk_rpc::RmrkApi as RmrkRuntimeApi;36use up_data_structs::{37 RmrkCollectionId, RmrkNftId, RmrkBaseId, RmrkNftChild, RmrkThemeName, RmrkResourceId,38};3940pub use rmrk_unique_rpc::RmrkApiServer;4142#[rpc(server)]43#[async_trait]44pub trait UniqueApi<BlockHash, CrossAccountId, AccountId> {45 /// Get tokens owned by account46 #[method(name = "unique_accountTokens")]47 fn account_tokens(48 &self,49 collection: CollectionId,50 account: CrossAccountId,51 at: Option<BlockHash>,52 ) -> Result<Vec<TokenId>>;53 /// Get tokens contained in collection54 #[method(name = "unique_collectionTokens")]55 fn collection_tokens(56 &self,57 collection: CollectionId,58 at: Option<BlockHash>,59 ) -> Result<Vec<TokenId>>;60 /// Check if token exists61 #[method(name = "unique_tokenExists")]62 fn token_exists(63 &self,64 collection: CollectionId,65 token: TokenId,66 at: Option<BlockHash>,67 ) -> Result<bool>;68 /// Get token owner69 #[method(name = "unique_tokenOwner")]70 fn token_owner(71 &self,72 collection: CollectionId,73 token: TokenId,74 at: Option<BlockHash>,75 ) -> Result<Option<CrossAccountId>>;76 /// Get token owner, in case of nested token - find the parent recursively77 #[method(name = "unique_topmostTokenOwner")]78 fn topmost_token_owner(79 &self,80 collection: CollectionId,81 token: TokenId,82 at: Option<BlockHash>,83 ) -> Result<Option<CrossAccountId>>;84 /// Get tokens nested directly into the token85 #[method(name = "unique_tokenChildren")]86 fn token_children(87 &self,88 collection: CollectionId,89 token: TokenId,90 at: Option<BlockHash>,91 ) -> Result<Vec<TokenChild>>;92 /// Get collection properties93 #[method(name = "unique_collectionProperties")]94 fn collection_properties(95 &self,96 collection: CollectionId,97 keys: Option<Vec<String>>,98 at: Option<BlockHash>,99 ) -> Result<Vec<Property>>;100 /// Get token properties101 #[method(name = "unique_tokenProperties")]102 fn token_properties(103 &self,104 collection: CollectionId,105 token_id: TokenId,106 keys: Option<Vec<String>>,107 at: Option<BlockHash>,108 ) -> Result<Vec<Property>>;109 /// Get property permissions110 #[method(name = "unique_propertyPermissions")]111 fn property_permissions(112 &self,113 collection: CollectionId,114 keys: Option<Vec<String>>,115 at: Option<BlockHash>,116 ) -> Result<Vec<PropertyKeyPermission>>;117 /// Get token data118 #[method(name = "unique_tokenData")]119 fn token_data(120 &self,121 collection: CollectionId,122 token_id: TokenId,123 keys: Option<Vec<String>>,124 at: Option<BlockHash>,125 ) -> Result<TokenData<CrossAccountId>>;126 /// Get amount of unique collection tokens127 #[method(name = "unique_totalSupply")]128 fn total_supply(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<u32>;129 /// Get owned amount of any user tokens130 #[method(name = "unique_accountBalance")]131 fn account_balance(132 &self,133 collection: CollectionId,134 account: CrossAccountId,135 at: Option<BlockHash>,136 ) -> Result<u32>;137 /// Get owned amount of specific account token138 #[method(name = "unique_balance")]139 fn balance(140 &self,141 collection: CollectionId,142 account: CrossAccountId,143 token: TokenId,144 at: Option<BlockHash>,145 ) -> Result<String>;146 /// Get allowed amount147 #[method(name = "unique_allowance")]148 fn allowance(149 &self,150 collection: CollectionId,151 sender: CrossAccountId,152 spender: CrossAccountId,153 token: TokenId,154 at: Option<BlockHash>,155 ) -> Result<String>;156 /// Get admin list157 #[method(name = "unique_adminlist")]158 fn adminlist(159 &self,160 collection: CollectionId,161 at: Option<BlockHash>,162 ) -> Result<Vec<CrossAccountId>>;163 /// Get allowlist164 #[method(name = "unique_allowlist")]165 fn allowlist(166 &self,167 collection: CollectionId,168 at: Option<BlockHash>,169 ) -> Result<Vec<CrossAccountId>>;170 /// Check if user is allowed to use collection171 #[method(name = "unique_allowed")]172 fn allowed(173 &self,174 collection: CollectionId,175 user: CrossAccountId,176 at: Option<BlockHash>,177 ) -> Result<bool>;178 /// Get last token ID created in a collection179 #[method(name = "unique_lastTokenId")]180 fn last_token_id(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<TokenId>;181 /// Get collection by specified ID182 #[method(name = "unique_collectionById")]183 fn collection_by_id(184 &self,185 collection: CollectionId,186 at: Option<BlockHash>,187 ) -> Result<Option<RpcCollection<AccountId>>>;188 /// Get collection stats189 #[method(name = "unique_collectionStats")]190 fn collection_stats(&self, at: Option<BlockHash>) -> Result<CollectionStats>;191 /// Get number of blocks when sponsored transaction is available192 #[method(name = "unique_nextSponsored")]193 fn next_sponsored(194 &self,195 collection: CollectionId,196 account: CrossAccountId,197 token: TokenId,198 at: Option<BlockHash>,199 ) -> Result<Option<u64>>;200 /// Get effective collection limits201 #[method(name = "unique_effectiveCollectionLimits")]202 fn effective_collection_limits(203 &self,204 collection_id: CollectionId,205 at: Option<BlockHash>,206 ) -> Result<Option<CollectionLimits>>;207 /// Get total pieces of token208 #[method(name = "unique_totalPieces")]209 fn total_pieces(210 &self,211 collection_id: CollectionId,212 token_id: TokenId,213 at: Option<BlockHash>,214 ) -> Result<Option<u128>>;215}216217mod rmrk_unique_rpc {218 use super::*;219220 #[rpc(server)]221 #[async_trait]222 pub trait RmrkApi<223 BlockHash,224 AccountId,225 CollectionInfo,226 NftInfo,227 ResourceInfo,228 PropertyInfo,229 BaseInfo,230 PartType,231 Theme,232 >233 {234 #[method(name = "rmrk_lastCollectionIdx")]235 /// Get the latest created collection id236 fn last_collection_idx(&self, at: Option<BlockHash>) -> Result<RmrkCollectionId>;237238 #[method(name = "rmrk_collectionById")]239 /// Get collection by id240 fn collection_by_id(241 &self,242 id: RmrkCollectionId,243 at: Option<BlockHash>,244 ) -> Result<Option<CollectionInfo>>;245246 #[method(name = "rmrk_nftById")]247 /// Get NFT by collection id and NFT id248 fn nft_by_id(249 &self,250 collection_id: RmrkCollectionId,251 nft_id: RmrkNftId,252 at: Option<BlockHash>,253 ) -> Result<Option<NftInfo>>;254255 #[method(name = "rmrk_accountTokens")]256 /// Get tokens owned by an account in a collection257 fn account_tokens(258 &self,259 account_id: AccountId,260 collection_id: RmrkCollectionId,261 at: Option<BlockHash>,262 ) -> Result<Vec<RmrkNftId>>;263264 #[method(name = "rmrk_nftChildren")]265 /// Get NFT children266 fn nft_children(267 &self,268 collection_id: RmrkCollectionId,269 nft_id: RmrkNftId,270 at: Option<BlockHash>,271 ) -> Result<Vec<RmrkNftChild>>;272273 #[method(name = "rmrk_collectionProperties")]274 /// Get collection properties275 fn collection_properties(276 &self,277 collection_id: RmrkCollectionId,278 filter_keys: Option<Vec<String>>,279 at: Option<BlockHash>,280 ) -> Result<Vec<PropertyInfo>>;281282 #[method(name = "rmrk_nftProperties")]283 /// Get NFT properties284 fn nft_properties(285 &self,286 collection_id: RmrkCollectionId,287 nft_id: RmrkNftId,288 filter_keys: Option<Vec<String>>,289 at: Option<BlockHash>,290 ) -> Result<Vec<PropertyInfo>>;291292 #[method(name = "rmrk_nftResources")]293 /// Get NFT resources294 fn nft_resources(295 &self,296 collection_id: RmrkCollectionId,297 nft_id: RmrkNftId,298 at: Option<BlockHash>,299 ) -> Result<Vec<ResourceInfo>>;300301 #[method(name = "rmrk_nftResourcePriority")]302 /// Get NFT resource priority303 fn nft_resource_priority(304 &self,305 collection_id: RmrkCollectionId,306 nft_id: RmrkNftId,307 resource_id: RmrkResourceId,308 at: Option<BlockHash>,309 ) -> Result<Option<u32>>;310311 #[method(name = "rmrk_base")]312 /// Get base info313 fn base(&self, base_id: RmrkBaseId, at: Option<BlockHash>) -> Result<Option<BaseInfo>>;314315 #[method(name = "rmrk_baseParts")]316 /// Get all Base's parts317 fn base_parts(&self, base_id: RmrkBaseId, at: Option<BlockHash>) -> Result<Vec<PartType>>;318319 #[method(name = "rmrk_themeNames")]320 /// Get Base's theme names321 fn theme_names(322 &self,323 base_id: RmrkBaseId,324 at: Option<BlockHash>,325 ) -> Result<Vec<RmrkThemeName>>;326327 #[method(name = "rmrk_themes")]328 /// Get Theme info -- name, properties, and inherit flag329 fn theme(330 &self,331 base_id: RmrkBaseId,332 theme_name: String,333 filter_keys: Option<Vec<String>>,334 at: Option<BlockHash>,335 ) -> Result<Option<Theme>>;336 }337}338339pub struct Unique<C, P> {340 client: Arc<C>,341 _marker: std::marker::PhantomData<P>,342}343344impl<C, P> Unique<C, P> {345 pub fn new(client: Arc<C>) -> Self {346 Self {347 client,348 _marker: Default::default(),349 }350 }351}352353pub struct Rmrk<C, P> {354 client: Arc<C>,355 _marker: std::marker::PhantomData<P>,356}357358impl<C, P> Rmrk<C, P> {359 pub fn new(client: Arc<C>) -> Self {360 Self {361 client,362 _marker: Default::default(),363 }364 }365}366367macro_rules! pass_method {368 (369 $method_name:ident(370 $($(#[map(|$map_arg:ident| $map:expr)])? $name:ident: $ty:ty),* $(,)?371 ) -> $result:ty $(=> $mapper:expr)?,372 //$runtime_name:ident $(<$($lt: tt),+>)*373 $runtime_api_macro:ident374 $(; changed_in $ver:expr, $changed_method_name:ident ($($changed_name:expr), * $(,)?) => $fixer:expr)*375 ) => {376 fn $method_name(377 &self,378 $(379 $name: $ty,380 )*381 at: Option<<Block as BlockT>::Hash>,382 ) -> Result<$result> {383 let api = self.client.runtime_api();384 let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash));385 let _api_version = if let Ok(Some(api_version)) =386 api.api_version::<$runtime_api_macro!()>(&at)387 {388 api_version389 } else {390 // unreachable for our runtime391 return Err(anyhow!("api is not available").into())392 };393394 let result = $(if _api_version < $ver {395 api.$changed_method_name(&at, $($changed_name),*).map(|r| r.map($fixer))396 } else)*397 { api.$method_name(&at, $($((|$map_arg: $ty| $map))? ($name)),*) };398399 Ok(result400 .map_err(|e| anyhow!("unable to query: {e}"))?401 .map_err(|e| anyhow!("runtime error: {e:?}"))$(.map($mapper))??)402 }403 };404}405406macro_rules! unique_api {407 () => {408 dyn UniqueRuntimeApi<Block, CrossAccountId, AccountId>409 };410}411412macro_rules! rmrk_api {413 () => {414 dyn RmrkRuntimeApi<Block, AccountId, CollectionInfo, NftInfo, ResourceInfo, PropertyInfo, BaseInfo, PartType, Theme>415 };416}417418#[allow(deprecated)]419impl<C, Block, CrossAccountId, AccountId>420 UniqueApiServer<<Block as BlockT>::Hash, CrossAccountId, AccountId> for Unique<C, Block>421where422 Block: BlockT,423 AccountId: Decode,424 C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,425 C::Api: UniqueRuntimeApi<Block, CrossAccountId, AccountId>,426 CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,427{428 pass_method!(429 account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId>, unique_api430 );431 pass_method!(432 collection_tokens(collection: CollectionId) -> Vec<TokenId>, unique_api433 );434 pass_method!(435 token_exists(collection: CollectionId, token: TokenId) -> bool, unique_api436 );437 pass_method!(438 token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>, unique_api439 );440 pass_method!(441 topmost_token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>, unique_api442 );443 pass_method!(token_children(collection: CollectionId, token: TokenId) -> Vec<TokenChild>, unique_api);444 pass_method!(total_supply(collection: CollectionId) -> u32, unique_api);445 pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32, unique_api);446 pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string(), unique_api);447 pass_method!(448 allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string(),449 unique_api450 );451452 pass_method!(collection_properties(453 collection: CollectionId,454455 #[map(|keys| string_keys_to_bytes_keys(keys))]456 keys: Option<Vec<String>>457 ) -> Vec<Property>, unique_api);458459 pass_method!(token_properties(460 collection: CollectionId,461 token_id: TokenId,462463 #[map(|keys| string_keys_to_bytes_keys(keys))]464 keys: Option<Vec<String>>465 ) -> Vec<Property>, unique_api);466467 pass_method!(property_permissions(468 collection: CollectionId,469470 #[map(|keys| string_keys_to_bytes_keys(keys))]471 keys: Option<Vec<String>>472 ) -> Vec<PropertyKeyPermission>, unique_api);473474 pass_method!(token_data(475 collection: CollectionId,476 token_id: TokenId,477478 #[map(|keys| string_keys_to_bytes_keys(keys))]479 keys: Option<Vec<String>>,480 ) -> TokenData<CrossAccountId>, unique_api);481482 pass_method!(adminlist(collection: CollectionId) -> Vec<CrossAccountId>, unique_api);483 pass_method!(allowlist(collection: CollectionId) -> Vec<CrossAccountId>, unique_api);484 pass_method!(allowed(collection: CollectionId, user: CrossAccountId) -> bool, unique_api);485 pass_method!(last_token_id(collection: CollectionId) -> TokenId, unique_api);486 pass_method!(collection_by_id(collection: CollectionId) -> Option<RpcCollection<AccountId>>, unique_api);487 pass_method!(collection_stats() -> CollectionStats, unique_api);488 pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);489 pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>, unique_api);490 pass_method!(total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<u128>, unique_api);491}492493#[allow(deprecated)]494impl<495 C,496 Block,497 AccountId,498 CollectionInfo,499 NftInfo,500 ResourceInfo,501 PropertyInfo,502 BaseInfo,503 PartType,504 Theme,505 >506 rmrk_unique_rpc::RmrkApiServer<507 <Block as BlockT>::Hash,508 AccountId,509 CollectionInfo,510 NftInfo,511 ResourceInfo,512 PropertyInfo,513 BaseInfo,514 PartType,515 Theme,516 > for Rmrk<C, Block>517where518 C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,519 C::Api: RmrkRuntimeApi<520 Block,521 AccountId,522 CollectionInfo,523 NftInfo,524 ResourceInfo,525 PropertyInfo,526 BaseInfo,527 PartType,528 Theme,529 >,530 AccountId: Decode + Encode,531 CollectionInfo: Decode,532 NftInfo: Decode,533 ResourceInfo: Decode,534 PropertyInfo: Decode,535 BaseInfo: Decode,536 PartType: Decode,537 Theme: Decode,538 Block: BlockT,539{540 pass_method!(last_collection_idx() -> RmrkCollectionId, rmrk_api);541 pass_method!(collection_by_id(id: RmrkCollectionId) -> Option<CollectionInfo>, rmrk_api);542 pass_method!(nft_by_id(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Option<NftInfo>, rmrk_api);543 pass_method!(account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Vec<RmrkNftId>, rmrk_api);544 pass_method!(nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Vec<RmrkNftChild>, rmrk_api);545 pass_method!(546 collection_properties(547 collection_id: RmrkCollectionId,548549 #[map(|keys| string_keys_to_bytes_keys(keys))]550 filter_keys: Option<Vec<String>>551 ) -> Vec<PropertyInfo>,552 rmrk_api553 );554 pass_method!(555 nft_properties(556 collection_id: RmrkCollectionId,557 nft_id: RmrkNftId,558559 #[map(|keys| string_keys_to_bytes_keys(keys))]560 filter_keys: Option<Vec<String>>561 ) -> Vec<PropertyInfo>,562 rmrk_api563 );564 pass_method!(nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Vec<ResourceInfo>, rmrk_api);565 pass_method!(nft_resource_priority(collection_id: RmrkCollectionId, nft_id: RmrkNftId, resource_id: RmrkResourceId) -> Option<u32>, rmrk_api);566 pass_method!(base(base_id: RmrkBaseId) -> Option<BaseInfo>, rmrk_api);567 pass_method!(base_parts(base_id: RmrkBaseId) -> Vec<PartType>, rmrk_api);568 pass_method!(theme_names(base_id: RmrkBaseId) -> Vec<RmrkThemeName>, rmrk_api);569 pass_method!(570 theme(571 base_id: RmrkBaseId,572573 #[map(|n| n.into_bytes())]574 theme_name: String,575576 #[map(|keys| string_keys_to_bytes_keys(keys))]577 filter_keys: Option<Vec<String>>578 ) -> Option<Theme>, rmrk_api);579}580581fn string_keys_to_bytes_keys(keys: Option<Vec<String>>) -> Option<Vec<Vec<u8>>> {582 keys.map(|keys| keys.into_iter().map(|key| key.into_bytes()).collect())583}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original License18use std::sync::Arc;1920use codec::{Decode, Encode};21use jsonrpsee::{22 core::{RpcResult as Result},23 proc_macros::rpc,24};25use anyhow::anyhow;26use up_data_structs::{27 RpcCollection, CollectionId, CollectionStats, CollectionLimits, TokenId, Property,28 PropertyKeyPermission, TokenData, TokenChild,29};30use sp_api::{BlockId, BlockT, ProvideRuntimeApi, ApiExt};31use sp_blockchain::HeaderBackend;32use up_rpc::UniqueApi as UniqueRuntimeApi;3334// RMRK35use rmrk_rpc::RmrkApi as RmrkRuntimeApi;36use up_data_structs::{37 RmrkCollectionId, RmrkNftId, RmrkBaseId, RmrkNftChild, RmrkThemeName, RmrkResourceId,38};3940pub use rmrk_unique_rpc::RmrkApiServer;4142#[rpc(server)]43#[async_trait]44pub trait UniqueApi<BlockHash, CrossAccountId, AccountId> {45 /// Get tokens owned by account46 #[method(name = "unique_accountTokens")]47 fn account_tokens(48 &self,49 collection: CollectionId,50 account: CrossAccountId,51 at: Option<BlockHash>,52 ) -> Result<Vec<TokenId>>;5354 /// Get tokens contained in collection55 #[method(name = "unique_collectionTokens")]56 fn collection_tokens(57 &self,58 collection: CollectionId,59 at: Option<BlockHash>,60 ) -> Result<Vec<TokenId>>;6162 /// Check if token exists63 #[method(name = "unique_tokenExists")]64 fn token_exists(65 &self,66 collection: CollectionId,67 token: TokenId,68 at: Option<BlockHash>,69 ) -> Result<bool>;7071 /// Get token owner72 #[method(name = "unique_tokenOwner")]73 fn token_owner(74 &self,75 collection: CollectionId,76 token: TokenId,77 at: Option<BlockHash>,78 ) -> Result<Option<CrossAccountId>>;7980 /// Get token owner, in case of nested token - find the parent recursively81 #[method(name = "unique_topmostTokenOwner")]82 fn topmost_token_owner(83 &self,84 collection: CollectionId,85 token: TokenId,86 at: Option<BlockHash>,87 ) -> Result<Option<CrossAccountId>>;8889 /// Get tokens nested directly into the token90 #[method(name = "unique_tokenChildren")]91 fn token_children(92 &self,93 collection: CollectionId,94 token: TokenId,95 at: Option<BlockHash>,96 ) -> Result<Vec<TokenChild>>;9798 /// Get collection properties99 #[method(name = "unique_collectionProperties")]100 fn collection_properties(101 &self,102 collection: CollectionId,103 keys: Option<Vec<String>>,104 at: Option<BlockHash>,105 ) -> Result<Vec<Property>>;106107 /// Get token properties108 #[method(name = "unique_tokenProperties")]109 fn token_properties(110 &self,111 collection: CollectionId,112 token_id: TokenId,113 keys: Option<Vec<String>>,114 at: Option<BlockHash>,115 ) -> Result<Vec<Property>>;116117 /// Get property permissions118 #[method(name = "unique_propertyPermissions")]119 fn property_permissions(120 &self,121 collection: CollectionId,122 keys: Option<Vec<String>>,123 at: Option<BlockHash>,124 ) -> Result<Vec<PropertyKeyPermission>>;125126 /// Get token data127 #[method(name = "unique_tokenData")]128 fn token_data(129 &self,130 collection: CollectionId,131 token_id: TokenId,132 keys: Option<Vec<String>>,133 at: Option<BlockHash>,134 ) -> Result<TokenData<CrossAccountId>>;135136 /// Get amount of unique collection tokens137 #[method(name = "unique_totalSupply")]138 fn total_supply(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<u32>;139140 /// Get owned amount of any user tokens141 #[method(name = "unique_accountBalance")]142 fn account_balance(143 &self,144 collection: CollectionId,145 account: CrossAccountId,146 at: Option<BlockHash>,147 ) -> Result<u32>;148149 /// Get owned amount of specific account token150 #[method(name = "unique_balance")]151 fn balance(152 &self,153 collection: CollectionId,154 account: CrossAccountId,155 token: TokenId,156 at: Option<BlockHash>,157 ) -> Result<String>;158159 /// Get allowed amount160 #[method(name = "unique_allowance")]161 fn allowance(162 &self,163 collection: CollectionId,164 sender: CrossAccountId,165 spender: CrossAccountId,166 token: TokenId,167 at: Option<BlockHash>,168 ) -> Result<String>;169170 /// Get admin list171 #[method(name = "unique_adminlist")]172 fn adminlist(173 &self,174 collection: CollectionId,175 at: Option<BlockHash>,176 ) -> Result<Vec<CrossAccountId>>;177178 /// Get allowlist179 #[method(name = "unique_allowlist")]180 fn allowlist(181 &self,182 collection: CollectionId,183 at: Option<BlockHash>,184 ) -> Result<Vec<CrossAccountId>>;185186 /// Check if user is allowed to use collection187 #[method(name = "unique_allowed")]188 fn allowed(189 &self,190 collection: CollectionId,191 user: CrossAccountId,192 at: Option<BlockHash>,193 ) -> Result<bool>;194195 /// Get last token ID created in a collection196 #[method(name = "unique_lastTokenId")]197 fn last_token_id(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<TokenId>;198199 /// Get collection by specified ID200 #[method(name = "unique_collectionById")]201 fn collection_by_id(202 &self,203 collection: CollectionId,204 at: Option<BlockHash>,205 ) -> Result<Option<RpcCollection<AccountId>>>;206207 /// Get collection stats208 #[method(name = "unique_collectionStats")]209 fn collection_stats(&self, at: Option<BlockHash>) -> Result<CollectionStats>;210211 /// Get number of blocks when sponsored transaction is available212 #[method(name = "unique_nextSponsored")]213 fn next_sponsored(214 &self,215 collection: CollectionId,216 account: CrossAccountId,217 token: TokenId,218 at: Option<BlockHash>,219 ) -> Result<Option<u64>>;220221 /// Get effective collection limits222 #[method(name = "unique_effectiveCollectionLimits")]223 fn effective_collection_limits(224 &self,225 collection_id: CollectionId,226 at: Option<BlockHash>,227 ) -> Result<Option<CollectionLimits>>;228229 /// Get total pieces of token230 #[method(name = "unique_totalPieces")]231 fn total_pieces(232 &self,233 collection_id: CollectionId,234 token_id: TokenId,235 at: Option<BlockHash>,236 ) -> Result<Option<u128>>;237}238239mod rmrk_unique_rpc {240 use super::*;241242 #[rpc(server)]243 #[async_trait]244 pub trait RmrkApi<245 BlockHash,246 AccountId,247 CollectionInfo,248 NftInfo,249 ResourceInfo,250 PropertyInfo,251 BaseInfo,252 PartType,253 Theme,254 >255 {256 #[method(name = "rmrk_lastCollectionIdx")]257 /// Get the latest created collection id258 fn last_collection_idx(&self, at: Option<BlockHash>) -> Result<RmrkCollectionId>;259260 #[method(name = "rmrk_collectionById")]261 /// Get collection by id262 fn collection_by_id(263 &self,264 id: RmrkCollectionId,265 at: Option<BlockHash>,266 ) -> Result<Option<CollectionInfo>>;267268 #[method(name = "rmrk_nftById")]269 /// Get NFT by collection id and NFT id270 fn nft_by_id(271 &self,272 collection_id: RmrkCollectionId,273 nft_id: RmrkNftId,274 at: Option<BlockHash>,275 ) -> Result<Option<NftInfo>>;276277 #[method(name = "rmrk_accountTokens")]278 /// Get tokens owned by an account in a collection279 fn account_tokens(280 &self,281 account_id: AccountId,282 collection_id: RmrkCollectionId,283 at: Option<BlockHash>,284 ) -> Result<Vec<RmrkNftId>>;285286 #[method(name = "rmrk_nftChildren")]287 /// Get NFT children288 fn nft_children(289 &self,290 collection_id: RmrkCollectionId,291 nft_id: RmrkNftId,292 at: Option<BlockHash>,293 ) -> Result<Vec<RmrkNftChild>>;294295 #[method(name = "rmrk_collectionProperties")]296 /// Get collection properties297 fn collection_properties(298 &self,299 collection_id: RmrkCollectionId,300 filter_keys: Option<Vec<String>>,301 at: Option<BlockHash>,302 ) -> Result<Vec<PropertyInfo>>;303304 #[method(name = "rmrk_nftProperties")]305 /// Get NFT properties306 fn nft_properties(307 &self,308 collection_id: RmrkCollectionId,309 nft_id: RmrkNftId,310 filter_keys: Option<Vec<String>>,311 at: Option<BlockHash>,312 ) -> Result<Vec<PropertyInfo>>;313314 #[method(name = "rmrk_nftResources")]315 /// Get NFT resources316 fn nft_resources(317 &self,318 collection_id: RmrkCollectionId,319 nft_id: RmrkNftId,320 at: Option<BlockHash>,321 ) -> Result<Vec<ResourceInfo>>;322323 #[method(name = "rmrk_nftResourcePriority")]324 /// Get NFT resource priority325 fn nft_resource_priority(326 &self,327 collection_id: RmrkCollectionId,328 nft_id: RmrkNftId,329 resource_id: RmrkResourceId,330 at: Option<BlockHash>,331 ) -> Result<Option<u32>>;332333 #[method(name = "rmrk_base")]334 /// Get base info335 fn base(&self, base_id: RmrkBaseId, at: Option<BlockHash>) -> Result<Option<BaseInfo>>;336337 #[method(name = "rmrk_baseParts")]338 /// Get all Base's parts339 fn base_parts(&self, base_id: RmrkBaseId, at: Option<BlockHash>) -> Result<Vec<PartType>>;340341 #[method(name = "rmrk_themeNames")]342 /// Get Base's theme names343 fn theme_names(344 &self,345 base_id: RmrkBaseId,346 at: Option<BlockHash>,347 ) -> Result<Vec<RmrkThemeName>>;348349 #[method(name = "rmrk_themes")]350 /// Get Theme info -- name, properties, and inherit flag351 fn theme(352 &self,353 base_id: RmrkBaseId,354 theme_name: String,355 filter_keys: Option<Vec<String>>,356 at: Option<BlockHash>,357 ) -> Result<Option<Theme>>;358 }359}360361pub struct Unique<C, P> {362 client: Arc<C>,363 _marker: std::marker::PhantomData<P>,364}365366impl<C, P> Unique<C, P> {367 pub fn new(client: Arc<C>) -> Self {368 Self {369 client,370 _marker: Default::default(),371 }372 }373}374375pub struct Rmrk<C, P> {376 client: Arc<C>,377 _marker: std::marker::PhantomData<P>,378}379380impl<C, P> Rmrk<C, P> {381 pub fn new(client: Arc<C>) -> Self {382 Self {383 client,384 _marker: Default::default(),385 }386 }387}388389macro_rules! pass_method {390 (391 $method_name:ident(392 $($(#[map(|$map_arg:ident| $map:expr)])? $name:ident: $ty:ty),* $(,)?393 ) -> $result:ty $(=> $mapper:expr)?,394 //$runtime_name:ident $(<$($lt: tt),+>)*395 $runtime_api_macro:ident396 $(; changed_in $ver:expr, $changed_method_name:ident ($($changed_name:expr), * $(,)?) => $fixer:expr)*397 ) => {398 fn $method_name(399 &self,400 $(401 $name: $ty,402 )*403 at: Option<<Block as BlockT>::Hash>,404 ) -> Result<$result> {405 let api = self.client.runtime_api();406 let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash));407 let _api_version = if let Ok(Some(api_version)) =408 api.api_version::<$runtime_api_macro!()>(&at)409 {410 api_version411 } else {412 // unreachable for our runtime413 return Err(anyhow!("api is not available").into())414 };415416 let result = $(if _api_version < $ver {417 api.$changed_method_name(&at, $($changed_name),*).map(|r| r.map($fixer))418 } else)*419 { api.$method_name(&at, $($((|$map_arg: $ty| $map))? ($name)),*) };420421 Ok(result422 .map_err(|e| anyhow!("unable to query: {e}"))?423 .map_err(|e| anyhow!("runtime error: {e:?}"))$(.map($mapper))??)424 }425 };426}427428macro_rules! unique_api {429 () => {430 dyn UniqueRuntimeApi<Block, CrossAccountId, AccountId>431 };432}433434macro_rules! rmrk_api {435 () => {436 dyn RmrkRuntimeApi<Block, AccountId, CollectionInfo, NftInfo, ResourceInfo, PropertyInfo, BaseInfo, PartType, Theme>437 };438}439440#[allow(deprecated)]441impl<C, Block, CrossAccountId, AccountId>442 UniqueApiServer<<Block as BlockT>::Hash, CrossAccountId, AccountId> for Unique<C, Block>443where444 Block: BlockT,445 AccountId: Decode,446 C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,447 C::Api: UniqueRuntimeApi<Block, CrossAccountId, AccountId>,448 CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,449{450 pass_method!(451 account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId>, unique_api452 );453 pass_method!(454 collection_tokens(collection: CollectionId) -> Vec<TokenId>, unique_api455 );456 pass_method!(457 token_exists(collection: CollectionId, token: TokenId) -> bool, unique_api458 );459 pass_method!(460 token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>, unique_api461 );462 pass_method!(463 topmost_token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>, unique_api464 );465 pass_method!(token_children(collection: CollectionId, token: TokenId) -> Vec<TokenChild>, unique_api);466 pass_method!(total_supply(collection: CollectionId) -> u32, unique_api);467 pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32, unique_api);468 pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string(), unique_api);469 pass_method!(470 allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string(),471 unique_api472 );473474 pass_method!(collection_properties(475 collection: CollectionId,476477 #[map(|keys| string_keys_to_bytes_keys(keys))]478 keys: Option<Vec<String>>479 ) -> Vec<Property>, unique_api);480481 pass_method!(token_properties(482 collection: CollectionId,483 token_id: TokenId,484485 #[map(|keys| string_keys_to_bytes_keys(keys))]486 keys: Option<Vec<String>>487 ) -> Vec<Property>, unique_api);488489 pass_method!(property_permissions(490 collection: CollectionId,491492 #[map(|keys| string_keys_to_bytes_keys(keys))]493 keys: Option<Vec<String>>494 ) -> Vec<PropertyKeyPermission>, unique_api);495496 pass_method!(token_data(497 collection: CollectionId,498 token_id: TokenId,499500 #[map(|keys| string_keys_to_bytes_keys(keys))]501 keys: Option<Vec<String>>,502 ) -> TokenData<CrossAccountId>, unique_api);503504 pass_method!(adminlist(collection: CollectionId) -> Vec<CrossAccountId>, unique_api);505 pass_method!(allowlist(collection: CollectionId) -> Vec<CrossAccountId>, unique_api);506 pass_method!(allowed(collection: CollectionId, user: CrossAccountId) -> bool, unique_api);507 pass_method!(last_token_id(collection: CollectionId) -> TokenId, unique_api);508 pass_method!(collection_by_id(collection: CollectionId) -> Option<RpcCollection<AccountId>>, unique_api);509 pass_method!(collection_stats() -> CollectionStats, unique_api);510 pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);511 pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>, unique_api);512 pass_method!(total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<u128>, unique_api);513}514515#[allow(deprecated)]516impl<517 C,518 Block,519 AccountId,520 CollectionInfo,521 NftInfo,522 ResourceInfo,523 PropertyInfo,524 BaseInfo,525 PartType,526 Theme,527 >528 rmrk_unique_rpc::RmrkApiServer<529 <Block as BlockT>::Hash,530 AccountId,531 CollectionInfo,532 NftInfo,533 ResourceInfo,534 PropertyInfo,535 BaseInfo,536 PartType,537 Theme,538 > for Rmrk<C, Block>539where540 C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,541 C::Api: RmrkRuntimeApi<542 Block,543 AccountId,544 CollectionInfo,545 NftInfo,546 ResourceInfo,547 PropertyInfo,548 BaseInfo,549 PartType,550 Theme,551 >,552 AccountId: Decode + Encode,553 CollectionInfo: Decode,554 NftInfo: Decode,555 ResourceInfo: Decode,556 PropertyInfo: Decode,557 BaseInfo: Decode,558 PartType: Decode,559 Theme: Decode,560 Block: BlockT,561{562 pass_method!(last_collection_idx() -> RmrkCollectionId, rmrk_api);563 pass_method!(collection_by_id(id: RmrkCollectionId) -> Option<CollectionInfo>, rmrk_api);564 pass_method!(nft_by_id(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Option<NftInfo>, rmrk_api);565 pass_method!(account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Vec<RmrkNftId>, rmrk_api);566 pass_method!(nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Vec<RmrkNftChild>, rmrk_api);567 pass_method!(568 collection_properties(569 collection_id: RmrkCollectionId,570571 #[map(|keys| string_keys_to_bytes_keys(keys))]572 filter_keys: Option<Vec<String>>573 ) -> Vec<PropertyInfo>,574 rmrk_api575 );576 pass_method!(577 nft_properties(578 collection_id: RmrkCollectionId,579 nft_id: RmrkNftId,580581 #[map(|keys| string_keys_to_bytes_keys(keys))]582 filter_keys: Option<Vec<String>>583 ) -> Vec<PropertyInfo>,584 rmrk_api585 );586 pass_method!(nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Vec<ResourceInfo>, rmrk_api);587 pass_method!(nft_resource_priority(collection_id: RmrkCollectionId, nft_id: RmrkNftId, resource_id: RmrkResourceId) -> Option<u32>, rmrk_api);588 pass_method!(base(base_id: RmrkBaseId) -> Option<BaseInfo>, rmrk_api);589 pass_method!(base_parts(base_id: RmrkBaseId) -> Vec<PartType>, rmrk_api);590 pass_method!(theme_names(base_id: RmrkBaseId) -> Vec<RmrkThemeName>, rmrk_api);591 pass_method!(592 theme(593 base_id: RmrkBaseId,594595 #[map(|n| n.into_bytes())]596 theme_name: String,597598 #[map(|keys| string_keys_to_bytes_keys(keys))]599 filter_keys: Option<Vec<String>>600 ) -> Option<Theme>, rmrk_api);601}602603fn string_keys_to_bytes_keys(keys: Option<Vec<String>>) -> Option<Vec<Vec<u8>>> {604 keys.map(|keys| keys.into_iter().map(|key| key.into_bytes()).collect())605}pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -334,7 +334,7 @@
///
/// * collection_id: ID of the collection to which the item belongs.
///
- /// * item_id: ID of the item trasnferred.
+ /// * item_id: ID of the item transferred.
///
/// * sender: Original owner of the item.
///
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -58,13 +58,13 @@
pub enum Error<T> {
/// Not Fungible item data used to mint in Fungible collection.
NotFungibleDataUsedToMintFungibleCollectionToken,
- /// Not default id passed as TokenId argument
+ /// Not default id passed as TokenId argument.
FungibleItemsHaveNoId,
- /// Tried to set data for fungible item
+ /// Tried to set data for fungible item.
FungibleItemsDontHaveData,
- /// Fungible token does not support nested
+ /// Fungible token does not support nesting.
FungibleDisallowsNesting,
- /// Setting item properties is not allowed
+ /// Setting item properties is not allowed.
SettingPropertiesNotAllowed,
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -171,7 +171,7 @@
QueryKind = ValueQuery,
>;
- /// Amount of tokens owned in a collection.s
+ /// Amount of tokens owned in a collection.
#[pallet::storage]
pub type AccountBalance<T: Config> = StorageNMap<
Key = (
@@ -182,7 +182,7 @@
QueryKind = ValueQuery,
>;
- /// todo doc
+ /// todo:doc
#[pallet::storage]
pub type Allowance<T: Config> = StorageNMap<
Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -64,13 +64,13 @@
pub enum Error<T> {
/// Not Refungible item data used to mint in Refungible collection.
NotRefungibleDataUsedToMintFungibleCollectionToken,
- /// Maximum refungibility exceeded
+ /// Maximum refungibility exceeded.
WrongRefungiblePieces,
- /// Refungible token can't be repartitioned by user who isn't owns all pieces
+ /// Refungible token can't be repartitioned by user who isn't owns all pieces.
RepartitionWhileNotOwningAllPieces,
- /// Refungible token can't nest other tokens
+ /// Refungible token can't nest other tokens.
RefungibleDisallowsNesting,
- /// Setting item properties is not allowed
+ /// Setting item properties is not allowed.
SettingPropertiesNotAllowed,
}
@@ -605,7 +605,6 @@
Ok(())
}
- /// todo:doc oh look, a precedent. not pub, too. but it has an unclear use-case.
/// Returns allowance, which should be set after transaction
fn check_allowed(
collection: &RefungibleHandle<T>,
pallets/structure/src/lib.rsdiffbeforeafterboth--- a/pallets/structure/src/lib.rs
+++ b/pallets/structure/src/lib.rs
@@ -31,7 +31,7 @@
DepthLimit,
/// While iterating over children, reached the breadth limit.
BreadthLimit,
- /// Couldn't find the token owner that is a token. Perhaps, it does not yet exist. todo:doc? rephrase?
+ /// Couldn't find the token owner that is itself a token.
TokenNotFound,
}
primitives/data-structs/src/lib.rsdiffbeforeafterboth--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -286,7 +286,7 @@
}
}
-/// Collection parameters, used in storage (see [`RpcCollection`] for the RPC version)
+/// Collection parameters, used in storage (see [`RpcCollection`] for the RPC version).
#[struct_versioning::versioned(version = 2, upper)]
#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, MaxEncodedLen)]
pub struct Collection<AccountId> {
@@ -327,7 +327,7 @@
pub meta_update_permission: MetaUpdatePermission,
}
-/// Collection parameters, used in RPC calls (see [`Collection`] for the storage version)
+/// Collection parameters, used in RPC calls (see [`Collection`] for the storage version).
#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
pub struct RpcCollection<AccountId> {
@@ -568,7 +568,7 @@
ReFungible(CreateReFungibleData),
}
-/// Explicit NFT creation data with meta parameters
+/// Explicit NFT creation data with meta parameters.
#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]
#[derivative(Debug)]
pub struct CreateNftExData<CrossAccountId> {
@@ -577,7 +577,7 @@
pub owner: CrossAccountId,
}
-/// Explicit RFT creation data with meta parameters
+/// Explicit RFT creation data with meta parameters.
#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]
#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]
pub struct CreateRefungibleExData<CrossAccountId> {
@@ -587,7 +587,7 @@
pub users: BoundedBTreeMap<CrossAccountId, u128, ConstU32<MAX_ITEMS_PER_BATCH>>,
}
-/// Explicit item creation data with meta parameters, namely the owner
+/// Explicit item creation data with meta parameters, namely the owner.
#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, TypeInfo, Derivative)]
#[derivative(Debug(bound = "CrossAccountId: fmt::Debug + Ord"))]
pub enum CreateItemExData<CrossAccountId> {
@@ -635,7 +635,7 @@
}
}
-/// Token's address, dictated by its collection and token IDs
+/// Token's address, dictated by its collection and token IDs.
#[derive(Encode, Decode, MaxEncodedLen, PartialEq, Clone, Debug, TypeInfo)]
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
// todo possibly rename to be used generally as an address pair