Search in sources :

Example 6 with NulsByteBuffer

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;
}
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 7 with NulsByteBuffer

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());
}
Also used : TransactionEvent(io.nuls.ledger.event.TransactionEvent) NulsException(io.nuls.core.exception.NulsException) ValidateResult(io.nuls.core.validate.ValidateResult) TransferTransaction(io.nuls.ledger.entity.tx.TransferTransaction) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) NulsByteBuffer(io.nuls.core.utils.io.NulsByteBuffer) ValidateResult(io.nuls.core.validate.ValidateResult)

Example 8 with NulsByteBuffer

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;
}
Also used : NulsByteBuffer(io.nuls.core.utils.io.NulsByteBuffer)

Example 9 with NulsByteBuffer

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

Aggregations

NulsByteBuffer (io.nuls.core.utils.io.NulsByteBuffer)9 NulsDigestData (io.nuls.core.chain.entity.NulsDigestData)3 Transaction (io.nuls.core.chain.entity.Transaction)3 NulsException (io.nuls.core.exception.NulsException)3 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)3 P2PKHScriptSig (io.nuls.core.script.P2PKHScriptSig)2 AbstractCoinTransaction (io.nuls.ledger.entity.tx.AbstractCoinTransaction)2 LockNulsTransaction (io.nuls.ledger.entity.tx.LockNulsTransaction)2 ValidateResult (io.nuls.core.validate.ValidateResult)1 TransferTransaction (io.nuls.ledger.entity.tx.TransferTransaction)1 TransactionEvent (io.nuls.ledger.event.TransactionEvent)1 IOException (java.io.IOException)1