use of io.nuls.core.utils.io.NulsByteBuffer in project nuls by nuls-io.
the class GetBlocksHashParam method main.
public static void main(String[] args) throws Exception {
GetBlocksHashParam param = new GetBlocksHashParam();
param.parse(new NulsByteBuffer(Hex.decode("ffff1d50746101000000000100000100")));
}
use of io.nuls.core.utils.io.NulsByteBuffer in project nuls by nuls-io.
the class TxSignValidator method validate.
@Override
public ValidateResult validate(Transaction tx) {
byte[] scriptSig = tx.getScriptSig();
tx.setScriptSig(null);
NulsDigestData nulsDigestData;
try {
nulsDigestData = NulsDigestData.calcDigestData(tx.serialize());
} catch (Exception e) {
return ValidateResult.getFailedResult(ErrorCode.DATA_ERROR);
} finally {
tx.setScriptSig(scriptSig);
}
if (!Arrays.equals(nulsDigestData.getDigestBytes(), tx.getHash().getDigestBytes())) {
return ValidateResult.getFailedResult(ErrorCode.DATA_ERROR);
}
P2PKHScriptSig p2PKHScriptSig = null;
try {
p2PKHScriptSig = new NulsByteBuffer(scriptSig).readNulsData(new P2PKHScriptSig());
} catch (NulsException e) {
return ValidateResult.getFailedResult(ErrorCode.SIGNATURE_ERROR);
}
return p2PKHScriptSig.verifySign(tx.getHash());
}
use of io.nuls.core.utils.io.NulsByteBuffer in project nuls by nuls-io.
the class ConsensusTool method fromPojo.
public static final BlockHeader fromPojo(BlockHeaderPo po) throws NulsException {
if (null == po) {
return null;
}
BlockHeader header = new BlockHeader();
header.setHash(NulsDigestData.fromDigestHex(po.getHash()));
header.setMerkleHash(NulsDigestData.fromDigestHex(po.getMerkleHash()));
header.setPackingAddress(po.getConsensusAddress());
header.setTxCount(po.getTxCount());
header.setPreHash(NulsDigestData.fromDigestHex(po.getPreHash()));
header.setTime(po.getCreateTime());
header.setHeight(po.getHeight());
header.setExtend(po.getExtend());
header.setSize(po.getSize());
header.setScriptSig((new NulsByteBuffer(po.getScriptSig()).readNulsData(new P2PKHScriptSig())));
return header;
}
use of io.nuls.core.utils.io.NulsByteBuffer in project nuls by nuls-io.
the class TransactionManager method getInstance.
public static Transaction getInstance(NulsByteBuffer byteBuffer) throws Exception {
int txType = (int) new NulsByteBuffer(byteBuffer.getPayloadByCursor()).readVarInt();
Class<? extends Transaction> txClass = getTxClass(txType);
if (null == txClass) {
throw new NulsRuntimeException(ErrorCode.FAILED, "transaction type not exist!");
}
Transaction tx = byteBuffer.readNulsData(txClass.getConstructor().newInstance());
return tx;
}
use of io.nuls.core.utils.io.NulsByteBuffer 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;
}
Aggregations