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.rsdiffbeforeafterboth301 .into_inner()301 .into_inner()302 }302 }303304 fn total_supply(&self) -> u32 {305 <Pallet<T>>::total_supply(self)306 }303307304 fn account_balance(&self, account: T::CrossAccountId) -> u32 {308 fn account_balance(&self, account: T::CrossAccountId) -> u32 {305 <AccountBalance<T>>::get((self.id, account))309 <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.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'),