Skip to content

Commit

Permalink
adding balance of batch in the vmt-service
Browse files Browse the repository at this point in the history
  • Loading branch information
MedovTimur committed Oct 22, 2024
1 parent bc4c59f commit d97bcfb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions extended-vmt/wasm/extended_vmt.idl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ service Vmt {
query Minters : () -> vec actor_id;
/// Returns the token balance of an account (`account`) for a specific token ID (`id`).
query BalanceOf : (account: actor_id, id: u256) -> u256;
/// Returns token account balances (`accounts`) for specific token identifiers (`ids`).
query BalanceOfBatch : (accounts: vec actor_id, ids: vec u256) -> vec u256;
/// Returns the number of decimal places used for this token.
query Decimals : () -> u8;
/// Checks if a specific operator (`operator`) is approved to transfer tokens on behalf of `account`.
Expand Down
17 changes: 17 additions & 0 deletions vmt-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ impl Service {
funcs::get_balance(&storage.balances, &account, &id)
}

/// Returns token account balances (`accounts`) for specific token identifiers (`ids`).
pub fn balance_of_batch(&self, accounts: Vec<ActorId>, ids: Vec<TokenId>) -> Vec<U256> {
let storage = Storage::get();

assert_eq!(
accounts.len(),
ids.len(),
"Accounts and IDs must have the same length"
);

accounts
.into_iter()
.zip(ids.into_iter())
.map(|(account, id)| funcs::get_balance(&storage.balances, &account, &id))
.collect()
}

/// Returns the number of decimal places used for this token.
pub fn decimals(&self) -> &'static u8 {
let storage = Storage::get();
Expand Down

0 comments on commit d97bcfb

Please sign in to comment.