difftreelog
fix some rpc fixes
in: master
3 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 sp_runtime::traits::{AtLeast32BitUnsigned, Member};27use up_data_structs::{28 RpcCollection, CollectionId, CollectionStats, CollectionLimits, TokenId, Property,29 PropertyKeyPermission, TokenData, TokenChild,30};31use sp_api::{BlockId, BlockT, ProvideRuntimeApi, ApiExt};32use sp_blockchain::HeaderBackend;33use up_rpc::UniqueApi as UniqueRuntimeApi;34use app_promotion_rpc::AppPromotionApi as AppPromotionRuntimeApi;3536// RMRK37use rmrk_rpc::RmrkApi as RmrkRuntimeApi;38use up_data_structs::{39 RmrkCollectionId, RmrkNftId, RmrkBaseId, RmrkNftChild, RmrkThemeName, RmrkResourceId,40};4142pub use app_promotion_unique_rpc::AppPromotionApiServer;43pub use rmrk_unique_rpc::RmrkApiServer;4445#[rpc(server)]46#[async_trait]47pub trait UniqueApi<BlockHash, BlockNumber, CrossAccountId, AccountId> {48 /// Get tokens owned by account.49 #[method(name = "unique_accountTokens")]50 fn account_tokens(51 &self,52 collection: CollectionId,53 account: CrossAccountId,54 at: Option<BlockHash>,55 ) -> Result<Vec<TokenId>>;5657 /// Get tokens contained within a collection.58 #[method(name = "unique_collectionTokens")]59 fn collection_tokens(60 &self,61 collection: CollectionId,62 at: Option<BlockHash>,63 ) -> Result<Vec<TokenId>>;6465 /// Check if the token exists.66 #[method(name = "unique_tokenExists")]67 fn token_exists(68 &self,69 collection: CollectionId,70 token: TokenId,71 at: Option<BlockHash>,72 ) -> Result<bool>;7374 /// Get the token owner.75 #[method(name = "unique_tokenOwner")]76 fn token_owner(77 &self,78 collection: CollectionId,79 token: TokenId,80 at: Option<BlockHash>,81 ) -> Result<Option<CrossAccountId>>;8283 /// Returns 10 tokens owners in no particular order.84 #[method(name = "unique_tokenOwners")]85 fn token_owners(86 &self,87 collection: CollectionId,88 token: TokenId,89 at: Option<BlockHash>,90 ) -> Result<Vec<CrossAccountId>>;9192 /// Get the topmost token owner in the hierarchy of a possibly nested token.93 #[method(name = "unique_topmostTokenOwner")]94 fn topmost_token_owner(95 &self,96 collection: CollectionId,97 token: TokenId,98 at: Option<BlockHash>,99 ) -> Result<Option<CrossAccountId>>;100101 /// Get tokens nested directly into the token.102 #[method(name = "unique_tokenChildren")]103 fn token_children(104 &self,105 collection: CollectionId,106 token: TokenId,107 at: Option<BlockHash>,108 ) -> Result<Vec<TokenChild>>;109110 /// Get collection properties, optionally limited to the provided keys.111 #[method(name = "unique_collectionProperties")]112 fn collection_properties(113 &self,114 collection: CollectionId,115 keys: Option<Vec<String>>,116 at: Option<BlockHash>,117 ) -> Result<Vec<Property>>;118119 /// Get token properties, optionally limited to the provided keys.120 #[method(name = "unique_tokenProperties")]121 fn token_properties(122 &self,123 collection: CollectionId,124 token_id: TokenId,125 keys: Option<Vec<String>>,126 at: Option<BlockHash>,127 ) -> Result<Vec<Property>>;128129 /// Get property permissions, optionally limited to the provided keys.130 #[method(name = "unique_propertyPermissions")]131 fn property_permissions(132 &self,133 collection: CollectionId,134 keys: Option<Vec<String>>,135 at: Option<BlockHash>,136 ) -> Result<Vec<PropertyKeyPermission>>;137138 /// Get token data, including properties, optionally limited to the provided keys, and total pieces for an RFT.139 #[method(name = "unique_tokenData")]140 fn token_data(141 &self,142 collection: CollectionId,143 token_id: TokenId,144 keys: Option<Vec<String>>,145 at: Option<BlockHash>,146 ) -> Result<TokenData<CrossAccountId>>;147148 /// Get the amount of distinctive tokens present in a collection.149 #[method(name = "unique_totalSupply")]150 fn total_supply(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<u32>;151152 /// Get the amount of any user tokens owned by an account.153 #[method(name = "unique_accountBalance")]154 fn account_balance(155 &self,156 collection: CollectionId,157 account: CrossAccountId,158 at: Option<BlockHash>,159 ) -> Result<u32>;160161 /// Get the amount of a specific token owned by an account.162 #[method(name = "unique_balance")]163 fn balance(164 &self,165 collection: CollectionId,166 account: CrossAccountId,167 token: TokenId,168 at: Option<BlockHash>,169 ) -> Result<String>;170171 /// Get the amount of currently possible sponsored transactions on a token for the fee to be taken off a sponsor.172 #[method(name = "unique_allowance")]173 fn allowance(174 &self,175 collection: CollectionId,176 sender: CrossAccountId,177 spender: CrossAccountId,178 token: TokenId,179 at: Option<BlockHash>,180 ) -> Result<String>;181182 /// Get the list of admin accounts of a collection.183 #[method(name = "unique_adminlist")]184 fn adminlist(185 &self,186 collection: CollectionId,187 at: Option<BlockHash>,188 ) -> Result<Vec<CrossAccountId>>;189190 /// Get the list of accounts allowed to operate within a collection.191 #[method(name = "unique_allowlist")]192 fn allowlist(193 &self,194 collection: CollectionId,195 at: Option<BlockHash>,196 ) -> Result<Vec<CrossAccountId>>;197198 /// Check if a user is allowed to operate within a collection.199 #[method(name = "unique_allowed")]200 fn allowed(201 &self,202 collection: CollectionId,203 user: CrossAccountId,204 at: Option<BlockHash>,205 ) -> Result<bool>;206207 /// Get the last token ID created in a collection.208 #[method(name = "unique_lastTokenId")]209 fn last_token_id(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<TokenId>;210211 /// Get collection info by the specified ID.212 #[method(name = "unique_collectionById")]213 fn collection_by_id(214 &self,215 collection: CollectionId,216 at: Option<BlockHash>,217 ) -> Result<Option<RpcCollection<AccountId>>>;218219 /// Get chain stats about collections.220 #[method(name = "unique_collectionStats")]221 fn collection_stats(&self, at: Option<BlockHash>) -> Result<CollectionStats>;222223 /// Get the number of blocks until sponsoring a transaction is available.224 #[method(name = "unique_nextSponsored")]225 fn next_sponsored(226 &self,227 collection: CollectionId,228 account: CrossAccountId,229 token: TokenId,230 at: Option<BlockHash>,231 ) -> Result<Option<u64>>;232233 /// Get effective collection limits. If not explicitly set, get the chain defaults.234 #[method(name = "unique_effectiveCollectionLimits")]235 fn effective_collection_limits(236 &self,237 collection_id: CollectionId,238 at: Option<BlockHash>,239 ) -> Result<Option<CollectionLimits>>;240241 /// Get the total amount of pieces of an RFT.242 #[method(name = "unique_totalPieces")]243 fn total_pieces(244 &self,245 collection_id: CollectionId,246 token_id: TokenId,247 at: Option<BlockHash>,248 ) -> Result<Option<String>>;249}250251mod app_promotion_unique_rpc {252 use super::*;253 254 #[rpc(server)]255 #[async_trait]256 pub trait AppPromotionApi<BlockHash, BlockNumber, CrossAccountId, AccountId> {257 /// Returns the total amount of staked tokens.258 #[method(name = "appPromotion_totalStaked")]259 fn total_staked(&self, staker: Option<CrossAccountId>, at: Option<BlockHash>)260 -> Result<String>;261262 ///Returns the total amount of staked tokens per block when staked.263 #[method(name = "appPromotion_totalStakedPerBlock")]264 fn total_staked_per_block(265 &self,266 staker: CrossAccountId,267 at: Option<BlockHash>,268 ) -> Result<Vec<(BlockNumber, String)>>;269270 /// Returns the total amount locked by staking tokens.271 #[method(name = "appPromotion_totalStakingLocked")]272 fn total_staking_locked(&self, staker: CrossAccountId, at: Option<BlockHash>)273 -> Result<String>;274275 /// Returns the total amount of tokens pending withdrawal from staking.276 #[method(name = "appPromotion_pendingUnstake")]277 fn pending_unstake(278 &self,279 staker: Option<CrossAccountId>,280 at: Option<BlockHash>,281 ) -> Result<String>;282283 /// Returns the total amount of tokens pending withdrawal from staking per block.284 #[method(name = "appPromotion_pendingUnstakePerBlock")]285 fn pending_unstake_per_block(286 &self,287 staker: CrossAccountId,288 at: Option<BlockHash>,289 ) -> Result<Vec<(BlockNumber, String)>>;290 }291}292293mod rmrk_unique_rpc {294 use super::*;295296 #[rpc(server)]297 #[async_trait]298 pub trait RmrkApi<299 BlockHash,300 AccountId,301 CollectionInfo,302 NftInfo,303 ResourceInfo,304 PropertyInfo,305 BaseInfo,306 PartType,307 Theme,308 >309 {310 /// Get the latest created collection ID.311 #[method(name = "rmrk_lastCollectionIdx")]312 fn last_collection_idx(&self, at: Option<BlockHash>) -> Result<RmrkCollectionId>;313314 /// Get collection info by ID.315 #[method(name = "rmrk_collectionById")]316 fn collection_by_id(317 &self,318 id: RmrkCollectionId,319 at: Option<BlockHash>,320 ) -> Result<Option<CollectionInfo>>;321322 /// Get NFT info by collection and NFT IDs.323 #[method(name = "rmrk_nftById")]324 fn nft_by_id(325 &self,326 collection_id: RmrkCollectionId,327 nft_id: RmrkNftId,328 at: Option<BlockHash>,329 ) -> Result<Option<NftInfo>>;330331 /// Get tokens owned by an account in a collection.332 #[method(name = "rmrk_accountTokens")]333 fn account_tokens(334 &self,335 account_id: AccountId,336 collection_id: RmrkCollectionId,337 at: Option<BlockHash>,338 ) -> Result<Vec<RmrkNftId>>;339340 /// Get tokens nested in an NFT - its direct children (not the children's children).341 #[method(name = "rmrk_nftChildren")]342 fn nft_children(343 &self,344 collection_id: RmrkCollectionId,345 nft_id: RmrkNftId,346 at: Option<BlockHash>,347 ) -> Result<Vec<RmrkNftChild>>;348349 /// Get collection properties, created by the user - not the proxy-specific properties.350 #[method(name = "rmrk_collectionProperties")]351 fn collection_properties(352 &self,353 collection_id: RmrkCollectionId,354 filter_keys: Option<Vec<String>>,355 at: Option<BlockHash>,356 ) -> Result<Vec<PropertyInfo>>;357358 /// Get NFT properties, created by the user - not the proxy-specific properties.359 #[method(name = "rmrk_nftProperties")]360 fn nft_properties(361 &self,362 collection_id: RmrkCollectionId,363 nft_id: RmrkNftId,364 filter_keys: Option<Vec<String>>,365 at: Option<BlockHash>,366 ) -> Result<Vec<PropertyInfo>>;367368 /// Get data of resources of an NFT.369 #[method(name = "rmrk_nftResources")]370 fn nft_resources(371 &self,372 collection_id: RmrkCollectionId,373 nft_id: RmrkNftId,374 at: Option<BlockHash>,375 ) -> Result<Vec<ResourceInfo>>;376377 /// Get the priority of a resource in an NFT.378 #[method(name = "rmrk_nftResourcePriority")]379 fn nft_resource_priority(380 &self,381 collection_id: RmrkCollectionId,382 nft_id: RmrkNftId,383 resource_id: RmrkResourceId,384 at: Option<BlockHash>,385 ) -> Result<Option<u32>>;386387 /// Get base info by its ID.388 #[method(name = "rmrk_base")]389 fn base(&self, base_id: RmrkBaseId, at: Option<BlockHash>) -> Result<Option<BaseInfo>>;390391 /// Get all parts of a base.392 #[method(name = "rmrk_baseParts")]393 fn base_parts(&self, base_id: RmrkBaseId, at: Option<BlockHash>) -> Result<Vec<PartType>>;394395 /// Get the theme names belonging to a base.396 #[method(name = "rmrk_themeNames")]397 fn theme_names(398 &self,399 base_id: RmrkBaseId,400 at: Option<BlockHash>,401 ) -> Result<Vec<RmrkThemeName>>;402403 /// Get theme info, including properties, optionally limited to the provided keys.404 #[method(name = "rmrk_themes")]405 fn theme(406 &self,407 base_id: RmrkBaseId,408 theme_name: String,409 filter_keys: Option<Vec<String>>,410 at: Option<BlockHash>,411 ) -> Result<Option<Theme>>;412 }413}414415pub struct Unique<C, P> {416 client: Arc<C>,417 _marker: std::marker::PhantomData<P>,418}419420impl<C, P> Unique<C, P> {421 pub fn new(client: Arc<C>) -> Self {422 Self {423 client,424 _marker: Default::default(),425 }426 }427}428429pub struct AppPromotion<C, P> {430 client: Arc<C>,431 _marker: std::marker::PhantomData<P>,432}433434impl<C, P> AppPromotion<C, P> {435 pub fn new(client: Arc<C>) -> Self {436 Self {437 client,438 _marker: Default::default(),439 }440 }441}442443pub struct Rmrk<C, P> {444 client: Arc<C>,445 _marker: std::marker::PhantomData<P>,446}447448impl<C, P> Rmrk<C, P> {449 pub fn new(client: Arc<C>) -> Self {450 Self {451 client,452 _marker: Default::default(),453 }454 }455}456457macro_rules! pass_method {458 (459 $method_name:ident(460 $($(#[map(|$map_arg:ident| $map:expr)])? $name:ident: $ty:ty),* $(,)?461 ) -> $result:ty $(=> $mapper:expr)?,462 //$runtime_name:ident $(<$($lt: tt),+>)*463 $runtime_api_macro:ident464 $(; changed_in $ver:expr, $changed_method_name:ident ($($changed_name:expr), * $(,)?) => $fixer:expr)*465 ) => {466 fn $method_name(467 &self,468 $(469 $name: $ty,470 )*471 at: Option<<Block as BlockT>::Hash>,472 ) -> Result<$result> {473 let api = self.client.runtime_api();474 let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash));475 let _api_version = if let Ok(Some(api_version)) =476 api.api_version::<$runtime_api_macro!()>(&at)477 {478 api_version479 } else {480 // unreachable for our runtime481 return Err(anyhow!("api is not available").into())482 };483484 let result = $(if _api_version < $ver {485 api.$changed_method_name(&at, $($changed_name),*).map(|r| r.map($fixer))486 } else)*487 { api.$method_name(&at, $($((|$map_arg: $ty| $map))? ($name)),*) };488489 Ok(result490 .map_err(|e| anyhow!("unable to query: {e}"))?491 .map_err(|e| anyhow!("runtime error: {e:?}"))$(.map($mapper))??)492 }493 };494}495496macro_rules! unique_api {497 () => {498 dyn UniqueRuntimeApi<Block, BlockNumber, CrossAccountId, AccountId>499 };500}501502macro_rules! app_promotion_api {503 () => {504 dyn AppPromotionRuntimeApi<Block, BlockNumber, CrossAccountId, AccountId>505 };506}507508macro_rules! rmrk_api {509 () => {510 dyn RmrkRuntimeApi<Block, AccountId, CollectionInfo, NftInfo, ResourceInfo, PropertyInfo, BaseInfo, PartType, Theme>511 };512}513514#[allow(deprecated)]515impl<C, Block, BlockNumber, CrossAccountId, AccountId>516 UniqueApiServer<<Block as BlockT>::Hash, BlockNumber, CrossAccountId, AccountId>517 for Unique<C, Block>518where519 Block: BlockT,520 BlockNumber: Decode + Member + AtLeast32BitUnsigned,521 AccountId: Decode,522 C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,523 C::Api: UniqueRuntimeApi<Block, BlockNumber, CrossAccountId, AccountId>,524 CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,525{526 pass_method!(527 account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId>, unique_api528 );529 pass_method!(530 collection_tokens(collection: CollectionId) -> Vec<TokenId>, unique_api531 );532 pass_method!(533 token_exists(collection: CollectionId, token: TokenId) -> bool, unique_api534 );535 pass_method!(536 token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>, unique_api537 );538 pass_method!(539 topmost_token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>, unique_api540 );541 pass_method!(token_children(collection: CollectionId, token: TokenId) -> Vec<TokenChild>, unique_api);542 pass_method!(total_supply(collection: CollectionId) -> u32, unique_api);543 pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32, unique_api);544 pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string(), unique_api);545 pass_method!(546 allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string(),547 unique_api548 );549550 pass_method!(collection_properties(551 collection: CollectionId,552553 #[map(|keys| string_keys_to_bytes_keys(keys))]554 keys: Option<Vec<String>>555 ) -> Vec<Property>, unique_api);556557 pass_method!(token_properties(558 collection: CollectionId,559 token_id: TokenId,560561 #[map(|keys| string_keys_to_bytes_keys(keys))]562 keys: Option<Vec<String>>563 ) -> Vec<Property>, unique_api);564565 pass_method!(property_permissions(566 collection: CollectionId,567568 #[map(|keys| string_keys_to_bytes_keys(keys))]569 keys: Option<Vec<String>>570 ) -> Vec<PropertyKeyPermission>, unique_api);571572 pass_method!(token_data(573 collection: CollectionId,574 token_id: TokenId,575576 #[map(|keys| string_keys_to_bytes_keys(keys))]577 keys: Option<Vec<String>>,578 ) -> TokenData<CrossAccountId>, unique_api);579580 pass_method!(adminlist(collection: CollectionId) -> Vec<CrossAccountId>, unique_api);581 pass_method!(allowlist(collection: CollectionId) -> Vec<CrossAccountId>, unique_api);582 pass_method!(allowed(collection: CollectionId, user: CrossAccountId) -> bool, unique_api);583 pass_method!(last_token_id(collection: CollectionId) -> TokenId, unique_api);584 pass_method!(collection_by_id(collection: CollectionId) -> Option<RpcCollection<AccountId>>, unique_api);585 pass_method!(collection_stats() -> CollectionStats, unique_api);586 pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);587 pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>, unique_api);588 pass_method!(total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<String> => |o| o.map(|number| number.to_string()) , unique_api);589 pass_method!(token_owners(collection: CollectionId, token: TokenId) -> Vec<CrossAccountId>, unique_api);590}591592impl<C, Block, BlockNumber, CrossAccountId, AccountId>593 app_promotion_unique_rpc::AppPromotionApiServer<<Block as BlockT>::Hash, BlockNumber, CrossAccountId, AccountId>594 for AppPromotion<C, Block>595where596 Block: BlockT,597 BlockNumber: Decode + Member + AtLeast32BitUnsigned,598 AccountId: Decode,599 C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,600 C::Api: AppPromotionRuntimeApi<Block, BlockNumber, CrossAccountId, AccountId>,601 CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,602{603 pass_method!(total_staked(staker: Option<CrossAccountId>) -> String => |v| v.to_string(), app_promotion_api);604 pass_method!(total_staked_per_block(staker: CrossAccountId) -> Vec<(BlockNumber, String)> =>605 |v| v606 .into_iter()607 .map(|(b, a)| (b, a.to_string()))608 .collect::<Vec<_>>(), unique_api);609 pass_method!(total_staking_locked(staker: CrossAccountId) -> String => |v| v.to_string(), unique_api);610 pass_method!(pending_unstake(staker: Option<CrossAccountId>) -> String => |v| v.to_string(), unique_api);611 pass_method!(pending_unstake_per_block(staker: CrossAccountId) -> Vec<(BlockNumber, String)> =>612 |v| v613 .into_iter()614 .map(|(b, a)| (b, a.to_string()))615 .collect::<Vec<_>>(), unique_api);616}617618#[allow(deprecated)]619impl<620 C,621 Block,622 AccountId,623 CollectionInfo,624 NftInfo,625 ResourceInfo,626 PropertyInfo,627 BaseInfo,628 PartType,629 Theme,630 >631 rmrk_unique_rpc::RmrkApiServer<632 <Block as BlockT>::Hash,633 AccountId,634 CollectionInfo,635 NftInfo,636 ResourceInfo,637 PropertyInfo,638 BaseInfo,639 PartType,640 Theme,641 > for Rmrk<C, Block>642where643 C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,644 C::Api: RmrkRuntimeApi<645 Block,646 AccountId,647 CollectionInfo,648 NftInfo,649 ResourceInfo,650 PropertyInfo,651 BaseInfo,652 PartType,653 Theme,654 >,655 AccountId: Decode + Encode,656 CollectionInfo: Decode,657 NftInfo: Decode,658 ResourceInfo: Decode,659 PropertyInfo: Decode,660 BaseInfo: Decode,661 PartType: Decode,662 Theme: Decode,663 Block: BlockT,664{665 pass_method!(last_collection_idx() -> RmrkCollectionId, rmrk_api);666 pass_method!(collection_by_id(id: RmrkCollectionId) -> Option<CollectionInfo>, rmrk_api);667 pass_method!(nft_by_id(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Option<NftInfo>, rmrk_api);668 pass_method!(account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Vec<RmrkNftId>, rmrk_api);669 pass_method!(nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Vec<RmrkNftChild>, rmrk_api);670 pass_method!(671 collection_properties(672 collection_id: RmrkCollectionId,673674 #[map(|keys| string_keys_to_bytes_keys(keys))]675 filter_keys: Option<Vec<String>>676 ) -> Vec<PropertyInfo>,677 rmrk_api678 );679 pass_method!(680 nft_properties(681 collection_id: RmrkCollectionId,682 nft_id: RmrkNftId,683684 #[map(|keys| string_keys_to_bytes_keys(keys))]685 filter_keys: Option<Vec<String>>686 ) -> Vec<PropertyInfo>,687 rmrk_api688 );689 pass_method!(nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Vec<ResourceInfo>, rmrk_api);690 pass_method!(nft_resource_priority(collection_id: RmrkCollectionId, nft_id: RmrkNftId, resource_id: RmrkResourceId) -> Option<u32>, rmrk_api);691 pass_method!(base(base_id: RmrkBaseId) -> Option<BaseInfo>, rmrk_api);692 pass_method!(base_parts(base_id: RmrkBaseId) -> Vec<PartType>, rmrk_api);693 pass_method!(theme_names(base_id: RmrkBaseId) -> Vec<RmrkThemeName>, rmrk_api);694 pass_method!(695 theme(696 base_id: RmrkBaseId,697698 #[map(|n| n.into_bytes())]699 theme_name: String,700701 #[map(|keys| string_keys_to_bytes_keys(keys))]702 filter_keys: Option<Vec<String>>703 ) -> Option<Theme>, rmrk_api);704}705706fn string_keys_to_bytes_keys(keys: Option<Vec<String>>) -> Option<Vec<Vec<u8>>> {707 keys.map(|keys| keys.into_iter().map(|key| key.into_bytes()).collect())708}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 sp_runtime::traits::{AtLeast32BitUnsigned, Member};27use up_data_structs::{28 RpcCollection, CollectionId, CollectionStats, CollectionLimits, TokenId, Property,29 PropertyKeyPermission, TokenData, TokenChild,30};31use sp_api::{BlockId, BlockT, ProvideRuntimeApi, ApiExt};32use sp_blockchain::HeaderBackend;33use up_rpc::UniqueApi as UniqueRuntimeApi;34use app_promotion_rpc::AppPromotionApi as AppPromotionRuntimeApi;3536// RMRK37use rmrk_rpc::RmrkApi as RmrkRuntimeApi;38use up_data_structs::{39 RmrkCollectionId, RmrkNftId, RmrkBaseId, RmrkNftChild, RmrkThemeName, RmrkResourceId,40};4142pub use app_promotion_unique_rpc::AppPromotionApiServer;43pub use rmrk_unique_rpc::RmrkApiServer;4445#[rpc(server)]46#[async_trait]47pub trait UniqueApi<BlockHash, BlockNumber, CrossAccountId, AccountId> {48 /// Get tokens owned by account.49 #[method(name = "unique_accountTokens")]50 fn account_tokens(51 &self,52 collection: CollectionId,53 account: CrossAccountId,54 at: Option<BlockHash>,55 ) -> Result<Vec<TokenId>>;5657 /// Get tokens contained within a collection.58 #[method(name = "unique_collectionTokens")]59 fn collection_tokens(60 &self,61 collection: CollectionId,62 at: Option<BlockHash>,63 ) -> Result<Vec<TokenId>>;6465 /// Check if the token exists.66 #[method(name = "unique_tokenExists")]67 fn token_exists(68 &self,69 collection: CollectionId,70 token: TokenId,71 at: Option<BlockHash>,72 ) -> Result<bool>;7374 /// Get the token owner.75 #[method(name = "unique_tokenOwner")]76 fn token_owner(77 &self,78 collection: CollectionId,79 token: TokenId,80 at: Option<BlockHash>,81 ) -> Result<Option<CrossAccountId>>;8283 /// Returns 10 tokens owners in no particular order.84 #[method(name = "unique_tokenOwners")]85 fn token_owners(86 &self,87 collection: CollectionId,88 token: TokenId,89 at: Option<BlockHash>,90 ) -> Result<Vec<CrossAccountId>>;9192 /// Get the topmost token owner in the hierarchy of a possibly nested token.93 #[method(name = "unique_topmostTokenOwner")]94 fn topmost_token_owner(95 &self,96 collection: CollectionId,97 token: TokenId,98 at: Option<BlockHash>,99 ) -> Result<Option<CrossAccountId>>;100101 /// Get tokens nested directly into the token.102 #[method(name = "unique_tokenChildren")]103 fn token_children(104 &self,105 collection: CollectionId,106 token: TokenId,107 at: Option<BlockHash>,108 ) -> Result<Vec<TokenChild>>;109110 /// Get collection properties, optionally limited to the provided keys.111 #[method(name = "unique_collectionProperties")]112 fn collection_properties(113 &self,114 collection: CollectionId,115 keys: Option<Vec<String>>,116 at: Option<BlockHash>,117 ) -> Result<Vec<Property>>;118119 /// Get token properties, optionally limited to the provided keys.120 #[method(name = "unique_tokenProperties")]121 fn token_properties(122 &self,123 collection: CollectionId,124 token_id: TokenId,125 keys: Option<Vec<String>>,126 at: Option<BlockHash>,127 ) -> Result<Vec<Property>>;128129 /// Get property permissions, optionally limited to the provided keys.130 #[method(name = "unique_propertyPermissions")]131 fn property_permissions(132 &self,133 collection: CollectionId,134 keys: Option<Vec<String>>,135 at: Option<BlockHash>,136 ) -> Result<Vec<PropertyKeyPermission>>;137138 /// Get token data, including properties, optionally limited to the provided keys, and total pieces for an RFT.139 #[method(name = "unique_tokenData")]140 fn token_data(141 &self,142 collection: CollectionId,143 token_id: TokenId,144 keys: Option<Vec<String>>,145 at: Option<BlockHash>,146 ) -> Result<TokenData<CrossAccountId>>;147148 /// Get the amount of distinctive tokens present in a collection.149 #[method(name = "unique_totalSupply")]150 fn total_supply(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<u32>;151152 /// Get the amount of any user tokens owned by an account.153 #[method(name = "unique_accountBalance")]154 fn account_balance(155 &self,156 collection: CollectionId,157 account: CrossAccountId,158 at: Option<BlockHash>,159 ) -> Result<u32>;160161 /// Get the amount of a specific token owned by an account.162 #[method(name = "unique_balance")]163 fn balance(164 &self,165 collection: CollectionId,166 account: CrossAccountId,167 token: TokenId,168 at: Option<BlockHash>,169 ) -> Result<String>;170171 /// Get the amount of currently possible sponsored transactions on a token for the fee to be taken off a sponsor.172 #[method(name = "unique_allowance")]173 fn allowance(174 &self,175 collection: CollectionId,176 sender: CrossAccountId,177 spender: CrossAccountId,178 token: TokenId,179 at: Option<BlockHash>,180 ) -> Result<String>;181182 /// Get the list of admin accounts of a collection.183 #[method(name = "unique_adminlist")]184 fn adminlist(185 &self,186 collection: CollectionId,187 at: Option<BlockHash>,188 ) -> Result<Vec<CrossAccountId>>;189190 /// Get the list of accounts allowed to operate within a collection.191 #[method(name = "unique_allowlist")]192 fn allowlist(193 &self,194 collection: CollectionId,195 at: Option<BlockHash>,196 ) -> Result<Vec<CrossAccountId>>;197198 /// Check if a user is allowed to operate within a collection.199 #[method(name = "unique_allowed")]200 fn allowed(201 &self,202 collection: CollectionId,203 user: CrossAccountId,204 at: Option<BlockHash>,205 ) -> Result<bool>;206207 /// Get the last token ID created in a collection.208 #[method(name = "unique_lastTokenId")]209 fn last_token_id(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<TokenId>;210211 /// Get collection info by the specified ID.212 #[method(name = "unique_collectionById")]213 fn collection_by_id(214 &self,215 collection: CollectionId,216 at: Option<BlockHash>,217 ) -> Result<Option<RpcCollection<AccountId>>>;218219 /// Get chain stats about collections.220 #[method(name = "unique_collectionStats")]221 fn collection_stats(&self, at: Option<BlockHash>) -> Result<CollectionStats>;222223 /// Get the number of blocks until sponsoring a transaction is available.224 #[method(name = "unique_nextSponsored")]225 fn next_sponsored(226 &self,227 collection: CollectionId,228 account: CrossAccountId,229 token: TokenId,230 at: Option<BlockHash>,231 ) -> Result<Option<u64>>;232233 /// Get effective collection limits. If not explicitly set, get the chain defaults.234 #[method(name = "unique_effectiveCollectionLimits")]235 fn effective_collection_limits(236 &self,237 collection_id: CollectionId,238 at: Option<BlockHash>,239 ) -> Result<Option<CollectionLimits>>;240241 /// Get the total amount of pieces of an RFT.242 #[method(name = "unique_totalPieces")]243 fn total_pieces(244 &self,245 collection_id: CollectionId,246 token_id: TokenId,247 at: Option<BlockHash>,248 ) -> Result<Option<String>>;249}250251mod app_promotion_unique_rpc {252 use super::*;253 254 #[rpc(server)]255 #[async_trait]256 pub trait AppPromotionApi<BlockHash, BlockNumber, CrossAccountId, AccountId> {257 /// Returns the total amount of staked tokens.258 #[method(name = "appPromotion_totalStaked")]259 fn total_staked(&self, staker: Option<CrossAccountId>, at: Option<BlockHash>)260 -> Result<String>;261262 ///Returns the total amount of staked tokens per block when staked.263 #[method(name = "appPromotion_totalStakedPerBlock")]264 fn total_staked_per_block(265 &self,266 staker: CrossAccountId,267 at: Option<BlockHash>,268 ) -> Result<Vec<(BlockNumber, String)>>;269270 /// Returns the total amount locked by staking tokens.271 #[method(name = "appPromotion_totalStakingLocked")]272 fn total_staking_locked(&self, staker: CrossAccountId, at: Option<BlockHash>)273 -> Result<String>;274275 /// Returns the total amount of tokens pending withdrawal from staking.276 #[method(name = "appPromotion_pendingUnstake")]277 fn pending_unstake(278 &self,279 staker: Option<CrossAccountId>,280 at: Option<BlockHash>,281 ) -> Result<String>;282283 /// Returns the total amount of tokens pending withdrawal from staking per block.284 #[method(name = "appPromotion_pendingUnstakePerBlock")]285 fn pending_unstake_per_block(286 &self,287 staker: CrossAccountId,288 at: Option<BlockHash>,289 ) -> Result<Vec<(BlockNumber, String)>>;290 }291}292293mod rmrk_unique_rpc {294 use super::*;295296 #[rpc(server)]297 #[async_trait]298 pub trait RmrkApi<299 BlockHash,300 AccountId,301 CollectionInfo,302 NftInfo,303 ResourceInfo,304 PropertyInfo,305 BaseInfo,306 PartType,307 Theme,308 >309 {310 /// Get the latest created collection ID.311 #[method(name = "rmrk_lastCollectionIdx")]312 fn last_collection_idx(&self, at: Option<BlockHash>) -> Result<RmrkCollectionId>;313314 /// Get collection info by ID.315 #[method(name = "rmrk_collectionById")]316 fn collection_by_id(317 &self,318 id: RmrkCollectionId,319 at: Option<BlockHash>,320 ) -> Result<Option<CollectionInfo>>;321322 /// Get NFT info by collection and NFT IDs.323 #[method(name = "rmrk_nftById")]324 fn nft_by_id(325 &self,326 collection_id: RmrkCollectionId,327 nft_id: RmrkNftId,328 at: Option<BlockHash>,329 ) -> Result<Option<NftInfo>>;330331 /// Get tokens owned by an account in a collection.332 #[method(name = "rmrk_accountTokens")]333 fn account_tokens(334 &self,335 account_id: AccountId,336 collection_id: RmrkCollectionId,337 at: Option<BlockHash>,338 ) -> Result<Vec<RmrkNftId>>;339340 /// Get tokens nested in an NFT - its direct children (not the children's children).341 #[method(name = "rmrk_nftChildren")]342 fn nft_children(343 &self,344 collection_id: RmrkCollectionId,345 nft_id: RmrkNftId,346 at: Option<BlockHash>,347 ) -> Result<Vec<RmrkNftChild>>;348349 /// Get collection properties, created by the user - not the proxy-specific properties.350 #[method(name = "rmrk_collectionProperties")]351 fn collection_properties(352 &self,353 collection_id: RmrkCollectionId,354 filter_keys: Option<Vec<String>>,355 at: Option<BlockHash>,356 ) -> Result<Vec<PropertyInfo>>;357358 /// Get NFT properties, created by the user - not the proxy-specific properties.359 #[method(name = "rmrk_nftProperties")]360 fn nft_properties(361 &self,362 collection_id: RmrkCollectionId,363 nft_id: RmrkNftId,364 filter_keys: Option<Vec<String>>,365 at: Option<BlockHash>,366 ) -> Result<Vec<PropertyInfo>>;367368 /// Get data of resources of an NFT.369 #[method(name = "rmrk_nftResources")]370 fn nft_resources(371 &self,372 collection_id: RmrkCollectionId,373 nft_id: RmrkNftId,374 at: Option<BlockHash>,375 ) -> Result<Vec<ResourceInfo>>;376377 /// Get the priority of a resource in an NFT.378 #[method(name = "rmrk_nftResourcePriority")]379 fn nft_resource_priority(380 &self,381 collection_id: RmrkCollectionId,382 nft_id: RmrkNftId,383 resource_id: RmrkResourceId,384 at: Option<BlockHash>,385 ) -> Result<Option<u32>>;386387 /// Get base info by its ID.388 #[method(name = "rmrk_base")]389 fn base(&self, base_id: RmrkBaseId, at: Option<BlockHash>) -> Result<Option<BaseInfo>>;390391 /// Get all parts of a base.392 #[method(name = "rmrk_baseParts")]393 fn base_parts(&self, base_id: RmrkBaseId, at: Option<BlockHash>) -> Result<Vec<PartType>>;394395 /// Get the theme names belonging to a base.396 #[method(name = "rmrk_themeNames")]397 fn theme_names(398 &self,399 base_id: RmrkBaseId,400 at: Option<BlockHash>,401 ) -> Result<Vec<RmrkThemeName>>;402403 /// Get theme info, including properties, optionally limited to the provided keys.404 #[method(name = "rmrk_themes")]405 fn theme(406 &self,407 base_id: RmrkBaseId,408 theme_name: String,409 filter_keys: Option<Vec<String>>,410 at: Option<BlockHash>,411 ) -> Result<Option<Theme>>;412 }413}414415macro_rules! define_struct_for_server_api {416 ($name:ident) => {417 pub struct $name<C, P> {418 client: Arc<C>,419 _marker: std::marker::PhantomData<P>,420 }421 422 impl<C, P> $name<C, P> {423 pub fn new(client: Arc<C>) -> Self {424 Self {425 client,426 _marker: Default::default(),427 }428 }429 }430 };431}432433define_struct_for_server_api!(Unique);434define_struct_for_server_api!(AppPromotion);435define_struct_for_server_api!(Rmrk);436437macro_rules! pass_method {438 (439 $method_name:ident(440 $($(#[map(|$map_arg:ident| $map:expr)])? $name:ident: $ty:ty),* $(,)?441 ) -> $result:ty $(=> $mapper:expr)?,442 //$runtime_name:ident $(<$($lt: tt),+>)*443 $runtime_api_macro:ident444 $(; changed_in $ver:expr, $changed_method_name:ident ($($changed_name:expr), * $(,)?) => $fixer:expr)*445 ) => {446 fn $method_name(447 &self,448 $(449 $name: $ty,450 )*451 at: Option<<Block as BlockT>::Hash>,452 ) -> Result<$result> {453 let api = self.client.runtime_api();454 let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash));455 let _api_version = if let Ok(Some(api_version)) =456 api.api_version::<$runtime_api_macro!()>(&at)457 {458 api_version459 } else {460 // unreachable for our runtime461 return Err(anyhow!("api is not available").into())462 };463464 let result = $(if _api_version < $ver {465 api.$changed_method_name(&at, $($changed_name),*).map(|r| r.map($fixer))466 } else)*467 { api.$method_name(&at, $($((|$map_arg: $ty| $map))? ($name)),*) };468469 Ok(result470 .map_err(|e| anyhow!("unable to query: {e}"))?471 .map_err(|e| anyhow!("runtime error: {e:?}"))$(.map($mapper))??)472 }473 };474}475476macro_rules! unique_api {477 () => {478 dyn UniqueRuntimeApi<Block, BlockNumber, CrossAccountId, AccountId>479 };480}481482macro_rules! app_promotion_api {483 () => {484 dyn AppPromotionRuntimeApi<Block, BlockNumber, CrossAccountId, AccountId>485 };486}487488macro_rules! rmrk_api {489 () => {490 dyn RmrkRuntimeApi<Block, AccountId, CollectionInfo, NftInfo, ResourceInfo, PropertyInfo, BaseInfo, PartType, Theme>491 };492}493494#[allow(deprecated)]495impl<C, Block, BlockNumber, CrossAccountId, AccountId>496 UniqueApiServer<<Block as BlockT>::Hash, BlockNumber, CrossAccountId, AccountId>497 for Unique<C, Block>498where499 Block: BlockT,500 BlockNumber: Decode + Member + AtLeast32BitUnsigned,501 AccountId: Decode,502 C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,503 C::Api: UniqueRuntimeApi<Block, BlockNumber, CrossAccountId, AccountId>,504 CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,505{506 pass_method!(507 account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId>, unique_api508 );509 pass_method!(510 collection_tokens(collection: CollectionId) -> Vec<TokenId>, unique_api511 );512 pass_method!(513 token_exists(collection: CollectionId, token: TokenId) -> bool, unique_api514 );515 pass_method!(516 token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>, unique_api517 );518 pass_method!(519 topmost_token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>, unique_api520 );521 pass_method!(token_children(collection: CollectionId, token: TokenId) -> Vec<TokenChild>, unique_api);522 pass_method!(total_supply(collection: CollectionId) -> u32, unique_api);523 pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32, unique_api);524 pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string(), unique_api);525 pass_method!(526 allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string(),527 unique_api528 );529530 pass_method!(collection_properties(531 collection: CollectionId,532533 #[map(|keys| string_keys_to_bytes_keys(keys))]534 keys: Option<Vec<String>>535 ) -> Vec<Property>, unique_api);536537 pass_method!(token_properties(538 collection: CollectionId,539 token_id: TokenId,540541 #[map(|keys| string_keys_to_bytes_keys(keys))]542 keys: Option<Vec<String>>543 ) -> Vec<Property>, unique_api);544545 pass_method!(property_permissions(546 collection: CollectionId,547548 #[map(|keys| string_keys_to_bytes_keys(keys))]549 keys: Option<Vec<String>>550 ) -> Vec<PropertyKeyPermission>, unique_api);551552 pass_method!(token_data(553 collection: CollectionId,554 token_id: TokenId,555556 #[map(|keys| string_keys_to_bytes_keys(keys))]557 keys: Option<Vec<String>>,558 ) -> TokenData<CrossAccountId>, unique_api);559560 pass_method!(adminlist(collection: CollectionId) -> Vec<CrossAccountId>, unique_api);561 pass_method!(allowlist(collection: CollectionId) -> Vec<CrossAccountId>, unique_api);562 pass_method!(allowed(collection: CollectionId, user: CrossAccountId) -> bool, unique_api);563 pass_method!(last_token_id(collection: CollectionId) -> TokenId, unique_api);564 pass_method!(collection_by_id(collection: CollectionId) -> Option<RpcCollection<AccountId>>, unique_api);565 pass_method!(collection_stats() -> CollectionStats, unique_api);566 pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);567 pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>, unique_api);568 pass_method!(total_pieces(collection_id: CollectionId, token_id: TokenId) -> Option<String> => |o| o.map(|number| number.to_string()) , unique_api);569 pass_method!(token_owners(collection: CollectionId, token: TokenId) -> Vec<CrossAccountId>, unique_api);570}571572impl<C, Block, BlockNumber, CrossAccountId, AccountId>573 app_promotion_unique_rpc::AppPromotionApiServer<<Block as BlockT>::Hash, BlockNumber, CrossAccountId, AccountId>574 for AppPromotion<C, Block>575where576 Block: BlockT,577 BlockNumber: Decode + Member + AtLeast32BitUnsigned,578 AccountId: Decode,579 C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,580 C::Api: AppPromotionRuntimeApi<Block, BlockNumber, CrossAccountId, AccountId>,581 CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,582{583 pass_method!(total_staked(staker: Option<CrossAccountId>) -> String => |v| v.to_string(), app_promotion_api);584 pass_method!(total_staked_per_block(staker: CrossAccountId) -> Vec<(BlockNumber, String)> =>585 |v| v586 .into_iter()587 .map(|(b, a)| (b, a.to_string()))588 .collect::<Vec<_>>(), app_promotion_api);589 pass_method!(total_staking_locked(staker: CrossAccountId) -> String => |v| v.to_string(), app_promotion_api);590 pass_method!(pending_unstake(staker: Option<CrossAccountId>) -> String => |v| v.to_string(), app_promotion_api);591 pass_method!(pending_unstake_per_block(staker: CrossAccountId) -> Vec<(BlockNumber, String)> =>592 |v| v593 .into_iter()594 .map(|(b, a)| (b, a.to_string()))595 .collect::<Vec<_>>(), app_promotion_api);596}597598#[allow(deprecated)]599impl<600 C,601 Block,602 AccountId,603 CollectionInfo,604 NftInfo,605 ResourceInfo,606 PropertyInfo,607 BaseInfo,608 PartType,609 Theme,610 >611 rmrk_unique_rpc::RmrkApiServer<612 <Block as BlockT>::Hash,613 AccountId,614 CollectionInfo,615 NftInfo,616 ResourceInfo,617 PropertyInfo,618 BaseInfo,619 PartType,620 Theme,621 > for Rmrk<C, Block>622where623 C: Send + Sync + 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,624 C::Api: RmrkRuntimeApi<625 Block,626 AccountId,627 CollectionInfo,628 NftInfo,629 ResourceInfo,630 PropertyInfo,631 BaseInfo,632 PartType,633 Theme,634 >,635 AccountId: Decode + Encode,636 CollectionInfo: Decode,637 NftInfo: Decode,638 ResourceInfo: Decode,639 PropertyInfo: Decode,640 BaseInfo: Decode,641 PartType: Decode,642 Theme: Decode,643 Block: BlockT,644{645 pass_method!(last_collection_idx() -> RmrkCollectionId, rmrk_api);646 pass_method!(collection_by_id(id: RmrkCollectionId) -> Option<CollectionInfo>, rmrk_api);647 pass_method!(nft_by_id(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Option<NftInfo>, rmrk_api);648 pass_method!(account_tokens(account_id: AccountId, collection_id: RmrkCollectionId) -> Vec<RmrkNftId>, rmrk_api);649 pass_method!(nft_children(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Vec<RmrkNftChild>, rmrk_api);650 pass_method!(651 collection_properties(652 collection_id: RmrkCollectionId,653654 #[map(|keys| string_keys_to_bytes_keys(keys))]655 filter_keys: Option<Vec<String>>656 ) -> Vec<PropertyInfo>,657 rmrk_api658 );659 pass_method!(660 nft_properties(661 collection_id: RmrkCollectionId,662 nft_id: RmrkNftId,663664 #[map(|keys| string_keys_to_bytes_keys(keys))]665 filter_keys: Option<Vec<String>>666 ) -> Vec<PropertyInfo>,667 rmrk_api668 );669 pass_method!(nft_resources(collection_id: RmrkCollectionId, nft_id: RmrkNftId) -> Vec<ResourceInfo>, rmrk_api);670 pass_method!(nft_resource_priority(collection_id: RmrkCollectionId, nft_id: RmrkNftId, resource_id: RmrkResourceId) -> Option<u32>, rmrk_api);671 pass_method!(base(base_id: RmrkBaseId) -> Option<BaseInfo>, rmrk_api);672 pass_method!(base_parts(base_id: RmrkBaseId) -> Vec<PartType>, rmrk_api);673 pass_method!(theme_names(base_id: RmrkBaseId) -> Vec<RmrkThemeName>, rmrk_api);674 pass_method!(675 theme(676 base_id: RmrkBaseId,677678 #[map(|n| n.into_bytes())]679 theme_name: String,680681 #[map(|keys| string_keys_to_bytes_keys(keys))]682 filter_keys: Option<Vec<String>>683 ) -> Option<Theme>, rmrk_api);684}685686fn string_keys_to_bytes_keys(keys: Option<Vec<String>>) -> Option<Vec<Vec<u8>>> {687 keys.map(|keys| keys.into_iter().map(|key| key.into_bytes()).collect())688}node/rpc/src/lib.rsdiffbeforeafterboth--- a/node/rpc/src/lib.rs
+++ b/node/rpc/src/lib.rs
@@ -38,7 +38,6 @@
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sc_service::TransactionPool;
-use uc_rpc::AppPromotion;
use std::{collections::BTreeMap, sync::Arc};
use up_common::types::opaque::{Hash, AccountId, RuntimeInstance, Index, Block, BlockNumber, Balance};
@@ -232,7 +231,7 @@
io.merge(Unique::new(client.clone()).into_rpc())?;
- // #[cfg(not(feature = "unique-runtime"))]
+ #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]
io.merge(AppPromotion::new(client.clone()).into_rpc())?;
#[cfg(not(feature = "unique-runtime"))]
tests/src/interfaces/augment-api-query.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-query.ts
+++ b/tests/src/interfaces/augment-api-query.ts
@@ -6,7 +6,7 @@
import '@polkadot/api-base/types/storage';
import type { ApiTypes, AugmentedQuery, QueryableStorageEntry } from '@polkadot/api-base/types';
-import type { BTreeMap, Bytes, Option, U256, U8aFixed, Vec, bool, u128, u16, u32, u64 } from '@polkadot/types-codec';
+import type { BTreeMap, Bytes, Option, U256, U8aFixed, Vec, bool, u128, u16, u32, u64, u8 } from '@polkadot/types-codec';
import type { AnyNumber, ITuple } from '@polkadot/types-codec/types';
import type { AccountId32, H160, H256 } from '@polkadot/types/interfaces/runtime';
import type { CumulusPalletDmpQueueConfigData, CumulusPalletDmpQueuePageIndexData, CumulusPalletParachainSystemRelayStateSnapshotMessagingStateSnapshot, CumulusPalletXcmpQueueInboundChannelDetails, CumulusPalletXcmpQueueOutboundChannelDetails, CumulusPalletXcmpQueueQueueConfigData, EthereumBlock, EthereumLog, EthereumReceiptReceiptV3, EthereumTransactionTransactionV2, FpRpcTransactionStatus, FrameSupportWeightsPerDispatchClassU64, FrameSystemAccountInfo, FrameSystemEventRecord, FrameSystemLastRuntimeUpgradeInfo, FrameSystemPhase, OrmlVestingVestingSchedule, PalletBalancesAccountData, PalletBalancesBalanceLock, PalletBalancesReleases, PalletBalancesReserveData, PalletEvmAccountBasicCrossAccountIdRepr, PalletEvmContractHelpersSponsoringModeT, PalletNonfungibleItemData, PalletRefungibleItemData, PalletTransactionPaymentReleases, PalletTreasuryProposal, PalletUniqueSchedulerScheduledV3, PhantomTypeUpDataStructs, PolkadotCorePrimitivesOutboundHrmpMessage, PolkadotPrimitivesV2AbridgedHostConfiguration, PolkadotPrimitivesV2PersistedValidationData, PolkadotPrimitivesV2UpgradeRestriction, SpRuntimeDigest, SpTrieStorageProof, UpDataStructsCollection, UpDataStructsCollectionStats, UpDataStructsProperties, UpDataStructsPropertiesMapPropertyPermission, UpDataStructsPropertyPermission, UpDataStructsPropertyScope, UpDataStructsSponsorshipStateBasicCrossAccountIdRepr, UpDataStructsTokenChild } from '@polkadot/types/lookup';
@@ -513,10 +513,10 @@
promotion: {
admin: AugmentedQuery<ApiType, () => Observable<Option<AccountId32>>, []> & QueryableStorageEntry<ApiType, []>;
/**
- * Stores the address of the staker for which the last revenue recalculation was performed.
+ * Stores hash a record for which the last revenue recalculation was performed.
* If `None`, then recalculation has not yet been performed or calculations have been completed for all stakers.
**/
- lastCalcucaltedStaker: AugmentedQuery<ApiType, () => Observable<Option<AccountId32>>, []> & QueryableStorageEntry<ApiType, []>;
+ nextCalculatedRecord: AugmentedQuery<ApiType, () => Observable<Option<ITuple<[AccountId32, u32]>>>, []> & QueryableStorageEntry<ApiType, []>;
/**
* Next target block when interest is recalculated
**/
@@ -530,6 +530,10 @@
**/
staked: AugmentedQuery<ApiType, (arg1: AccountId32 | string | Uint8Array, arg2: u32 | AnyNumber | Uint8Array) => Observable<ITuple<[u128, u32]>>, [AccountId32, u32]> & QueryableStorageEntry<ApiType, [AccountId32, u32]>;
/**
+ * Amount of stakes for an Account
+ **/
+ stakesPerAccount: AugmentedQuery<ApiType, (arg: AccountId32 | string | Uint8Array) => Observable<u8>, [AccountId32]> & QueryableStorageEntry<ApiType, [AccountId32]>;
+ /**
* A block when app-promotion has started .I think this is redundant, because we only need `NextInterestBlock`.
**/
startBlock: AugmentedQuery<ApiType, () => Observable<u32>, []> & QueryableStorageEntry<ApiType, []>;