Skip to content

Commit

Permalink
fix: search transactions don't use address filter (#265)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Kammerlo authored Jan 8, 2025
1 parent 41dc9ed commit a866cc0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> findTxHashesByOwnerAddr(@Param("address") String ownerAddr);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ public List<BlockTx> searchTransaction(Operator operator, String txHash, String
List<TxnEntity> txnEntities;
Set<String> txHashes = new HashSet<>();
Optional.ofNullable(txHash).ifPresent(txHashes::add);
Optional.ofNullable(address).ifPresent(addr -> txHashes.addAll(addressUtxoRepository.findTxHashesByOwnerAddr(addr)));

Optional<String> addressOptional = Optional.ofNullable(address);
Set<String> 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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void searchAddressTransactions() {
.build();

List<BlockTransaction> blockTransactions = service.searchTransaction(req, 0L, 5L);
assertEquals(5, blockTransactions.size());
assertEquals(4, blockTransactions.size());
}

@Test
Expand Down

0 comments on commit a866cc0

Please sign in to comment.