forked from Qortal/qortal
Allow multiple txType in API GET /transactions/search
This commit is contained in:
parent
b0b74eb48d
commit
b4d0f9ab68
@ -291,7 +291,7 @@ public class TransactionsResource {
|
||||
ApiError.INVALID_CRITERIA, ApiError.REPOSITORY_ISSUE
|
||||
})
|
||||
public List<TransactionData> searchTransactions(@QueryParam("startBlock") Integer startBlock, @QueryParam("blockLimit") Integer blockLimit,
|
||||
@QueryParam("txType") TransactionType txType, @QueryParam("address") String address, @Parameter(
|
||||
@QueryParam("txType") List<TransactionType> txTypes, @QueryParam("address") String address, @Parameter(
|
||||
description = "whether to include confirmed, unconfirmed or both",
|
||||
required = true
|
||||
) @QueryParam("confirmationStatus") ConfirmationStatus confirmationStatus, @Parameter(
|
||||
@ -302,7 +302,7 @@ public class TransactionsResource {
|
||||
ref = "reverse"
|
||||
) @QueryParam("reverse") Boolean reverse) {
|
||||
// Must have at least one of txType / address / limit <= 20
|
||||
if (txType == null && (address == null || address.isEmpty()) && (limit == null || limit > 20))
|
||||
if ((txTypes == null || txTypes.isEmpty()) && (address == null || address.isEmpty()) && (limit == null || limit > 20))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA);
|
||||
|
||||
// You can't ask for unconfirmed and impose a block height range
|
||||
@ -310,7 +310,7 @@ public class TransactionsResource {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA);
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
List<byte[]> signatures = repository.getTransactionRepository().getSignaturesMatchingCriteria(startBlock, blockLimit, txType, address,
|
||||
List<byte[]> signatures = repository.getTransactionRepository().getSignaturesMatchingCriteria(startBlock, blockLimit, txTypes, address,
|
||||
confirmationStatus, limit, offset, reverse);
|
||||
|
||||
// Expand signatures to transactions
|
||||
|
@ -46,7 +46,7 @@ public interface TransactionRepository {
|
||||
*/
|
||||
public Map<TransactionType, Integer> getTransactionSummary(int startHeight, int endHeight) throws DataException;
|
||||
|
||||
public List<byte[]> getSignaturesMatchingCriteria(Integer startBlock, Integer blockLimit, TransactionType txType, String address,
|
||||
public List<byte[]> getSignaturesMatchingCriteria(Integer startBlock, Integer blockLimit, List<TransactionType> txTypes, String address,
|
||||
ConfirmationStatus confirmationStatus, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||
|
||||
/**
|
||||
|
@ -355,12 +355,12 @@ public class HSQLDBTransactionRepository implements TransactionRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<byte[]> getSignaturesMatchingCriteria(Integer startBlock, Integer blockLimit, TransactionType txType, String address,
|
||||
public List<byte[]> getSignaturesMatchingCriteria(Integer startBlock, Integer blockLimit, List<TransactionType> txTypes, String address,
|
||||
ConfirmationStatus confirmationStatus, Integer limit, Integer offset, Boolean reverse) throws DataException {
|
||||
List<byte[]> signatures = new ArrayList<byte[]>();
|
||||
|
||||
boolean hasAddress = address != null && !address.isEmpty();
|
||||
boolean hasTxType = txType != null;
|
||||
boolean hasTxTypes = txTypes != null && !txTypes.isEmpty();
|
||||
boolean hasHeightRange = startBlock != null || blockLimit != null;
|
||||
|
||||
if (hasHeightRange && startBlock == null)
|
||||
@ -407,8 +407,10 @@ public class HSQLDBTransactionRepository implements TransactionRepository {
|
||||
whereClauses.add("Blocks.height < " + (startBlock + blockLimit));
|
||||
}
|
||||
|
||||
if (hasTxType)
|
||||
whereClauses.add("Transactions.type = " + txType.value);
|
||||
if (hasTxTypes) {
|
||||
whereClauses.add("Transactions.type IN (" + HSQLDBRepository.nPlaceholders(txTypes.size()) + ")");
|
||||
bindParams.addAll(txTypes.stream().map(txType -> txType.value).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
if (hasAddress) {
|
||||
whereClauses.add("TransactionParticipants.participant = ?");
|
||||
|
Loading…
Reference in New Issue
Block a user