difftreelog
fix(rpc) wrong return type for collectionTokens call
in: master
7 files changed
client/rpc/src/lib.rsdiffbeforeafterboth33 account: CrossAccountId,33 account: CrossAccountId,34 at: Option<BlockHash>,34 at: Option<BlockHash>,35 ) -> Result<Vec<TokenId>>;35 ) -> Result<Vec<TokenId>>;36 #[rpc(name = "unique_collectionTokens")]37 fn collection_tokens(38 &self,39 collection: CollectionId,40 at: Option<BlockHash>,41 ) -> Result<Vec<TokenId>>;36 #[rpc(name = "unique_tokenExists")]42 #[rpc(name = "unique_tokenExists")]37 fn token_exists(43 fn token_exists(38 &self,44 &self,70 at: Option<BlockHash>,76 at: Option<BlockHash>,71 ) -> Result<Vec<u8>>;77 ) -> Result<Vec<u8>>;727873 #[rpc(name = "unique_collectionTokens")]74 fn collection_tokens(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<u32>;75 #[rpc(name = "unique_accountBalance")]79 #[rpc(name = "unique_accountBalance")]76 fn account_balance(80 fn account_balance(77 &self,81 &self,226 CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,230 CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,227{231{228 pass_method!(account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId>);232 pass_method!(account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId>);233 pass_method!(collection_tokens(collection: CollectionId) -> Vec<TokenId>);229 pass_method!(token_exists(collection: CollectionId, token: TokenId) -> bool);234 pass_method!(token_exists(collection: CollectionId, token: TokenId) -> bool);230 pass_method!(235 pass_method!(231 token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>;236 token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>;234 pass_method!(topmost_token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>);239 pass_method!(topmost_token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>);235 pass_method!(const_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);240 pass_method!(const_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);236 pass_method!(variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);241 pass_method!(variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);237 pass_method!(collection_tokens(collection: CollectionId) -> u32);238 pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32);242 pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32);239 pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string());243 pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string());240 pass_method!(allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string());244 pass_method!(allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string());pallets/common/src/lib.rsdiffbeforeafterboth--- 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<TokenId>;
+ fn collection_tokens(&self) -> Vec<TokenId>;
fn token_exists(&self, token: TokenId) -> bool;
fn last_token_id(&self) -> TokenId;
@@ -931,8 +932,6 @@
fn const_metadata(&self, token: TokenId) -> Vec<u8>;
fn variable_metadata(&self, token: TokenId) -> Vec<u8>;
- /// 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)
pallets/fungible/src/common.rsdiffbeforeafterboth--- 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<TokenId> {
+ vec![TokenId::default()]
}
fn account_balance(&self, account: T::CrossAccountId) -> u32 {
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -264,6 +264,12 @@
.collect()
}
+ fn collection_tokens(&self) -> Vec<TokenId> {
+ <TokenData<T>>::iter_prefix((self.id,))
+ .map(|(id, _)| id)
+ .collect()
+ }
+
fn token_exists(&self, token: TokenId) -> bool {
<Pallet<T>>::token_exists(self, token)
}
@@ -286,10 +292,6 @@
.map(|t| t.variable_data)
.unwrap_or_default()
.into_inner()
- }
-
- fn collection_tokens(&self) -> u32 {
- <Pallet<T>>::total_supply(self)
}
fn account_balance(&self, account: T::CrossAccountId) -> u32 {
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -273,6 +273,12 @@
.collect()
}
+ fn collection_tokens(&self) -> Vec<TokenId> {
+ <TokenData<T>>::iter_prefix((self.id,))
+ .map(|(id, _)| id)
+ .collect()
+ }
+
fn token_exists(&self, token: TokenId) -> bool {
<Pallet<T>>::token_exists(self, token)
}
@@ -293,10 +299,6 @@
<TokenData<T>>::get((self.id, token))
.variable_data
.into_inner()
- }
-
- fn collection_tokens(&self) -> u32 {
- <Pallet<T>>::total_supply(self)
}
fn account_balance(&self, account: T::CrossAccountId) -> u32 {
primitives/rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -33,6 +33,7 @@
fn token_owner(collection: CollectionId, token: TokenId) -> Result<CrossAccountId>;
fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>>;
+ fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>>;
fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool>;
fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>>;
@@ -40,7 +41,6 @@
fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;
fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;
- fn collection_tokens(collection: CollectionId) -> Result<u32>;
fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32>;
fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128>;
fn allowance(
runtime/common/src/runtime_apis.rsdiffbeforeafterboth--- 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<u32, DispatchError> {
+ fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>, DispatchError> {
dispatch_unique_runtime!(collection.collection_tokens())
}
fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {