Search in sources :

Example 1 with Alias

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;
}
Also used : Alias(io.nuls.account.entity.Alias) AliasPo(io.nuls.db.entity.AliasPo)

Example 2 with 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);
    }
}
Also used : Alias(io.nuls.account.entity.Alias) NulsException(io.nuls.core.exception.NulsException) AliasPo(io.nuls.db.entity.AliasPo)

Example 3 with Alias

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));
}
Also used : Alias(io.nuls.account.entity.Alias)

Example 4 with 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;
}
Also used : Alias(io.nuls.account.entity.Alias)

Example 5 with 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");
}
Also used : Account(io.nuls.account.entity.Account) AliasTransaction(io.nuls.account.entity.tx.AliasTransaction) TransactionEvent(io.nuls.ledger.event.TransactionEvent) CoinTransferData(io.nuls.ledger.entity.params.CoinTransferData) Alias(io.nuls.account.entity.Alias) ValidateResult(io.nuls.core.validate.ValidateResult) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) ValidateResult(io.nuls.core.validate.ValidateResult) Result(io.nuls.core.chain.entity.Result)

Aggregations

Alias (io.nuls.account.entity.Alias)7 AliasPo (io.nuls.db.entity.AliasPo)3 Account (io.nuls.account.entity.Account)2 NulsException (io.nuls.core.exception.NulsException)2 Address (io.nuls.account.entity.Address)1 AliasTransaction (io.nuls.account.entity.tx.AliasTransaction)1 Result (io.nuls.core.chain.entity.Result)1 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)1 ValidateResult (io.nuls.core.validate.ValidateResult)1 CoinTransferData (io.nuls.ledger.entity.params.CoinTransferData)1 TransactionEvent (io.nuls.ledger.event.TransactionEvent)1 IOException (java.io.IOException)1