use of io.nuls.db.transactional.annotation.DbSession in project nuls by nuls-io.
the class UtxoLedgerServiceImpl method saveTxList.
@Override
@DbSession
public boolean saveTxList(List<Transaction> txList) throws IOException {
lock.lock();
try {
List<TransactionPo> poList = new ArrayList<>();
List<TransactionLocalPo> localPoList = new ArrayList<>();
for (int i = 0; i < txList.size(); i++) {
Transaction tx = txList.get(i);
boolean isMine = false;
try {
isMine = this.checkTxIsMine(tx);
} catch (NulsException e) {
throw new NulsRuntimeException(e);
}
TransactionPo po = UtxoTransferTool.toTransactionPojo(tx);
poList.add(po);
if (isMine) {
TransactionLocalPo localPo = UtxoTransferTool.toLocalTransactionPojo(tx);
localPoList.add(localPo);
}
}
txDao.saveTxList(poList);
if (localPoList.size() > 0) {
txDao.saveLocalList(localPoList);
}
} finally {
lock.unlock();
}
return false;
}
use of io.nuls.db.transactional.annotation.DbSession in project nuls by nuls-io.
the class UtxoLedgerServiceImpl method saveTxInLocal.
@Override
@DbSession
public void saveTxInLocal(String address) {
List<TransactionPo> poList = txDao.getTxs(null, address, 0, 0, 0);
if (poList.isEmpty()) {
return;
}
List<TransactionLocalPo> localPoList = new ArrayList<>();
for (TransactionPo po : poList) {
TransactionLocalPo localPo = txDao.getLocaltx(po.getHash());
if (localPo != null) {
continue;
}
localPo = new TransactionLocalPo(po);
for (UtxoInputPo inputPo : po.getInputs()) {
if (inputPo.getFromOutPut().getAddress().equals(address)) {
localPo.setTransferType(Transaction.TRANSFER_SEND);
break;
}
}
localPoList.add(localPo);
}
txDao.saveLocalList(localPoList);
}
use of io.nuls.db.transactional.annotation.DbSession 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);
}
use of io.nuls.db.transactional.annotation.DbSession in project nuls by nuls-io.
the class BlockServiceImpl method saveBlock.
@Override
@DbSession
public boolean saveBlock(Block block) throws IOException {
block.verifyWithException();
boolean b = false;
for (int x = 0; x < block.getHeader().getTxCount(); x++) {
Transaction tx = block.getTxs().get(x);
if (tx.getStatus() == TxStatusEnum.CACHED) {
b = true;
tx.setBlockHeight(block.getHeader().getHeight());
try {
ledgerService.approvalTx(tx);
} catch (Exception e) {
Log.error(e);
rollback(block.getTxs(), x);
throw new NulsRuntimeException(e);
}
}
}
if (b) {
block.verifyWithException();
}
for (int x = 0; x < block.getHeader().getTxCount(); x++) {
Transaction tx = block.getTxs().get(x);
if (tx.getStatus() == TxStatusEnum.AGREED) {
tx.setBlockHeight(block.getHeader().getHeight());
try {
ledgerService.commitTx(tx);
} catch (Exception e) {
Log.error(e);
rollback(block.getTxs(), x);
throw new NulsRuntimeException(e);
}
}
}
ledgerService.saveTxList(block.getTxs());
blockStorageService.save(block);
return true;
}
use of io.nuls.db.transactional.annotation.DbSession in project nuls by nuls-io.
the class BlockServiceImpl method rollbackBlock.
@Override
@DbSession
public void rollbackBlock(long height) {
Block block = this.getBlock(height);
if (null == block) {
return;
}
blockManager.rollback(block);
this.rollback(block.getTxs(), block.getTxs().size() - 1);
this.ledgerService.deleteTx(block.getHeader().getHeight());
blockStorageService.delete(block.getHeader().getHash().getDigestHex());
}
Aggregations