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