Search in sources :

Example 6 with Balance

use of io.nuls.ledger.entity.Balance in project nuls by nuls-io.

the class UtxoLedgerServiceImpl method getBalance.

@Override
public Balance getBalance(String address) {
    if (StringUtils.isNotBlank(address)) {
        Balance balance = ledgerCacheService.getBalance(address);
        return balance;
    } else {
        Balance allBalance = new Balance();
        long usable = 0;
        long locked = 0;
        for (String addr : NulsContext.LOCAL_ADDRESS_LIST) {
            Balance balance = ledgerCacheService.getBalance(addr);
            if (null != balance) {
                usable += balance.getUsable().getValue();
                locked += balance.getLocked().getValue();
            }
        }
        allBalance.setUsable(Na.valueOf(usable));
        allBalance.setLocked(Na.valueOf(locked));
        allBalance.setBalance(Na.valueOf(usable + locked));
        return allBalance;
    }
}
Also used : Balance(io.nuls.ledger.entity.Balance)

Aggregations

Balance (io.nuls.ledger.entity.Balance)6 UtxoBalance (io.nuls.ledger.entity.UtxoBalance)3 Consensus (io.nuls.consensus.entity.Consensus)2 Agent (io.nuls.consensus.entity.member.Agent)2 Deposit (io.nuls.consensus.entity.member.Deposit)2 Account (io.nuls.account.entity.Account)1 ArrayList (java.util.ArrayList)1