difftreelog
Add rpc method for total_pieces
in: master
8 files changed
client/rpc/src/lib.rsdiffbeforeafterboth191 at: Option<BlockHash>,192 at: Option<BlockHash>,192 ) -> Result<Option<CollectionLimits>>;193 ) -> Result<Option<CollectionLimits>>;194195 #[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}194203195mod 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}467477468#[allow(deprecated)]478#[allow(deprecated)]pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -1382,6 +1382,8 @@
fn account_balance(&self, account: T::CrossAccountId) -> u32;
/// Amount of specific token account have (Applicable to fungible/refungible)
fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128;
+ /// Amount of token pieces
+ fn total_pieces(&self, token: TokenId) -> u128;
fn allowance(
&self,
sender: T::CrossAccountId,
pallets/fungible/src/common.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -403,4 +403,8 @@
fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {
None
}
+
+ fn total_pieces(&self, _token: TokenId) -> u128 {
+ 0
+ }
}
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -472,4 +472,8 @@
fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {
None
}
+
+ fn total_pieces(&self, _token: TokenId) -> u128 {
+ 1
+ }
}
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -409,6 +409,10 @@
fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {
Some(self)
}
+
+ fn total_pieces(&self, token: TokenId) -> u128 {
+ <Pallet<T>>::total_pieces(self.id, token)
+ }
}
impl<T: Config> RefungibleExtensions<T> for RefungibleHandle<T> {
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -710,4 +710,9 @@
<TotalSupply<T>>::insert((collection.id, token), amount);
Ok(())
}
+
+ fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> u128 {
+ // Not "try_fold" because total count of pieces is limited by 'MAX_REFUNGIBLE_PIECES'.
+ <Balance<T>>::iter_prefix((collection_id, token_id)).fold(0, |total, piece| total + piece.1)
+ }
}
primitives/rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -80,5 +80,6 @@
fn collection_stats() -> Result<CollectionStats>;
fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;
fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;
+ fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Result<u128>;
}
}
runtime/common/src/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -142,6 +142,10 @@
fn effective_collection_limits(collection: CollectionId) -> Result<Option<CollectionLimits>, DispatchError> {
Ok(<pallet_common::Pallet<Runtime>>::effective_collection_limits(collection))
}
+
+ fn total_pieces(collection: CollectionId, token_id: TokenId) -> Result<u128, DispatchError> {
+ dispatch_unique_runtime!(collection.total_pieces(token_id))
+ }
}
impl sp_api::Core<Block> for Runtime {