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

difftreelog

feat(rpc) totalSupply

Yaroslav Bolyukin2022-04-14parent: #bbd154a.patch.diff
in: master

8 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
76 at: Option<BlockHash>,76 at: Option<BlockHash>,
77 ) -> Result<Vec<u8>>;77 ) -> Result<Vec<u8>>;
7878
79 #[rpc(name = "unique_totalSupply")]
80 fn total_supply(
81 &self,
82 collection: CollectionId,
83 at: Option<BlockHash>,
84 ) -> Result<u32>;
79 #[rpc(name = "unique_accountBalance")]85 #[rpc(name = "unique_accountBalance")]
80 fn account_balance(86 fn account_balance(
81 &self,87 &self,
240 pass_method!(const_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);246 pass_method!(const_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);
241 pass_method!(variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);247 pass_method!(variable_metadata(collection: CollectionId, token: TokenId) -> Vec<u8>);
248
249 pass_method!(total_supply(collection: CollectionId) -> u32);
242 pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32);250 pass_method!(account_balance(collection: CollectionId, account: CrossAccountId) -> u32);
243 pass_method!(balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> String => |v| v.to_string());251 pass_method!(balance(collection: CollectionId, account: 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());252 pass_method!(allowance(collection: CollectionId, sender: CrossAccountId, spender: CrossAccountId, token: TokenId) -> String => |v| v.to_string());
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -932,6 +932,8 @@
 	fn const_metadata(&self, token: TokenId) -> Vec<u8>;
 	fn variable_metadata(&self, token: TokenId) -> Vec<u8>;
 
+	/// Amount of unique collection tokens
+	fn total_supply(&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)
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -244,6 +244,10 @@
 		fail!(<Error<T>>::FungibleDisallowsNesting)
 	}
 
+	fn collection_tokens(&self) -> Vec<TokenId> {
+		vec![TokenId::default()]
+	}
+
 	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
 		if <Balance<T>>::get((self.id, account)) != 0 {
 			vec![TokenId::default()]
@@ -270,8 +274,8 @@
 		Vec::new()
 	}
 
-	fn collection_tokens(&self) -> Vec<TokenId> {
-		vec![TokenId::default()]
+	fn total_supply(&self) -> u32 {
+		1
 	}
 
 	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
@@ -294,6 +294,10 @@
 			.into_inner()
 	}
 
+	fn total_supply(&self) -> u32 {
+		<Pallet<T>>::total_supply(self)
+	}
+
 	fn account_balance(&self, account: T::CrossAccountId) -> u32 {
 		<AccountBalance<T>>::get((self.id, account))
 	}
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -301,6 +301,10 @@
 			.into_inner()
 	}
 
+	fn total_supply(&self) -> u32 {
+		<Pallet<T>>::total_supply(self)
+	}
+
 	fn account_balance(&self, account: T::CrossAccountId) -> u32 {
 		<AccountBalance<T>>::get((self.id, account))
 	}
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -41,6 +41,7 @@
 		fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;
 		fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;
 
+		fn total_supply(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
@@ -14,6 +14,9 @@
                 fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {
                     dispatch_unique_runtime!(collection.account_tokens(account))
                 }
+                fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>, DispatchError> {
+                    dispatch_unique_runtime!(collection.collection_tokens())
+                }
                 fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {
                     dispatch_unique_runtime!(collection.token_exists(token))
                 }
@@ -33,8 +36,8 @@
                     dispatch_unique_runtime!(collection.variable_metadata(token))
                 }
 
-                fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>, DispatchError> {
-                    dispatch_unique_runtime!(collection.collection_tokens())
+                fn total_supply(collection: CollectionId) -> Result<u32, DispatchError> {
+                    dispatch_unique_runtime!(collection.total_supply())
                 }
                 fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {
                     dispatch_unique_runtime!(collection.account_balance(account))
modifiedtests/src/interfaces/unique/definitions.tsdiffbeforeafterboth
--- a/tests/src/interfaces/unique/definitions.ts
+++ b/tests/src/interfaces/unique/definitions.ts
@@ -45,6 +45,7 @@
     collectionTokens: fun('Get tokens contained in collection', [collectionParam], 'Vec<u32>'),
 
     lastTokenId: fun('Get last token id', [collectionParam], 'u32'),
+    totalSupply: fun('Get amount of unique collection tokens', [collectionParam], 'u32'),
     accountBalance: fun('Get amount of different user tokens', [collectionParam, crossAccountParam()], 'u32'),
     balance: fun('Get amount of specific account token', [collectionParam, crossAccountParam(), tokenParam], 'u128'),
     allowance: fun('Get allowed amount', [collectionParam, crossAccountParam('sender'), crossAccountParam('spender'), tokenParam], 'u128'),