Added ability to filter arbitrary transactions by name when searching.

This commit is contained in:
CalDescent 2021-10-31 21:07:14 +00:00
parent 4882cc92a8
commit cbed6418e7
9 changed files with 29 additions and 18 deletions

View File

@ -89,7 +89,9 @@ public class ArbitraryResource {
})
public List<TransactionData> searchTransactions(@QueryParam("startBlock") Integer startBlock, @QueryParam("blockLimit") Integer blockLimit,
@QueryParam("txGroupId") Integer txGroupId,
@QueryParam("service") Integer service, @QueryParam("address") String address, @Parameter(
@QueryParam("service") Integer service,
@QueryParam("name") String name,
@QueryParam("address") String address, @Parameter(
description = "whether to include confirmed, unconfirmed or both",
required = true
) @QueryParam("confirmationStatus") ConfirmationStatus confirmationStatus, @Parameter(
@ -112,7 +114,7 @@ public class ArbitraryResource {
try (final Repository repository = RepositoryManager.getRepository()) {
List<byte[]> signatures = repository.getTransactionRepository().getSignaturesMatchingCriteria(startBlock, blockLimit, txGroupId, txTypes,
service, address, confirmationStatus, limit, offset, reverse);
service, name, address, confirmationStatus, limit, offset, reverse);
// Expand signatures to transactions
List<TransactionData> transactions = new ArrayList<TransactionData>(signatures.size());

View File

@ -348,7 +348,7 @@ public class TransactionsResource {
try (final Repository repository = RepositoryManager.getRepository()) {
List<byte[]> signatures = repository.getTransactionRepository().getSignaturesMatchingCriteria(startBlock, blockLimit, txGroupId,
txTypes, null, address, confirmationStatus, limit, offset, reverse);
txTypes, null, null, address, confirmationStatus, limit, offset, reverse);
// Expand signatures to transactions
List<TransactionData> transactions = new ArrayList<>(signatures.size());

View File

@ -90,7 +90,7 @@ public class ArbitraryDataCleanupManager extends Thread {
// Any arbitrary transactions we want to fetch data for?
try (final Repository repository = RepositoryManager.getRepository()) {
List<byte[]> signatures = repository.getTransactionRepository().getSignaturesMatchingCriteria(null, null, null, ARBITRARY_TX_TYPE, null, null, ConfirmationStatus.BOTH, limit, offset, true);
List<byte[]> signatures = repository.getTransactionRepository().getSignaturesMatchingCriteria(null, null, null, ARBITRARY_TX_TYPE, null, null, null, ConfirmationStatus.BOTH, limit, offset, true);
// LOGGER.info("Found {} arbitrary transactions at offset: {}, limit: {}", signatures.size(), offset, limit);
if (signatures == null || signatures.isEmpty()) {
offset = 0;

View File

@ -128,7 +128,7 @@ public class ArbitraryDataManager extends Thread {
// Any arbitrary transactions we want to fetch data for?
try (final Repository repository = RepositoryManager.getRepository()) {
List<byte[]> signatures = repository.getTransactionRepository().getSignaturesMatchingCriteria(null, null, null, ARBITRARY_TX_TYPE, null, null, ConfirmationStatus.BOTH, limit, offset, true);
List<byte[]> signatures = repository.getTransactionRepository().getSignaturesMatchingCriteria(null, null, null, ARBITRARY_TX_TYPE, null, null, null, ConfirmationStatus.BOTH, limit, offset, true);
// LOGGER.info("Found {} arbitrary transactions at offset: {}, limit: {}", signatures.size(), offset, limit);
if (signatures == null || signatures.isEmpty()) {
offset = 0;

View File

@ -305,7 +305,7 @@ public class NamesDatabaseIntegrityCheck {
// Fetch all the confirmed REGISTER_NAME transaction signatures
List<byte[]> signatures = repository.getTransactionRepository().getSignaturesMatchingCriteria(
null, null, null, ALL_NAME_TX_TYPE, null, null,
ConfirmationStatus.CONFIRMED, null, null, false);
null, ConfirmationStatus.CONFIRMED, null, null, false);
for (byte[] signature : signatures) {
TransactionData transactionData = repository.getTransactionRepository().fromSignature(signature);

View File

@ -70,7 +70,7 @@ public interface TransactionRepository {
* @throws DataException
*/
public List<byte[]> getSignaturesMatchingCriteria(Integer startBlock, Integer blockLimit, Integer txGroupId,
List<TransactionType> txTypes, Integer service, String address,
List<TransactionType> txTypes, Integer service, String name, String address,
ConfirmationStatus confirmationStatus, Integer limit, Integer offset, Boolean reverse) throws DataException;
/**

View File

@ -907,8 +907,10 @@ public class HSQLDBDatabaseUpdates {
stmt.execute("ALTER TABLE ArbitraryTransactions ADD size INT NOT NULL DEFAULT 0");
// Larger data files need to be split into chunks, for easier transmission and greater decentralization
stmt.execute("ALTER TABLE ArbitraryTransactions ADD chunk_hashes ArbitraryDataHashes");
// For finding data files by hash
// For finding transactions by file hash
stmt.execute("CREATE INDEX ArbitraryDataIndex ON ArbitraryTransactions (is_data_raw, data)");
// For finding transactions by registered name
stmt.execute("CREATE INDEX ArbitraryNameIndex ON ArbitraryTransactions (name)");
break;
case 38:

View File

@ -386,7 +386,7 @@ public class HSQLDBTransactionRepository implements TransactionRepository {
@Override
public List<byte[]> getSignaturesMatchingCriteria(Integer startBlock, Integer blockLimit, Integer txGroupId,
List<TransactionType> txTypes, Integer service, String address,
List<TransactionType> txTypes, Integer service, String name, String address,
ConfirmationStatus confirmationStatus, Integer limit, Integer offset, Boolean reverse) throws DataException {
List<byte[]> signatures = new ArrayList<>();
@ -412,8 +412,8 @@ public class HSQLDBTransactionRepository implements TransactionRepository {
signatureColumn = "TransactionParticipants.signature";
}
if (service != null) {
// This is for ARBITRARY transactions
if (service != null || name != null) {
// These are for ARBITRARY transactions
tables.append(" LEFT OUTER JOIN ArbitraryTransactions ON ArbitraryTransactions.signature = Transactions.signature");
}
@ -469,6 +469,11 @@ public class HSQLDBTransactionRepository implements TransactionRepository {
bindParams.add(service);
}
if (name != null) {
whereClauses.add("ArbitraryTransactions.name = ?");
bindParams.add(name);
}
if (hasAddress) {
whereClauses.add("TransactionParticipants.participant = ?");
bindParams.add(address);

View File

@ -23,6 +23,7 @@ public class ArbitraryApiTests extends ApiCommon {
Integer[] blockLimits = new Integer[] { null, 0, 1, 999999999 };
Integer[] txGroupIds = new Integer[] { null, 0, 1, 999999999 };
Integer[] services = new Integer[] { null, 0, 1, 999999999 };
String[] names = new String[] { null, "Test" };
String[] addresses = new String[] { null, this.aliceAddress };
ConfirmationStatus[] confirmationStatuses = new ConfirmationStatus[] { ConfirmationStatus.UNCONFIRMED, ConfirmationStatus.CONFIRMED, ConfirmationStatus.BOTH };
@ -30,13 +31,14 @@ public class ArbitraryApiTests extends ApiCommon {
for (Integer blockLimit : blockLimits)
for (Integer txGroupId : txGroupIds)
for (Integer service : services)
for (String name : names)
for (String address : addresses)
for (ConfirmationStatus confirmationStatus : confirmationStatuses) {
if (confirmationStatus != ConfirmationStatus.CONFIRMED && (startBlock != null || blockLimit != null))
continue;
assertNotNull(this.arbitraryResource.searchTransactions(startBlock, blockLimit, txGroupId, service, address, confirmationStatus, 20, null, null));
assertNotNull(this.arbitraryResource.searchTransactions(startBlock, blockLimit, txGroupId, service, address, confirmationStatus, 1, 1, true));
assertNotNull(this.arbitraryResource.searchTransactions(startBlock, blockLimit, txGroupId, service, name, address, confirmationStatus, 20, null, null));
assertNotNull(this.arbitraryResource.searchTransactions(startBlock, blockLimit, txGroupId, service, name, address, confirmationStatus, 1, 1, true));
}
}