Search in sources :

Example 1 with TransferTransaction

use of io.nuls.ledger.entity.tx.TransferTransaction in project nuls by nuls-io.

the class UtxoTransactionTool method createTransferTx.

public TransferTransaction createTransferTx(CoinTransferData transferData, String password, String remark) throws Exception {
    if (transferData.getFrom().isEmpty()) {
        throw new NulsRuntimeException(ErrorCode.DATA_ERROR);
    }
    TransferTransaction tx = new TransferTransaction(transferData, password);
    if (StringUtils.isNotBlank(remark)) {
        tx.setRemark(remark.getBytes(NulsContext.DEFAULT_ENCODING));
    }
    tx.setHash(NulsDigestData.calcDigestData(tx.serialize()));
    AccountService accountService = getAccountService();
    Account account = accountService.getAccount(transferData.getFrom().get(0));
    tx.setScriptSig(accountService.createP2PKHScriptSigFromDigest(tx.getHash(), account, password).serialize());
    return tx;
}
Also used : Account(io.nuls.account.entity.Account) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) TransferTransaction(io.nuls.ledger.entity.tx.TransferTransaction) AccountService(io.nuls.account.service.intf.AccountService)

Example 2 with TransferTransaction

use of io.nuls.ledger.entity.tx.TransferTransaction 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)

Aggregations

NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)2 TransferTransaction (io.nuls.ledger.entity.tx.TransferTransaction)2 Account (io.nuls.account.entity.Account)1 AccountService (io.nuls.account.service.intf.AccountService)1 NulsException (io.nuls.core.exception.NulsException)1 NulsByteBuffer (io.nuls.core.utils.io.NulsByteBuffer)1 ValidateResult (io.nuls.core.validate.ValidateResult)1 TransactionEvent (io.nuls.ledger.event.TransactionEvent)1 IOException (java.io.IOException)1