Skip to content

Commit

Permalink
Merge pull request #32 from deleterium/feat/getAccountBalance
Browse files Browse the repository at this point in the history
Adding undocumented API Get_Account_Balance.
Reference signum-node commit signum-network/signum-node@c01f860
  • Loading branch information
deleterium authored Feb 9, 2024
2 parents e679293 + d9037b9 commit 00268c5
Show file tree
Hide file tree
Showing 9 changed files with 1,716 additions and 6,444 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/*
dist
coverage
.vscode
25 changes: 25 additions & 0 deletions docs/1.5-Built-in-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ void distributeToHoldersFx(
);
long getAssetHoldersCount(long minimumQuantity, long assetId);
long getAssetCirculating(long assetId);
long getAccountBalance(long accountId);
fixed getAccountBalanceFx(long accountId);
long getAccountQuantity(long accountId, long assetId);

// Special instructions
long mdv(long m1, long m2, long div);
Expand Down Expand Up @@ -497,6 +500,28 @@ Returns the quantity of 'assetId' currently in circulation.
1) In treasury accounts;
2) In sell orders;
3) In accountId zero (burn address).

### getAccountBalance, getAccountBalanceFx
* Prototype:
`long getAccountBalance(long accountId);`
* Fixed version prototype:
`fixed getAccountBalanceFx(long accountId);`
* Description:
Returns the SIGNA balance owned by 'accountId'.
If there is no accountId, returns zero.
When used to get the balances from smart contracts, it will return the balance on last block, not the one after the execution on current block.
Same applies to get the own contract balance, which is the same as signum API Get_Previous_Balance and most of times not useful.
* Note that some parts of the balance are also considered:
1) Commitment.

### getAccountAssetQuantity
* Prototype:
`long getAccountQuantity(long accountId, long assetId);`
* Description:
Returns the quantity of 'assetId' owned by 'accountId'.
When used to get the balances from smart contracts, it will return the balance on last block, not the one after the execution on current block.
* Note that some quantities are also considered:
1) In sell orders.
</details>
<details>
<summary>
Expand Down
30 changes: 30 additions & 0 deletions docs/2-API-Pseudo-Code.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,21 @@ long Get_Asset_Circulating(void) {
treasury account.
*/
}
long Get_Account_Balance(void) {
// Assembly name: Get_Account_Balance
accountId = B1;
assetId = B2;
if(assetId == 0L){
balance = Blockchain.getAccountBalance(accountId);
// if there is no account, then return zero
return balance
}
quantity = Blockchain.getAccountQuatity(accountId, assetId);
// If there is no account, or if account does not have the given asset, returns 0
return quantity
}
```
</details>
<details>
Expand Down Expand Up @@ -821,6 +836,21 @@ fixed F_Get_Activation_Fee(void) {
}
return 0;
}

fixed F_Get_Account_Balance(void) {
// Assembly name: Get_Account_Balance
accountId = B1;
assetId = B2;

if(assetId == 0L){
balance = Blockchain.getAccountBalance(accountId);
// if there is no account, then return zero
return balance
}
quantity = Blockchain.getAccountQuatity(accountId, assetId);
// If there is no account, or if account does not have the given asset, returns 0
return quantity
}
```
</details>
Expand Down
Loading

0 comments on commit 00268c5

Please sign in to comment.