Search in sources :

Example 6 with Alias

use of io.nuls.account.entity.Alias in project nuls by nuls-io.

the class AliasValidator method validate.

@Override
public ValidateResult validate(AliasTransaction tx) {
    Alias alias = tx.getTxData();
    if (StringUtils.isBlank(alias.getAddress()) || new Address(alias.getAddress()).getHash().length != 23) {
        return ValidateResult.getFailedResult("The address format error");
    }
    if (!StringUtils.validAlias(alias.getAlias())) {
        return ValidateResult.getFailedResult("The alias is between 3 to 20 characters");
    }
    AliasPo aliasPo = getAliasDataService().get(alias.getAlias());
    if (aliasPo != null) {
        return ValidateResult.getFailedResult("The alias has been occupied");
    }
    return ValidateResult.getSuccessResult();
}
Also used : Address(io.nuls.account.entity.Address) Alias(io.nuls.account.entity.Alias) AliasPo(io.nuls.db.entity.AliasPo)

Example 7 with Alias

use of io.nuls.account.entity.Alias in project nuls by nuls-io.

the class AccountResource method get.

@GET
@Path("/{address}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult get(@PathParam("address") String address) {
    RpcResult result;
    if (!Address.validAddress(address)) {
        result = RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
        return result;
    }
    Account account = accountService.getAccount(address);
    if (account == null) {
        Alias alias = accountService.getAlias(address);
        if (alias == null) {
            result = RpcResult.getFailed(ErrorCode.DATA_NOT_FOUND);
        } else {
            AccountDto dto = new AccountDto();
            dto.setAddress(address);
            dto.setAlias(alias.getAlias());
            result = RpcResult.getSuccess().setData(dto);
        }
    } else {
        result = RpcResult.getSuccess().setData(new AccountDto(account));
    }
    return result;
}
Also used : Account(io.nuls.account.entity.Account) Alias(io.nuls.account.entity.Alias)

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