Search in sources :

Example 31 with Transaction

use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.

the class CoinbaseValidator method validate.

@Override
public ValidateResult validate(Block block) {
    if (null == block || block.getHeader() == null || null == block.getTxs() || block.getTxs().isEmpty()) {
        return ValidateResult.getFailedResult(ErrorCode.DATA_FIELD_CHECK_ERROR);
    }
    Transaction tx = block.getTxs().get(0);
    if (tx.getType() != TransactionConstant.TX_TYPE_COIN_BASE) {
        return ValidateResult.getFailedResult("Coinbase transaction order wrong!");
    }
    for (int i = 1; i < block.getTxs().size(); i++) {
        Transaction transaction = block.getTxs().get(i);
        if (transaction.getType() == TransactionConstant.TX_TYPE_COIN_BASE) {
            ValidateResult result = ValidateResult.getFailedResult("Coinbase transaction more than one!");
            result.setLevel(SeverityLevelEnum.FLAGRANT_FOUL);
            return result;
        }
    }
    BlockRoundData blockRound = null;
    try {
        blockRound = new BlockRoundData(block.getHeader().getExtend());
    } catch (NulsException e) {
        Log.error(e);
    }
    if (null == blockRound) {
        return ValidateResult.getFailedResult("Cann't get the round data!");
    }
    return ValidateResult.getSuccessResult();
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) NulsException(io.nuls.core.exception.NulsException) ValidateResult(io.nuls.core.validate.ValidateResult) BlockRoundData(io.nuls.consensus.entity.block.BlockRoundData)

Example 32 with Transaction

use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.

the class ConfrimingBlockCacheManager method getBlock.

public Block getBlock(String hash) {
    if (null == txsCacheMap || headerCacheMap == null) {
        return null;
    }
    BlockHeader header = headerCacheMap.get(hash);
    List<Transaction> txs = txsCacheMap.get(hash);
    if (null == header || null == txs || txs.isEmpty()) {
        return null;
    }
    Block block = new Block();
    block.setHeader(header);
    block.setTxs(txs);
    return block;
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) Block(io.nuls.core.chain.entity.Block) BlockHeader(io.nuls.core.chain.entity.BlockHeader)

Example 33 with Transaction

use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.

the class UtxoTransferTool method toTransaction.

public static Transaction toTransaction(TransactionPo po) throws Exception {
    Transaction tx = TransactionManager.getInstanceByType(po.getType());
    tx.setHash(new NulsDigestData(Hex.decode(po.getHash())));
    tx.setTime(po.getCreateTime());
    tx.setBlockHeight(po.getBlockHeight());
    tx.setFee(Na.valueOf(po.getFee()));
    tx.setIndex(po.getTxIndex());
    tx.setSize(po.getSize());
    tx.setScriptSig(po.getScriptSig());
    if (StringUtils.isNotBlank(po.getRemark())) {
        tx.setRemark(po.getRemark().getBytes(NulsContext.DEFAULT_ENCODING));
    }
    if (null != po.getTxData()) {
        tx.setTxData(tx.parseTxData(new NulsByteBuffer(po.getTxData())));
    }
    transferCoinData(tx, po.getInputs(), po.getOutputs());
    tx.setStatus(TxStatusEnum.CONFIRMED);
    return tx;
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) AbstractCoinTransaction(io.nuls.ledger.entity.tx.AbstractCoinTransaction) LockNulsTransaction(io.nuls.ledger.entity.tx.LockNulsTransaction) NulsDigestData(io.nuls.core.chain.entity.NulsDigestData) NulsByteBuffer(io.nuls.core.utils.io.NulsByteBuffer)

Example 34 with Transaction

use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.

the class UtxoTransferTool method toTransaction.

public static Transaction toTransaction(TransactionLocalPo po) throws Exception {
    Transaction tx = TransactionManager.getInstanceByType(po.getType());
    tx.setHash(new NulsDigestData(Hex.decode(po.getHash())));
    tx.setTime(po.getCreateTime());
    tx.setBlockHeight(po.getBlockHeight());
    tx.setFee(Na.valueOf(po.getFee()));
    tx.setIndex(po.getTxIndex());
    tx.setTransferType(po.getTransferType());
    tx.setSize(po.getSize());
    tx.setScriptSig(po.getScriptSig());
    if (StringUtils.isNotBlank(po.getRemark())) {
        tx.setRemark(po.getRemark().getBytes(NulsContext.DEFAULT_ENCODING));
    }
    if (null != po.getTxData()) {
        tx.parseTxData(new NulsByteBuffer(po.getTxData()));
    }
    tx.setStatus(TxStatusEnum.CONFIRMED);
    transferCoinData(tx, po.getInputs(), po.getOutputs());
    return tx;
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) AbstractCoinTransaction(io.nuls.ledger.entity.tx.AbstractCoinTransaction) LockNulsTransaction(io.nuls.ledger.entity.tx.LockNulsTransaction) NulsDigestData(io.nuls.core.chain.entity.NulsDigestData) NulsByteBuffer(io.nuls.core.utils.io.NulsByteBuffer)

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