Getting the wallet balance with the address in currency (CS by default).
1: Address address
2: Currency currency = 'cs'
Type of result: BalanceGetResult
The address field is re-coded: if the address string length is 64 symbols, then we re-code from 16 representation into string, or else we compute the public key hash in respect of the same based on the blake2 algorithm.
We get the balance from the blockchain based on the so-computed address by searching for the element containing such address in the balance cache. If the cache balance is found not in the last block, then we:
Download the pool from the storage based on the last block's hash value and then, while the public key length is valid and hash value is not equal to the hash value of the last verified block:
Determine the transaction balance in respect of all transactions of the block (if address source);
Add the transaction price to the result in respect of all transactions of the block (if address target);
If the balance found refers to the address source, then we add the address source balance found to the result and terminate a loop;
Download the pool from storage based on the hash value of the previous unviewed block.
If the wallet address found refers to the address source, then we add cache balance to the result.
We save the balance of this wallet address in the balances cache.
The following structures are used for marshalling purposes:
BalanceGetResult balance get result
typedef string Address
typedef string TransactionInnerId
typedef string Currency
i8 code //status code
string message //status communication
i32 integral //the integral
i64 fraction //the fraction
/** BalanceGet begin */
Address addr = "4xyjk5LNjDfUxQVe72QvB7LFkfUXsxbj3Yty9ESMNJKN";
Currency cur = 'cs';
api->BalanceGet(bg_res, addr, cur);
std::cout << std::endl << std::endl;
/** BalanceGet end */