difftreelog
feat(rpc) totalSupply
in: master
8 files changed
client/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());
pallets/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)
pallets/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 {
pallets/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))
}
pallets/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))
}
primitives/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(
runtime/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))
tests/src/interfaces/unique/definitions.tsdiffbeforeafterboth1// 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/>.1617import types from '../lookup';1819type RpcParam = {20 name: string;21 type: string;22 isOptional?: true;23};2425const CROSS_ACCOUNT_ID_TYPE = 'PalletEvmAccountBasicCrossAccountIdRepr';2627const collectionParam = {name: 'collection', type: 'u32'};28const tokenParam = {name: 'tokenId', type: 'u32'};29const crossAccountParam = (name = 'account') => ({name, type: CROSS_ACCOUNT_ID_TYPE});30const atParam = {name: 'at', type: 'Hash', isOptional: true};3132const fun = (description: string, params: RpcParam[], type: string) => ({33 description,34 params: [...params, atParam],35 type,36});3738export default {39 types,40 rpc: {41 adminlist: fun('Get admin list', [collectionParam], 'Vec<PalletEvmAccountBasicCrossAccountIdRepr>'),42 allowlist: fun('Get allowlist', [collectionParam], 'Vec<PalletEvmAccountBasicCrossAccountIdRepr>'),4344 accountTokens: fun('Get tokens owned by account', [collectionParam, crossAccountParam()], 'Vec<u32>'),45 collectionTokens: fun('Get tokens contained in collection', [collectionParam], 'Vec<u32>'),4647 lastTokenId: fun('Get last token id', [collectionParam], 'u32'),48 accountBalance: fun('Get amount of different user tokens', [collectionParam, crossAccountParam()], 'u32'),49 balance: fun('Get amount of specific account token', [collectionParam, crossAccountParam(), tokenParam], 'u128'),50 allowance: fun('Get allowed amount', [collectionParam, crossAccountParam('sender'), crossAccountParam('spender'), tokenParam], 'u128'),51 tokenOwner: fun('Get token owner', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),52 topmostTokenOwner: fun('Get token owner, in case of nested token - find parent recursive', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),53 constMetadata: fun('Get token constant metadata', [collectionParam, tokenParam], 'Vec<u8>'),54 variableMetadata: fun('Get token variable metadata', [collectionParam, tokenParam], 'Vec<u8>'),55 tokenExists: fun('Check if token exists', [collectionParam, tokenParam], 'bool'),56 collectionById: fun('Get collection by specified id', [collectionParam], 'Option<UpDataStructsRpcCollection>'),57 collectionStats: fun('Get collection stats', [], 'UpDataStructsCollectionStats'),58 allowed: fun('Check if user is allowed to use collection', [collectionParam, crossAccountParam()], 'bool'),59 nextSponsored: fun('Get number of blocks when sponsored transaction is available', [collectionParam, crossAccountParam(), tokenParam], 'Option<u64>'),60 effectiveCollectionLimits: fun('Get effective collection limits', [collectionParam], 'Option<UpDataStructsCollectionLimits>'),61 },62};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/>.1617import types from '../lookup';1819type RpcParam = {20 name: string;21 type: string;22 isOptional?: true;23};2425const CROSS_ACCOUNT_ID_TYPE = 'PalletEvmAccountBasicCrossAccountIdRepr';2627const collectionParam = {name: 'collection', type: 'u32'};28const tokenParam = {name: 'tokenId', type: 'u32'};29const crossAccountParam = (name = 'account') => ({name, type: CROSS_ACCOUNT_ID_TYPE});30const atParam = {name: 'at', type: 'Hash', isOptional: true};3132const fun = (description: string, params: RpcParam[], type: string) => ({33 description,34 params: [...params, atParam],35 type,36});3738export default {39 types,40 rpc: {41 adminlist: fun('Get admin list', [collectionParam], 'Vec<PalletEvmAccountBasicCrossAccountIdRepr>'),42 allowlist: fun('Get allowlist', [collectionParam], 'Vec<PalletEvmAccountBasicCrossAccountIdRepr>'),4344 accountTokens: fun('Get tokens owned by account', [collectionParam, crossAccountParam()], 'Vec<u32>'),45 collectionTokens: fun('Get tokens contained in collection', [collectionParam], 'Vec<u32>'),4647 lastTokenId: fun('Get last token id', [collectionParam], 'u32'),48 totalSupply: fun('Get amount of unique collection tokens', [collectionParam], 'u32'),49 accountBalance: fun('Get amount of different user tokens', [collectionParam, crossAccountParam()], 'u32'),50 balance: fun('Get amount of specific account token', [collectionParam, crossAccountParam(), tokenParam], 'u128'),51 allowance: fun('Get allowed amount', [collectionParam, crossAccountParam('sender'), crossAccountParam('spender'), tokenParam], 'u128'),52 tokenOwner: fun('Get token owner', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),53 topmostTokenOwner: fun('Get token owner, in case of nested token - find parent recursive', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),54 constMetadata: fun('Get token constant metadata', [collectionParam, tokenParam], 'Vec<u8>'),55 variableMetadata: fun('Get token variable metadata', [collectionParam, tokenParam], 'Vec<u8>'),56 tokenExists: fun('Check if token exists', [collectionParam, tokenParam], 'bool'),57 collectionById: fun('Get collection by specified id', [collectionParam], 'Option<UpDataStructsRpcCollection>'),58 collectionStats: fun('Get collection stats', [], 'UpDataStructsCollectionStats'),59 allowed: fun('Check if user is allowed to use collection', [collectionParam, crossAccountParam()], 'bool'),60 nextSponsored: fun('Get number of blocks when sponsored transaction is available', [collectionParam, crossAccountParam(), tokenParam], 'Option<u64>'),61 effectiveCollectionLimits: fun('Get effective collection limits', [collectionParam], 'Option<UpDataStructsCollectionLimits>'),62 },63};