Published 15 October 2018

BalanceGet

Getting the wallet balance with the address in currency (CS by default).

Parameters

Parameters:

1: Address address

2: Currency currency = 'cs'

Type of result: BalanceGetResult

Operation algorithm

Operation algorithm:

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.

Data structure

The following structures are used for marshalling purposes:

BalanceGetResult balance get result

typedef string Address

typedef string TransactionInnerId

typedef string Currency

APIResponse status

status

i8 code //status code

string message //status communication

Amount amount

balance amount

i32 integral //the integral

i64 fraction //the fraction

 

Example

Example

/** BalanceGet begin */

 

Address                   addr = "4xyjk5LNjDfUxQVe72QvB7LFkfUXsxbj3Yty9ESMNJKN";

Currency                 cur = 'cs';

BalanceGetResult   bg_res;

 

try

{

         api->BalanceGet(bg_res, addr, cur);

}

catch (...)

{

         return 1;

}

 

bg_res.printTo(std::cout);

std::cout << std::endl << std::endl;

 

/** BalanceGet end */

16 Useful article

Contents