Search in sources :

Example 6 with Transaction

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);
}
Also used : CoinBaseTransaction(io.nuls.ledger.entity.tx.CoinBaseTransaction) Transaction(io.nuls.core.chain.entity.Transaction) RedPunishTransaction(io.nuls.consensus.entity.tx.RedPunishTransaction) YellowPunishTransaction(io.nuls.consensus.entity.tx.YellowPunishTransaction) ValidateResult(io.nuls.core.validate.ValidateResult) NulsDigestData(io.nuls.core.chain.entity.NulsDigestData) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 7 with Transaction

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);
    }
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction)

Example 8 with Transaction

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;
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 9 with Transaction

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);
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) NulsException(io.nuls.core.exception.NulsException) ArrayList(java.util.ArrayList) NulsDigestData(io.nuls.core.chain.entity.NulsDigestData)

Example 10 with Transaction

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());
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) NulsException(io.nuls.core.exception.NulsException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Aggregations

Transaction (io.nuls.core.chain.entity.Transaction)34 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)13 NulsException (io.nuls.core.exception.NulsException)12 Block (io.nuls.core.chain.entity.Block)8 HashMap (java.util.HashMap)7 NulsDigestData (io.nuls.core.chain.entity.NulsDigestData)6 ValidateResult (io.nuls.core.validate.ValidateResult)6 BlockHeader (io.nuls.core.chain.entity.BlockHeader)5 IOException (java.io.IOException)5 Deposit (io.nuls.consensus.entity.member.Deposit)4 PocExitConsensusTransaction (io.nuls.consensus.entity.tx.PocExitConsensusTransaction)4 PocJoinConsensusTransaction (io.nuls.consensus.entity.tx.PocJoinConsensusTransaction)4 RegisterAgentTransaction (io.nuls.consensus.entity.tx.RegisterAgentTransaction)4 ArrayList (java.util.ArrayList)4 RedPunishTransaction (io.nuls.consensus.entity.tx.RedPunishTransaction)3 YellowPunishTransaction (io.nuls.consensus.entity.tx.YellowPunishTransaction)3 NulsByteBuffer (io.nuls.core.utils.io.NulsByteBuffer)3 AbstractCoinTransaction (io.nuls.ledger.entity.tx.AbstractCoinTransaction)3 CoinBaseTransaction (io.nuls.ledger.entity.tx.CoinBaseTransaction)3 Account (io.nuls.account.entity.Account)2