Search in sources :

Example 31 with Coin

use of io.nuls.kernel.model.Coin in project nuls by nuls-io.

the class ContractBalanceManager method initContractBalance.

/**
 * 初始化缓存本地所有合约账户的余额信息
 */
public void initContractBalance() {
    balanceMap = new ConcurrentHashMap<>();
    List<Entry<byte[], byte[]>> rawList = contractUtxoStorageService.loadAllCoinList();
    Coin coin;
    String strAddress;
    ContractBalance balance;
    for (Entry<byte[], byte[]> coinEntry : rawList) {
        coin = new Coin();
        try {
            coin.parse(coinEntry.getValue(), 0);
            // strAddress = asString(coin.getOwner());
            coin.setKey(asString(coinEntry.getKey()));
            strAddress = asString(coin.getAddress());
        } catch (NulsException e) {
            Log.error("parse contract coin error form db", e);
            continue;
        }
        balance = balanceMap.get(strAddress);
        if (balance == null) {
            balance = new ContractBalance();
            balanceMap.put(strAddress, balance);
        }
        // 共识奖励的utxo
        if (coin.getLockTime() != 0) {
            balance.getConsensusRewardCoins().put(coin.getKey(), coin);
        } else {
            balance.addUsable(coin.getNa());
        }
    }
}
Also used : Coin(io.nuls.kernel.model.Coin) Entry(io.nuls.db.model.Entry) ContractBalance(io.nuls.contract.ledger.module.ContractBalance) NulsException(io.nuls.kernel.exception.NulsException) LedgerUtil.asString(io.nuls.ledger.util.LedgerUtil.asString)

Aggregations

Coin (io.nuls.kernel.model.Coin)31 NulsException (io.nuls.kernel.exception.NulsException)16 Na (io.nuls.kernel.model.Na)8 Entry (io.nuls.db.model.Entry)6 ValidateResult (io.nuls.kernel.validate.ValidateResult)6 CoinData (io.nuls.kernel.model.CoinData)5 TransactionSignature (io.nuls.kernel.script.TransactionSignature)4 ContractBalance (io.nuls.contract.ledger.module.ContractBalance)3 Result (io.nuls.kernel.model.Result)3 LedgerUtil.asString (io.nuls.ledger.util.LedgerUtil.asString)3 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 AgentPo (io.nuls.consensus.poc.storage.po.AgentPo)2 DepositPo (io.nuls.consensus.poc.storage.po.DepositPo)2 ECKey (io.nuls.core.tools.crypto.ECKey)2 RpcClientResult (io.nuls.kernel.model.RpcClientResult)2 Transaction (io.nuls.kernel.model.Transaction)2 Script (io.nuls.kernel.script.Script)2