Skip to content

Commit

Permalink
Fix/add address check (#238)
Browse files Browse the repository at this point in the history
* fix: added address check if valid to getEraAddressType

* fix: added address check if valid to getEraAddressType

* fix: added address check if valid to getEraAddressType
  • Loading branch information
Kammerlo authored Aug 16, 2024
1 parent 27533c8 commit c3592f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c3592f8

Please sign in to comment.