git.delta.rocks / unique-network / refs/commits / 860bb39fe415

difftreelog

Add rpc method for total_pieces

Trubnikov Sergey2022-06-29parent: #66c5541.patch.diff
in: master

8 files changed

modifiedclient/rpc/src/lib.rsdiffbeforeafterboth
191 at: Option<BlockHash>,192 at: Option<BlockHash>,
192 ) -> Result<Option<CollectionLimits>>;193 ) -> Result<Option<CollectionLimits>>;
194
195 #[method(name = "unique_totalPieces")]
196 fn total_pieces(
197 &self,
198 collection_id: CollectionId,
199 token_id: TokenId,
200 at: Option<BlockHash>,
201 ) -> Result<u128>;
193}202}
194203
195mod rmrk_unique_rpc {204mod rmrk_unique_rpc {
463 pass_method!(collection_stats() -> CollectionStats, unique_api);472 pass_method!(collection_stats() -> CollectionStats, unique_api);
464 pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);473 pass_method!(next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Option<u64>, unique_api);
465 pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>, unique_api);474 pass_method!(effective_collection_limits(collection_id: CollectionId) -> Option<CollectionLimits>, unique_api);
475 pass_method!(total_pieces(collection_id: CollectionId, token_id: TokenId) -> u128, unique_api);
466}476}
467477
468#[allow(deprecated)]478#[allow(deprecated)]
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
1382 fn account_balance(&self, account: T::CrossAccountId) -> u32;1382 fn account_balance(&self, account: T::CrossAccountId) -> u32;
1383 /// Amount of specific token account have (Applicable to fungible/refungible)1383 /// Amount of specific token account have (Applicable to fungible/refungible)
1384 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128;1384 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128;
1385 /// Amount of token pieces
1386 fn total_pieces(&self, token: TokenId) -> u128;
1385 fn allowance(1387 fn allowance(
1386 &self,1388 &self,
1387 sender: T::CrossAccountId,1389 sender: T::CrossAccountId,
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
404 None404 None
405 }405 }
406
407 fn total_pieces(&self, _token: TokenId) -> u128 {
408 0
409 }
406}410}
407411
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
473 None473 None
474 }474 }
475
476 fn total_pieces(&self, _token: TokenId) -> u128 {
477 1
478 }
475}479}
476480
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
410 Some(self)410 Some(self)
411 }411 }
412
413 fn total_pieces(&self, token: TokenId) -> u128 {
414 <Pallet<T>>::total_pieces(self.id, token)
415 }
412}416}
413417
414impl<T: Config> RefungibleExtensions<T> for RefungibleHandle<T> {418impl<T: Config> RefungibleExtensions<T> for RefungibleHandle<T> {
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
711 Ok(())711 Ok(())
712 }712 }
713
714 fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> u128 {
715 // Not "try_fold" because total count of pieces is limited by 'MAX_REFUNGIBLE_PIECES'.
716 <Balance<T>>::iter_prefix((collection_id, token_id)).fold(0, |total, piece| total + piece.1)
717 }
713}718}
714719
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
80 fn collection_stats() -> Result<CollectionStats>;80 fn collection_stats() -> Result<CollectionStats>;
81 fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;81 fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;
82 fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;82 fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;
83 fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Result<u128>;
83 }84 }
84}85}
8586
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
143 Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))143 Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))
144 }144 }
145
146 fn total_pieces(collection: CollectionId, token_id: TokenId) -> Result<u128, DispatchError> {
147 dispatch_unique_runtime!(collection.total_pieces(token_id))
148 }
145 }149 }
146150
147 impl sp_api::Core<Block> for Runtime {151 impl sp_api::Core<Block> for Runtime {