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