From f9a4dd52b855ae23a39554d46ea55e1a1d9e484b Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Tue, 12 Apr 2022 08:42:49 +0000 Subject: [PATCH] fix(rpc): wrong return type for collectionTokens call --- --- a/client/rpc/src/lib.rs +++ b/client/rpc/src/lib.rs @@ -33,6 +33,12 @@ account: CrossAccountId, at: Option, ) -> Result>; + #[rpc(name = "unique_collectionTokens")] + fn collection_tokens( + &self, + collection: CollectionId, + at: Option, + ) -> Result>; #[rpc(name = "unique_tokenExists")] fn token_exists( &self, @@ -70,8 +76,6 @@ at: Option, ) -> Result>; - #[rpc(name = "unique_collectionTokens")] - fn collection_tokens(&self, collection: CollectionId, at: Option) -> Result; #[rpc(name = "unique_accountBalance")] fn account_balance( &self, @@ -226,6 +230,7 @@ CrossAccountId: pallet_evm::account::CrossAccountId, { pass_method!(account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec); + pass_method!(collection_tokens(collection: CollectionId) -> Vec); pass_method!(token_exists(collection: CollectionId, token: TokenId) -> bool); pass_method!( token_owner(collection: CollectionId, token: TokenId) -> Option; @@ -234,7 +239,6 @@ pass_method!(topmost_token_owner(collection: CollectionId, token: TokenId) -> Option); pass_method!(const_metadata(collection: CollectionId, token: TokenId) -> Vec); pass_method!(variable_metadata(collection: CollectionId, token: TokenId) -> Vec); - pass_method!(collection_tokens(collection: CollectionId) -> u32); pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32); pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string()); pass_method!(allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string()); --- a/pallets/common/src/lib.rs +++ b/pallets/common/src/lib.rs @@ -924,6 +924,7 @@ ) -> DispatchResult; fn account_tokens(&self, account: T::CrossAccountId) -> Vec; + fn collection_tokens(&self) -> Vec; fn token_exists(&self, token: TokenId) -> bool; fn last_token_id(&self) -> TokenId; @@ -931,8 +932,6 @@ fn const_metadata(&self, token: TokenId) -> Vec; fn variable_metadata(&self, token: TokenId) -> Vec; - /// How many tokens collection contains (Applicable to nonfungible/refungible) - fn collection_tokens(&self) -> u32; /// Amount of different tokens account has (Applicable to nonfungible/refungible) fn account_balance(&self, account: T::CrossAccountId) -> u32; /// Amount of specific token account have (Applicable to fungible/refungible) --- a/pallets/fungible/src/common.rs +++ b/pallets/fungible/src/common.rs @@ -270,8 +270,8 @@ Vec::new() } - fn collection_tokens(&self) -> u32 { - 1 + fn collection_tokens(&self) -> Vec { + vec![TokenId::default()] } fn account_balance(&self, account: T::CrossAccountId) -> u32 { --- a/pallets/nonfungible/src/common.rs +++ b/pallets/nonfungible/src/common.rs @@ -264,6 +264,12 @@ .collect() } + fn collection_tokens(&self) -> Vec { + >::iter_prefix((self.id,)) + .map(|(id, _)| id) + .collect() + } + fn token_exists(&self, token: TokenId) -> bool { >::token_exists(self, token) } @@ -286,10 +292,6 @@ .map(|t| t.variable_data) .unwrap_or_default() .into_inner() - } - - fn collection_tokens(&self) -> u32 { - >::total_supply(self) } fn account_balance(&self, account: T::CrossAccountId) -> u32 { --- a/pallets/refungible/src/common.rs +++ b/pallets/refungible/src/common.rs @@ -273,6 +273,12 @@ .collect() } + fn collection_tokens(&self) -> Vec { + >::iter_prefix((self.id,)) + .map(|(id, _)| id) + .collect() + } + fn token_exists(&self, token: TokenId) -> bool { >::token_exists(self, token) } @@ -293,10 +299,6 @@ >::get((self.id, token)) .variable_data .into_inner() - } - - fn collection_tokens(&self) -> u32 { - >::total_supply(self) } fn account_balance(&self, account: T::CrossAccountId) -> u32 { --- a/primitives/rpc/src/lib.rs +++ b/primitives/rpc/src/lib.rs @@ -33,6 +33,7 @@ fn token_owner(collection: CollectionId, token: TokenId) -> Result; fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result>; + fn collection_tokens(collection: CollectionId) -> Result>; fn token_exists(collection: CollectionId, token: TokenId) -> Result; fn token_owner(collection: CollectionId, token: TokenId) -> Result>; @@ -40,7 +41,6 @@ fn const_metadata(collection: CollectionId, token: TokenId) -> Result>; fn variable_metadata(collection: CollectionId, token: TokenId) -> Result>; - fn collection_tokens(collection: CollectionId) -> Result; fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result; fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result; fn allowance( --- a/runtime/common/src/runtime_apis.rs +++ b/runtime/common/src/runtime_apis.rs @@ -33,7 +33,7 @@ dispatch_unique_runtime!(collection.variable_metadata(token)) } - fn collection_tokens(collection: CollectionId) -> Result { + fn collection_tokens(collection: CollectionId) -> Result, DispatchError> { dispatch_unique_runtime!(collection.collection_tokens()) } fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result { -- gitstuff