use of io.nuls.account.entity.Alias in project nuls by nuls-io.
the class AccountServiceImpl method getAlias.
@Override
public Alias getAlias(String address) {
AliasPo aliasPo = aliasDataService.getByAddress(address);
if (aliasPo == null) {
return null;
}
Alias alias = new Alias(aliasPo.getAddress(), aliasPo.getAlias());
return alias;
}
use of io.nuls.account.entity.Alias in project nuls by nuls-io.
the class AliasTxService method onApproval.
@Override
public void onApproval(AliasTransaction tx) throws NulsException {
Alias alias = tx.getTxData();
AliasPo po = getAliasDataService().getAlias(alias.getAlias());
if (po != null) {
throw new NulsException(ErrorCode.ALIAS_EXIST);
}
}
use of io.nuls.account.entity.Alias in project nuls by nuls-io.
the class AliasTxService method onCommit.
@Override
public void onCommit(AliasTransaction tx) throws NulsException {
Alias alias = tx.getTxData();
alias.setStatus(1);
getAliasDataService().saveAlias(AccountTool.toAliasPojo(alias));
}
use of io.nuls.account.entity.Alias in project nuls by nuls-io.
the class AccountTool method toAliasBean.
public static Alias toAliasBean(AliasPo po) {
Alias alias = new Alias(po.getAddress(), po.getAlias());
alias.setStatus(po.getStatus());
return alias;
}
use of io.nuls.account.entity.Alias 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