Search in sources :

Example 1 with UtxoOutput

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

the class LedgerCacheService method putUtxo.

public void putUtxo(String key, UtxoOutput output) {
    utxoCacheService.putElement(LedgerConstant.UTXO, key, output);
    String address = output.getAddress();
    UtxoBalance balance = (UtxoBalance) getBalance(address);
    if (balance == null) {
        balance = new UtxoBalance();
        List<UtxoOutput> outputs = new CopyOnWriteArrayList<>();
        outputs.add(output);
        balance.setUnSpends(outputs);
        putBalance(address, balance);
    } else {
        balance.getUnSpends().add(output);
        if (balance.getUnSpends().size() > 1) {
            Collections.sort(balance.getUnSpends());
        }
    }
}
Also used : UtxoBalance(io.nuls.ledger.entity.UtxoBalance) UtxoOutput(io.nuls.ledger.entity.UtxoOutput) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 2 with UtxoOutput

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

the class LedgerCacheService method updateUtxoStatus.

public boolean updateUtxoStatus(String key, OutPutStatusEnum newStatus, OutPutStatusEnum oldStatus) {
    if (!utxoCacheService.containsKey(LedgerConstant.UTXO, key)) {
        return false;
    }
    UtxoOutput output = utxoCacheService.getElement(LedgerConstant.UTXO, key);
    if (output.getStatus() != oldStatus) {
        return false;
    }
    output.setStatus(newStatus);
    return true;
}
Also used : UtxoOutput(io.nuls.ledger.entity.UtxoOutput)

Example 3 with UtxoOutput

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

the class UtxoCoinManager method cacheAllUnSpendUtxo.

public void cacheAllUnSpendUtxo() {
    List<UtxoOutputPo> utxoOutputPos = outputDataService.getAllUnSpend();
    Set<String> addressSet = new HashSet<>();
    for (int i = 0; i < utxoOutputPos.size(); i++) {
        UtxoOutputPo po = utxoOutputPos.get(i);
        UtxoOutput output = UtxoTransferTool.toOutput(po);
        ledgerCacheService.putUtxo(output.getKey(), output);
        addressSet.add(po.getAddress());
    }
    for (String str : addressSet) {
        UtxoTransactionTool.getInstance().calcBalance(str, false);
    }
}
Also used : UtxoOutputPo(io.nuls.db.entity.UtxoOutputPo) UtxoOutput(io.nuls.ledger.entity.UtxoOutput) HashSet(java.util.HashSet)

Example 4 with UtxoOutput

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

the class UtxoLedgerServiceImpl method unlockTxApprove.

@Override
public void unlockTxApprove(String txHash) {
    boolean b = true;
    int index = 0;
    while (b) {
        UtxoOutput output = ledgerCacheService.getUtxo(txHash + "-" + index);
        if (output != null) {
            if (OutPutStatusEnum.UTXO_UNCONFIRM_CONSENSUS_LOCK == output.getStatus()) {
                output.setStatus(OutPutStatusEnum.UTXO_UNCONFIRM_UNSPEND);
            } else if (OutPutStatusEnum.UTXO_CONFIRM_CONSENSUS_LOCK == output.getStatus()) {
                output.setStatus(OutPutStatusEnum.UTXO_CONFIRM_UNSPEND);
            }
            index++;
        } else {
            b = false;
        }
    }
}
Also used : UtxoOutput(io.nuls.ledger.entity.UtxoOutput)

Example 5 with UtxoOutput

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

the class UtxoLedgerServiceImpl method unlockTxRollback.

@Override
@DbSession
public void unlockTxRollback(String txHash) {
    boolean b = true;
    int index = 0;
    while (b) {
        UtxoOutput output = ledgerCacheService.getUtxo(txHash + "-" + index);
        if (output != null) {
            if (OutPutStatusEnum.UTXO_UNCONFIRM_UNSPEND == output.getStatus()) {
                output.setStatus(OutPutStatusEnum.UTXO_UNCONFIRM_CONSENSUS_LOCK);
            } else if (OutPutStatusEnum.UTXO_CONFIRM_UNSPEND == output.getStatus()) {
                output.setStatus(OutPutStatusEnum.UTXO_CONFIRM_CONSENSUS_LOCK);
            }
            index++;
        } else {
            b = false;
        }
    }
    txDao.lockTxOutput(txHash);
}
Also used : UtxoOutput(io.nuls.ledger.entity.UtxoOutput) DbSession(io.nuls.db.transactional.annotation.DbSession)

Aggregations

UtxoOutput (io.nuls.ledger.entity.UtxoOutput)12 UtxoBalance (io.nuls.ledger.entity.UtxoBalance)4 NulsDigestData (io.nuls.core.chain.entity.NulsDigestData)2 UtxoData (io.nuls.ledger.entity.UtxoData)2 UtxoInput (io.nuls.ledger.entity.UtxoInput)2 ArrayList (java.util.ArrayList)2 Na (io.nuls.core.chain.entity.Na)1 NulsException (io.nuls.core.exception.NulsException)1 P2PKHScript (io.nuls.core.script.P2PKHScript)1 P2PKHScriptSig (io.nuls.core.script.P2PKHScriptSig)1 UtxoOutputPo (io.nuls.db.entity.UtxoOutputPo)1 DbSession (io.nuls.db.transactional.annotation.DbSession)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1