use of io.nuls.ledger.event.TransactionEvent in project nuls by nuls-io.
the class AccountServiceImpl method setAlias.
@Override
public Result setAlias(String address, String password, String alias) {
Account account = getAccount(address);
if (account == null) {
return new Result(false, ErrorCode.ACCOUNT_NOT_EXIST, null);
}
if (StringUtils.isNotBlank(account.getAlias())) {
return new Result(false, "Alias has been set up");
}
if (!StringUtils.validAlias(alias)) {
return new Result(false, "The alias is between 3 to 20 characters");
}
try {
TransactionEvent event = new TransactionEvent();
CoinTransferData coinData = new CoinTransferData(OperationType.TRANSFER, AccountConstant.ALIAS_NA, address, ledgerService.getTxFee(TransactionConstant.TX_TYPE_SET_ALIAS));
AliasTransaction aliasTx = new AliasTransaction(coinData, password, new Alias(address, alias));
aliasTx.setHash(NulsDigestData.calcDigestData(aliasTx.serialize()));
aliasTx.setScriptSig(createP2PKHScriptSigFromDigest(aliasTx.getHash(), account, password).serialize());
ValidateResult validate = aliasTx.verify();
if (validate.isFailed()) {
return new Result(false, validate.getMessage());
}
event.setEventBody(aliasTx);
eventBroadcaster.broadcastAndCache(event, true);
SetAliasNotice notice = new SetAliasNotice();
notice.setEventBody(aliasTx);
eventBroadcaster.publishToLocal(notice);
} catch (Exception e) {
Log.error(e);
return new Result(false, e.getMessage());
}
return new Result(true, "OK");
}
use of io.nuls.ledger.event.TransactionEvent 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