use of io.nuls.core.utils.io.NulsByteBuffer 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;
}
use of io.nuls.core.utils.io.NulsByteBuffer in project nuls by nuls-io.
the class UtxoLedgerServiceImpl method transfer.
private Result transfer(CoinTransferData coinData, String password, String remark) {
TransferTransaction tx = null;
try {
tx = UtxoTransactionTool.getInstance().createTransferTx(coinData, password, remark);
ValidateResult result = tx.verify();
if (result.isFailed()) {
throw new NulsException(result.getErrorCode());
}
byte[] txbytes = tx.serialize();
TransferTransaction new_tx = new NulsByteBuffer(txbytes).readNulsData(new TransferTransaction());
result = new_tx.verify();
if (result.isFailed()) {
throw new NulsException(result.getErrorCode());
}
TransactionEvent event = new TransactionEvent();
event.setEventBody(tx);
eventBroadcaster.broadcastAndCacheAysn(event, true);
} catch (Exception e) {
Log.error(e);
return new Result(false, e.getMessage());
}
return new Result(true, "OK", tx.getHash().getDigestHex());
}
use of io.nuls.core.utils.io.NulsByteBuffer in project nuls by nuls-io.
the class NulsMessage method parse.
public void parse(ByteBuffer byteBuffer) throws NulsException {
byte[] headers = new byte[NulsMessageHeader.MESSAGE_HEADER_SIZE];
byteBuffer.get(headers, 0, headers.length);
NulsMessageHeader header = new NulsMessageHeader(new NulsByteBuffer(headers));
byte[] data = new byte[header.getLength()];
byteBuffer.get(data, 0, data.length);
this.header = header;
this.data = data;
}
use of io.nuls.core.utils.io.NulsByteBuffer in project nuls by nuls-io.
the class EventManager method getInstance.
public static BaseEvent getInstance(byte[] bytes) throws NulsException {
EventHeader header = new EventHeader();
header.parse(new NulsByteBuffer(bytes));
Class<? extends BaseEvent> clazz = EVENT_MAP.get(header.getModuleId() + "_" + header.getEventType());
if (null == clazz) {
return null;
}
BaseEvent event;
try {
event = clazz.newInstance();
} catch (Exception e) {
Log.error(e);
throw new NulsException(ErrorCode.DATA_PARSE_ERROR);
}
try {
event.parse(new NulsByteBuffer(bytes));
} catch (Exception e) {
Log.error(e);
throw e;
}
return event;
}
Aggregations