mirror of
https://github.com/Qortal/qortal.git
synced 2025-04-23 19:37:51 +00:00
Added "creator" parameter to GET /transactions/unconfirmed, to allow filtering unconfirmed transactions by creator's public key
This commit is contained in:
parent
a4d4d17b82
commit
0a419cb105
@ -253,14 +253,27 @@ public class TransactionsResource {
|
|||||||
ApiError.REPOSITORY_ISSUE
|
ApiError.REPOSITORY_ISSUE
|
||||||
})
|
})
|
||||||
public List<TransactionData> getUnconfirmedTransactions(@Parameter(
|
public List<TransactionData> getUnconfirmedTransactions(@Parameter(
|
||||||
|
description = "Transaction creator's base58 encoded public key"
|
||||||
|
) @QueryParam("creator") String creatorPublicKey58, @Parameter(
|
||||||
ref = "limit"
|
ref = "limit"
|
||||||
) @QueryParam("limit") Integer limit, @Parameter(
|
) @QueryParam("limit") Integer limit, @Parameter(
|
||||||
ref = "offset"
|
ref = "offset"
|
||||||
) @QueryParam("offset") Integer offset, @Parameter(
|
) @QueryParam("offset") Integer offset, @Parameter(
|
||||||
ref = "reverse"
|
ref = "reverse"
|
||||||
) @QueryParam("reverse") Boolean reverse) {
|
) @QueryParam("reverse") Boolean reverse) {
|
||||||
|
|
||||||
|
// Decode public key if supplied
|
||||||
|
byte[] creatorPublicKey = null;
|
||||||
|
if (creatorPublicKey58 != null) {
|
||||||
|
try {
|
||||||
|
creatorPublicKey = Base58.decode(creatorPublicKey58);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_PUBLIC_KEY, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||||
return repository.getTransactionRepository().getUnconfirmedTransactions(limit, offset, reverse);
|
return repository.getTransactionRepository().getUnconfirmedTransactions(creatorPublicKey, limit, offset, reverse);
|
||||||
} catch (ApiException e) {
|
} catch (ApiException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (DataException e) {
|
} catch (DataException e) {
|
||||||
|
@ -257,7 +257,7 @@ public interface TransactionRepository {
|
|||||||
* @return list of transactions, or empty if none.
|
* @return list of transactions, or empty if none.
|
||||||
* @throws DataException
|
* @throws DataException
|
||||||
*/
|
*/
|
||||||
public List<TransactionData> getUnconfirmedTransactions(Integer limit, Integer offset, Boolean reverse) throws DataException;
|
public List<TransactionData> getUnconfirmedTransactions(byte[] creatorPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns list of unconfirmed transactions in timestamp-else-signature order.
|
* Returns list of unconfirmed transactions in timestamp-else-signature order.
|
||||||
@ -266,7 +266,7 @@ public interface TransactionRepository {
|
|||||||
* @throws DataException
|
* @throws DataException
|
||||||
*/
|
*/
|
||||||
public default List<TransactionData> getUnconfirmedTransactions() throws DataException {
|
public default List<TransactionData> getUnconfirmedTransactions() throws DataException {
|
||||||
return getUnconfirmedTransactions(null, null, null);
|
return getUnconfirmedTransactions(null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1213,11 +1213,34 @@ public class HSQLDBTransactionRepository implements TransactionRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TransactionData> getUnconfirmedTransactions(Integer limit, Integer offset, Boolean reverse) throws DataException {
|
public List<TransactionData> getUnconfirmedTransactions(byte[] creatorPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException {
|
||||||
StringBuilder sql = new StringBuilder(256);
|
List<String> whereClauses = new ArrayList<>();
|
||||||
sql.append("SELECT signature FROM UnconfirmedTransactions ");
|
List<Object> bindParams = new ArrayList<>();
|
||||||
|
|
||||||
sql.append("ORDER BY created_when");
|
if (creatorPublicKey != null) {
|
||||||
|
whereClauses.add("creator = ?");
|
||||||
|
bindParams.add(creatorPublicKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sql = new StringBuilder(256);
|
||||||
|
sql.append("SELECT signature FROM UnconfirmedTransactions");
|
||||||
|
if (creatorPublicKey != null) {
|
||||||
|
sql.append(" JOIN Transactions USING (signature) ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!whereClauses.isEmpty()) {
|
||||||
|
sql.append(" WHERE ");
|
||||||
|
|
||||||
|
final int whereClausesSize = whereClauses.size();
|
||||||
|
for (int wci = 0; wci < whereClausesSize; ++wci) {
|
||||||
|
if (wci != 0)
|
||||||
|
sql.append(" AND ");
|
||||||
|
|
||||||
|
sql.append(whereClauses.get(wci));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sql.append(" ORDER BY created_when");
|
||||||
if (reverse != null && reverse)
|
if (reverse != null && reverse)
|
||||||
sql.append(" DESC");
|
sql.append(" DESC");
|
||||||
|
|
||||||
@ -1230,7 +1253,7 @@ public class HSQLDBTransactionRepository implements TransactionRepository {
|
|||||||
List<TransactionData> transactions = new ArrayList<>();
|
List<TransactionData> transactions = new ArrayList<>();
|
||||||
|
|
||||||
// Find transactions with no corresponding row in BlockTransactions
|
// Find transactions with no corresponding row in BlockTransactions
|
||||||
try (ResultSet resultSet = this.repository.checkedExecute(sql.toString())) {
|
try (ResultSet resultSet = this.repository.checkedExecute(sql.toString(), bindParams.toArray())) {
|
||||||
if (resultSet == null)
|
if (resultSet == null)
|
||||||
return transactions;
|
return transactions;
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ public class TransactionsApiTests extends ApiCommon {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetUnconfirmedTransactions() {
|
public void testGetUnconfirmedTransactions() {
|
||||||
assertNotNull(this.transactionsResource.getUnconfirmedTransactions(null, null, null));
|
assertNotNull(this.transactionsResource.getUnconfirmedTransactions(null, null, null, null));
|
||||||
assertNotNull(this.transactionsResource.getUnconfirmedTransactions(1, 1, true));
|
assertNotNull(this.transactionsResource.getUnconfirmedTransactions(null, 1, 1, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user