--- a/client/rpc/src/lib.rs +++ b/client/rpc/src/lib.rs @@ -76,6 +76,12 @@ at: Option, ) -> Result>; + #[rpc(name = "unique_totalSupply")] + fn total_supply( + &self, + collection: CollectionId, + at: Option, + ) -> Result; #[rpc(name = "unique_accountBalance")] fn account_balance( &self, @@ -239,6 +245,8 @@ pass_method!(topmost_token_owner(collection: CollectionId, token: TokenId) -> Option); pass_method!(const_metadata(collection: CollectionId, token: TokenId) -> Vec); pass_method!(variable_metadata(collection: CollectionId, token: TokenId) -> Vec); + + 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()); --- a/pallets/common/src/lib.rs +++ b/pallets/common/src/lib.rs @@ -932,6 +932,8 @@ fn const_metadata(&self, token: TokenId) -> Vec; fn variable_metadata(&self, token: TokenId) -> Vec; + /// 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) --- a/pallets/fungible/src/common.rs +++ b/pallets/fungible/src/common.rs @@ -244,6 +244,10 @@ fail!(>::FungibleDisallowsNesting) } + fn collection_tokens(&self) -> Vec { + vec![TokenId::default()] + } + fn account_tokens(&self, account: T::CrossAccountId) -> Vec { if >::get((self.id, account)) != 0 { vec![TokenId::default()] @@ -270,8 +274,8 @@ Vec::new() } - fn collection_tokens(&self) -> Vec { - vec![TokenId::default()] + fn total_supply(&self) -> u32 { + 1 } fn account_balance(&self, account: T::CrossAccountId) -> u32 { --- a/pallets/nonfungible/src/common.rs +++ b/pallets/nonfungible/src/common.rs @@ -294,6 +294,10 @@ .into_inner() } + fn total_supply(&self) -> u32 { + >::total_supply(self) + } + fn account_balance(&self, account: T::CrossAccountId) -> u32 { >::get((self.id, account)) } --- a/pallets/refungible/src/common.rs +++ b/pallets/refungible/src/common.rs @@ -301,6 +301,10 @@ .into_inner() } + fn total_supply(&self) -> u32 { + >::total_supply(self) + } + fn account_balance(&self, account: T::CrossAccountId) -> u32 { >::get((self.id, account)) } --- a/primitives/rpc/src/lib.rs +++ b/primitives/rpc/src/lib.rs @@ -41,6 +41,7 @@ fn const_metadata(collection: CollectionId, token: TokenId) -> Result>; fn variable_metadata(collection: CollectionId, token: TokenId) -> Result>; + fn total_supply(collection: CollectionId) -> Result; fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result; fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result; fn allowance( --- 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, DispatchError> { dispatch_unique_runtime!(collection.account_tokens(account)) } + fn collection_tokens(collection: CollectionId) -> Result, DispatchError> { + dispatch_unique_runtime!(collection.collection_tokens()) + } fn token_exists(collection: CollectionId, token: TokenId) -> Result { dispatch_unique_runtime!(collection.token_exists(token)) } @@ -33,8 +36,8 @@ dispatch_unique_runtime!(collection.variable_metadata(token)) } - fn collection_tokens(collection: CollectionId) -> Result, DispatchError> { - dispatch_unique_runtime!(collection.collection_tokens()) + fn total_supply(collection: CollectionId) -> Result { + dispatch_unique_runtime!(collection.total_supply()) } fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result { dispatch_unique_runtime!(collection.account_balance(account)) --- 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'), 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'),