diff --git a/api/src/main/java/org/cardanofoundation/rosetta/api/account/service/AccountServiceImpl.java b/api/src/main/java/org/cardanofoundation/rosetta/api/account/service/AccountServiceImpl.java index a57f908a..a1b684ed 100644 --- a/api/src/main/java/org/cardanofoundation/rosetta/api/account/service/AccountServiceImpl.java +++ b/api/src/main/java/org/cardanofoundation/rosetta/api/account/service/AccountServiceImpl.java @@ -75,10 +75,9 @@ public AccountCoinsResponse getAccountCoins(AccountCoinsRequest accountCoinsRequ log.debug("[accountCoins] Request received {}", accountCoinsRequest); if (Objects.isNull(CardanoAddressUtils.getEraAddressType(accountAddress))) { - log.debug("[accountCoins] Address isn't Era"); + log.debug("[findBalanceDataByAddressAndBlock] Provided address is invalid {}", accountAddress); throw ExceptionFactory.invalidAddressError(accountAddress); } - log.debug("[accountCoins] Address is Era"); if (Objects.nonNull(currencies)) { validateCurrencies(currencies); } diff --git a/api/src/main/java/org/cardanofoundation/rosetta/common/util/CardanoAddressUtils.java b/api/src/main/java/org/cardanofoundation/rosetta/common/util/CardanoAddressUtils.java index 179542c6..852a892f 100644 --- a/api/src/main/java/org/cardanofoundation/rosetta/common/util/CardanoAddressUtils.java +++ b/api/src/main/java/org/cardanofoundation/rosetta/common/util/CardanoAddressUtils.java @@ -9,6 +9,7 @@ import com.bloxbean.cardano.client.address.AddressType; import com.bloxbean.cardano.client.address.ByronAddress; import com.bloxbean.cardano.client.address.util.AddressEncoderDecoderUtil; +import com.bloxbean.cardano.client.address.util.AddressUtil; import com.bloxbean.cardano.client.common.model.Network; import com.bloxbean.cardano.client.crypto.Bech32; import com.bloxbean.cardano.client.crypto.KeyGenUtil; @@ -163,9 +164,9 @@ public static Object generateAddress(String address) { } public static EraAddressType getEraAddressType(String address) { - if(address == null) - return null; try { + if(address == null || !AddressUtil.isValidAddress(address)) + return null; if (address.startsWith(Constants.ADDRESS_PREFIX) || address.startsWith(StakeAddressPrefix.MAIN.getPrefix())) { // validate bech32 address. Unfortunately, it will throw a runtime exception in case of invalid address