use of io.nuls.account.entity.tx.AliasTransaction 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");
}
Aggregations