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