Search in sources :

Example 1 with LedgerUtil.asString

use of io.nuls.ledger.util.LedgerUtil.asString in project nuls by nuls-io.

the class ContractServiceImpl method rollbackToMapAndContractUsedCoinMap.

private void rollbackToMapAndContractUsedCoinMap(Transaction tx, Map<String, Coin> toMaps, Map<String, Coin> contractUsedCoinMap) {
    if (tx == null || tx.getCoinData() == null || contractUsedCoinMap == null) {
        return;
    }
    CoinData coinData = tx.getCoinData();
    List<Coin> froms = coinData.getFrom();
    List<Coin> tos = coinData.getTo();
    String key;
    for (Coin from : froms) {
        key = from.getKey();
        if (key != null) {
            contractUsedCoinMap.remove(from.getKey());
        }
    }
    try {
        byte[] txHashBytes = tx.getHash().serialize();
        for (int i = 0, size = tos.size(); i < size; i++) {
            toMaps.remove(LedgerUtil.asString(ArraysTool.concatenate(txHashBytes, new VarInt(i).encode())));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : VarInt(io.nuls.kernel.utils.VarInt) LedgerUtil.asString(io.nuls.ledger.util.LedgerUtil.asString) NulsException(io.nuls.kernel.exception.NulsException) IOException(java.io.IOException)

Aggregations

NulsException (io.nuls.kernel.exception.NulsException)1 VarInt (io.nuls.kernel.utils.VarInt)1 LedgerUtil.asString (io.nuls.ledger.util.LedgerUtil.asString)1 IOException (java.io.IOException)1