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