git.delta.rocks / unique-network / refs/commits / f9a4dd52b855

difftreelog

fix(rpc) wrong return type for collectionTokens call

Yaroslav Bolyukin2022-04-12parent: #3bd9a5e.patch.diff
in: master

7 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -33,6 +33,12 @@
 		account: CrossAccountId,
 		at: Option<BlockHash>,
 	) -> Result<Vec<TokenId>>;
+	#[rpc(name = "unique_collectionTokens")]
+	fn collection_tokens(
+		&self,
+		collection: CollectionId,
+		at: Option<BlockHash>,
+	) -> Result<Vec<TokenId>>;
 	#[rpc(name = "unique_tokenExists")]
 	fn token_exists(
 		&self,
@@ -70,8 +76,6 @@
 		at: Option<BlockHash>,
 	) -> Result<Vec<u8>>;
 
-	#[rpc(name = "unique_collectionTokens")]
-	fn collection_tokens(&self, collection: CollectionId, at: Option<BlockHash>) -> Result<u32>;
 	#[rpc(name = "unique_accountBalance")]
 	fn account_balance(
 		&self,
@@ -226,6 +230,7 @@
 	CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,
 {
 	pass_method!(account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId>);
+	pass_method!(collection_tokens(collection: CollectionId) -> Vec<TokenId>);
 	pass_method!(token_exists(collection: CollectionId, token: TokenId) -> bool);
 	pass_method!(
 		token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>;
@@ -234,7 +239,6 @@
 	pass_method!(topmost_token_owner(collection: CollectionId, token: TokenId) -> Option<CrossAccountId>);
 	pass_method!(const_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);
 	pass_method!(variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);
-	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());
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
924 ) -> DispatchResult;924 ) -> DispatchResult;
925925
926 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId>;926 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId>;
927 fn collection_tokens(&self) -> Vec<TokenId>;
927 fn token_exists(&self, token: TokenId) -> bool;928 fn token_exists(&self, token: TokenId) -> bool;
928 fn last_token_id(&self) -> TokenId;929 fn last_token_id(&self) -> TokenId;
929930
930 fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId>;931 fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId>;
931 fn const_metadata(&self, token: TokenId) -> Vec<u8>;932 fn const_metadata(&self, token: TokenId) -> Vec<u8>;
932 fn variable_metadata(&self, token: TokenId) -> Vec<u8>;933 fn variable_metadata(&self, token: TokenId) -> Vec<u8>;
933934
934 /// How many tokens collection contains (Applicable to nonfungible/refungible)
935 fn collection_tokens(&self) -> u32;
936 /// Amount of different tokens account has (Applicable to nonfungible/refungible)935 /// Amount of different tokens account has (Applicable to nonfungible/refungible)
937 fn account_balance(&self, account: T::CrossAccountId) -> u32;936 fn account_balance(&self, account: T::CrossAccountId) -> u32;
938 /// Amount of specific token account have (Applicable to fungible/refungible)937 /// Amount of specific token account have (Applicable to fungible/refungible)
modifiedpallets/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 {
modifiedpallets/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 {
modifiedpallets/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 {
modifiedprimitives/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(
modifiedruntime/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> {