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
932 fn const_metadata(&self, token: TokenId) -> Vec<u8>;932 fn const_metadata(&self, token: TokenId) -> Vec<u8>;
933 fn variable_metadata(&self, token: TokenId) -> Vec<u8>;933 fn variable_metadata(&self, token: TokenId) -> Vec<u8>;
934934
935 /// Amount of unique collection tokens
936 fn total_supply(&self) -> u32;
935 /// Amount of different tokens account has (Applicable to nonfungible/refungible)937 /// Amount of different tokens account has (Applicable to nonfungible/refungible)
936 fn account_balance(&self, account: T::CrossAccountId) -> u32;938 fn account_balance(&self, account: T::CrossAccountId) -> u32;
937 /// Amount of specific token account have (Applicable to fungible/refungible)939 /// Amount of specific token account have (Applicable to fungible/refungible)
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
244 fail!(<Error<T>>::FungibleDisallowsNesting)244 fail!(<Error<T>>::FungibleDisallowsNesting)
245 }245 }
246
247 fn collection_tokens(&self) -> Vec<TokenId> {
248 vec![TokenId::default()]
249 }
246250
247 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {251 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {
248 if <Balance<T>>::get((self.id, account)) != 0 {252 if <Balance<T>>::get((self.id, account)) != 0 {
270 Vec::new()274 Vec::new()
271 }275 }
272276
273 fn collection_tokens(&self) -> Vec<TokenId> {277 fn total_supply(&self) -> u32 {
274 vec![TokenId::default()]278 1
275 }279 }
276280
277 fn account_balance(&self, account: T::CrossAccountId) -> u32 {281 fn account_balance(&self, account: T::CrossAccountId) -> u32 {
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
294 .into_inner()294 .into_inner()
295 }295 }
296
297 fn total_supply(&self) -> u32 {
298 <Pallet<T>>::total_supply(self)
299 }
296300
297 fn account_balance(&self, account: T::CrossAccountId) -> u32 {301 fn account_balance(&self, account: T::CrossAccountId) -> u32 {
298 <AccountBalance<T>>::get((self.id, account))302 <AccountBalance<T>>::get((self.id, account))
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
301 .into_inner()301 .into_inner()
302 }302 }
303
304 fn total_supply(&self) -> u32 {
305 <Pallet<T>>::total_supply(self)
306 }
303307
304 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))
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
41 fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;41 fn const_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;
42 fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;42 fn variable_metadata(collection: CollectionId, token: TokenId) -> Result<Vec<u8>>;
4343
44 fn total_supply(collection: CollectionId) -> Result<u32>;
44 fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32>;45 fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32>;
45 fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128>;46 fn balance(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<u128>;
46 fn allowance(47 fn allowance(
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
14 fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {14 fn account_tokens(collection: CollectionId, account: CrossAccountId) -> Result<Vec<TokenId>, DispatchError> {
15 dispatch_unique_runtime!(collection.account_tokens(account))15 dispatch_unique_runtime!(collection.account_tokens(account))
16 }16 }
17 fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>, DispatchError> {
18 dispatch_unique_runtime!(collection.collection_tokens())
19 }
17 fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {20 fn token_exists(collection: CollectionId, token: TokenId) -> Result<bool, DispatchError> {
18 dispatch_unique_runtime!(collection.token_exists(token))21 dispatch_unique_runtime!(collection.token_exists(token))
19 }22 }
33 dispatch_unique_runtime!(collection.variable_metadata(token))36 dispatch_unique_runtime!(collection.variable_metadata(token))
34 }37 }
3538
36 fn collection_tokens(collection: CollectionId) -> Result<Vec<TokenId>, DispatchError> {39 fn total_supply(collection: CollectionId) -> Result<u32, DispatchError> {
37 dispatch_unique_runtime!(collection.collection_tokens())40 dispatch_unique_runtime!(collection.total_supply())
38 }41 }
39 fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {42 fn account_balance(collection: CollectionId, account: CrossAccountId) -> Result<u32, DispatchError> {
40 dispatch_unique_runtime!(collection.account_balance(account))43 dispatch_unique_runtime!(collection.account_balance(account))
modifiedtests/src/interfaces/unique/definitions.tsdiffbeforeafterboth
45 collectionTokens: fun('Get tokens contained in collection', [collectionParam], 'Vec<u32>'),45 collectionTokens: fun('Get tokens contained in collection', [collectionParam], 'Vec<u32>'),
4646
47 lastTokenId: fun('Get last token id', [collectionParam], 'u32'),47 lastTokenId: fun('Get last token id', [collectionParam], 'u32'),
48 totalSupply: fun('Get amount of unique collection tokens', [collectionParam], 'u32'),
48 accountBalance: fun('Get amount of different user tokens', [collectionParam, crossAccountParam()], 'u32'),49 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 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 allowance: fun('Get allowed amount', [collectionParam, crossAccountParam('sender'), crossAccountParam('spender'), tokenParam], 'u128'),