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());
}
}
}
Aggregations