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
--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -76,6 +76,12 @@
 		at: Option<BlockHash>,
 	) -> Result<Vec<u8>>;
 
+	#[rpc(name = "unique_totalSupply")]
+	fn total_supply(
+		&self,
+		collection: CollectionId,
+		at: Option<BlockHash>,
+	) -> Result<u32>;
 	#[rpc(name = "unique_accountBalance")]
 	fn account_balance(
 		&self,
@@ -239,6 +245,8 @@
 	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!(total_supply(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
--- 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
before · primitives/rpc/src/lib.rs
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#![cfg_attr(not(feature = "std"), no_std)]1819use up_data_structs::{CollectionId, TokenId, RpcCollection, CollectionStats, CollectionLimits};20use sp_std::vec::Vec;21use codec::Decode;22use sp_runtime::DispatchError;2324type Result<T> = core::result::Result<T, DispatchError>;2526sp_api::decl_runtime_apis! {27	#[api_version(2)]28	pub trait UniqueApi<CrossAccountId, AccountId> where29		AccountId: Decode,30		CrossAccountId: pallet_evm::account::CrossAccountId<AccountId>,31	{32		#[changed_in(2)]33		fn token_owner(collection: CollectionId, token: TokenId) -> Result<CrossAccountId>;3435		fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>>;36		fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>>;37		fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool>;3839		fn token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>>;40		fn topmost_token_owner(collection: CollectionId, token: TokenId) -> Result<Option<CrossAccountId>>;41		fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;42		fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;4344		fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32>;45		fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128>;46		fn allowance(47			collection: CollectionId,48			sender: CrossAccountId,49			spender: CrossAccountId,50			token: TokenId,51		) -> Result<u128>;5253		fn adminlist(collection: CollectionId) -> Result<Vec<CrossAccountId>>;54		fn allowlist(collection: CollectionId) -> Result<Vec<CrossAccountId>>;55		fn allowed(collection: CollectionId, user: CrossAccountId) -> Result<bool>;56		fn last_token_id(collection: CollectionId) -> Result<TokenId>;57		fn collection_by_id(collection: CollectionId) -> Result<Option<RpcCollection<AccountId>>>;58		fn collection_stats() -> Result<CollectionStats>;59		fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;60		fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;61	}62}
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'),