use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.
the class ConsensusMeetingRunner method addOrphanTx.
private void addOrphanTx(List<Transaction> txList, long totalSize, PocMeetingMember self) {
if ((self.getPackTime() - TimeService.currentTimeMillis()) <= 100) {
return;
}
List<Transaction> orphanTxList = orphanTxCacheManager.getTxList();
if (null == orphanTxList || orphanTxList.isEmpty()) {
return;
}
txList.sort(TxTimeComparator.getInstance());
List<NulsDigestData> outHashList = new ArrayList<>();
for (Transaction tx : orphanTxList) {
if ((self.getPackTime() - TimeService.currentTimeMillis()) <= 100) {
break;
}
totalSize += tx.size();
if (totalSize >= PocConsensusConstant.MAX_BLOCK_SIZE) {
break;
}
ValidateResult result = tx.verify();
if (result.isFailed()) {
Log.error(result.getMessage());
continue;
}
try {
ledgerService.approvalTx(tx);
} catch (Exception e) {
Log.error(result.getMessage());
Log.error(e);
continue;
}
confirmingTxCacheManager.putTx(tx);
txList.add(tx);
outHashList.add(tx.getHash());
}
orphanTxCacheManager.removeTx(outHashList);
}
use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.
the class TxGroup method serializeToStream.
@Override
protected void serializeToStream(NulsOutputStreamBuffer stream) throws IOException {
stream.writeNulsData(blockHash);
stream.writeVarInt(txList.size());
for (Transaction data : txList) {
stream.writeNulsData(data);
}
}
use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.
the class TransactionManager method getInstanceByType.
public static Transaction getInstanceByType(int txType) throws Exception {
Class<? extends Transaction> txClass = getTxClass(txType);
if (null == txClass) {
throw new NulsRuntimeException(ErrorCode.FAILED, "transaction type not exist!");
}
Transaction tx = txClass.getConstructor().newInstance();
return tx;
}
use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.
the class BlockManager method rollbackTxList.
private void rollbackTxList(List<Transaction> txList, int start, int end) {
List<NulsDigestData> txHashList = new ArrayList<>();
for (int i = start; i <= end && i < txList.size(); i++) {
Transaction tx = txList.get(i);
if (tx.getStatus() == TxStatusEnum.AGREED) {
try {
ledgerService.rollbackTx(tx);
} catch (NulsException e) {
Log.error(e);
}
txHashList.add(tx.getHash());
}
}
confirmingTxCacheManager.removeTxList(txHashList);
}
use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.
the class BlockManager method appravalBlock.
private void appravalBlock(Block block) {
for (int i = 0; i < block.getHeader().getTxCount(); i++) {
Transaction tx = block.getTxs().get(i);
tx.setBlockHeight(block.getHeader().getHeight());
tx.setIndex(i);
tx.setIndex(i);
if (tx.getStatus() == null || tx.getStatus() == TxStatusEnum.CACHED) {
try {
this.ledgerService.approvalTx(tx);
confirmingTxCacheManager.putTx(tx);
} catch (NulsException e) {
rollbackTxList(block.getTxs(), 0, i);
Log.error(e);
throw new NulsRuntimeException(e);
}
}
}
txCacheManager.removeTx(block.getTxHashList());
}
Aggregations