From a866cc0bee3d32d5e42ac968dc9efc3861a65a66 Mon Sep 17 00:00:00 2001 From: Thomas Kammerlocher Date: Wed, 8 Jan 2025 07:42:45 +0100 Subject: [PATCH] fix: search transactions don't use address filter (#265) * fix: fixed a bug, where only stakeaddresses where searched, when address filter is active + Changed the behaviour if address is set and no txHashes are found, we return an empty list * fix: adjusted tests to the fix of address filtering --- .../model/repository/AddressUtxoRepository.java | 3 ++- .../api/search/service/LedgerSearchServiceImpl.java | 12 +++++++++++- .../api/search/service/SearchControllerIntTest.java | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/org/cardanofoundation/rosetta/api/account/model/repository/AddressUtxoRepository.java b/api/src/main/java/org/cardanofoundation/rosetta/api/account/model/repository/AddressUtxoRepository.java index cea19dd7..d428075f 100644 --- a/api/src/main/java/org/cardanofoundation/rosetta/api/account/model/repository/AddressUtxoRepository.java +++ b/api/src/main/java/org/cardanofoundation/rosetta/api/account/model/repository/AddressUtxoRepository.java @@ -27,7 +27,8 @@ AND NOT EXISTS ( @Query(value = """ SELECT a.txHash FROM AddressUtxoEntity a - WHERE a.ownerStakeAddr = :address + WHERE a.ownerAddr = :address + OR a.ownerStakeAddr = :address """) List findTxHashesByOwnerAddr(@Param("address") String ownerAddr); diff --git a/api/src/main/java/org/cardanofoundation/rosetta/api/search/service/LedgerSearchServiceImpl.java b/api/src/main/java/org/cardanofoundation/rosetta/api/search/service/LedgerSearchServiceImpl.java index 0617c029..9c2f6156 100644 --- a/api/src/main/java/org/cardanofoundation/rosetta/api/search/service/LedgerSearchServiceImpl.java +++ b/api/src/main/java/org/cardanofoundation/rosetta/api/search/service/LedgerSearchServiceImpl.java @@ -41,7 +41,17 @@ public List searchTransaction(Operator operator, String txHash, String List txnEntities; Set txHashes = new HashSet<>(); Optional.ofNullable(txHash).ifPresent(txHashes::add); - Optional.ofNullable(address).ifPresent(addr -> txHashes.addAll(addressUtxoRepository.findTxHashesByOwnerAddr(addr))); + + Optional addressOptional = Optional.ofNullable(address); + Set addressTxHashes = new HashSet<>(); + addressOptional.ifPresent(addr -> addressTxHashes.addAll(addressUtxoRepository.findTxHashesByOwnerAddr(addr))); + // If Address was set and there weren't any transactions found, return empty list + if (addressOptional.isPresent() && addressTxHashes.isEmpty()) { + return List.of(); + } else { + txHashes.addAll(addressTxHashes); + } + Optional.ofNullable(utxoKey).ifPresent(utxo -> { txHashes.add(utxo.getTxHash()); txHashes.addAll(txInputRepository.findSpentTxHashByUtxoKey(utxoKey.getTxHash(), utxoKey.getOutputIndex())); diff --git a/api/src/test/java/org/cardanofoundation/rosetta/api/search/service/SearchControllerIntTest.java b/api/src/test/java/org/cardanofoundation/rosetta/api/search/service/SearchControllerIntTest.java index 95ab9a24..a9dac589 100644 --- a/api/src/test/java/org/cardanofoundation/rosetta/api/search/service/SearchControllerIntTest.java +++ b/api/src/test/java/org/cardanofoundation/rosetta/api/search/service/SearchControllerIntTest.java @@ -28,7 +28,7 @@ void searchAddressTransactions() { .build(); List blockTransactions = service.searchTransaction(req, 0L, 5L); - assertEquals(5, blockTransactions.size()); + assertEquals(4, blockTransactions.size()); } @Test