forked from Qortal/qortal
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
|
||||
})
|
||||
public List<TransactionData> getUnconfirmedTransactions(@Parameter(
|
||||
description = "Transaction creator's base58 encoded public key"
|
||||
) @QueryParam("creator") String creatorPublicKey58, @Parameter(
|
||||
ref = "limit"
|
||||
) @QueryParam("limit") Integer limit, @Parameter(
|
||||
ref = "offset"
|
||||
) @QueryParam("offset") Integer offset, @Parameter(
|
||||
ref = "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()) {
|
||||
return repository.getTransactionRepository().getUnconfirmedTransactions(limit, offset, reverse);
|
||||
return repository.getTransactionRepository().getUnconfirmedTransactions(creatorPublicKey, limit, offset, reverse);
|
||||
} catch (ApiException e) {
|
||||
throw e;
|
||||
} catch (DataException e) {
|
||||
|
@ -257,7 +257,7 @@ public interface TransactionRepository {
|
||||
* @return list of transactions, or empty if none.
|
||||
* @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.
|
||||
@ -266,7 +266,7 @@ public interface TransactionRepository {
|
||||
* @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
|
||||
public List<TransactionData> getUnconfirmedTransactions(Integer limit, Integer offset, Boolean reverse) throws DataException {
|
||||
StringBuilder sql = new StringBuilder(256);
|
||||
sql.append("SELECT signature FROM UnconfirmedTransactions ");
|
||||
public List<TransactionData> getUnconfirmedTransactions(byte[] creatorPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException {
|
||||
List<String> whereClauses = new ArrayList<>();
|
||||
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)
|
||||
sql.append(" DESC");
|
||||
|
||||
@ -1230,7 +1253,7 @@ public class HSQLDBTransactionRepository implements TransactionRepository {
|
||||
List<TransactionData> transactions = new ArrayList<>();
|
||||
|
||||
// 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)
|
||||
return transactions;
|
||||
|
||||
|
@ -36,8 +36,8 @@ public class TransactionsApiTests extends ApiCommon {
|
||||
|
||||
@Test
|
||||
public void testGetUnconfirmedTransactions() {
|
||||
assertNotNull(this.transactionsResource.getUnconfirmedTransactions(null, null, null));
|
||||
assertNotNull(this.transactionsResource.getUnconfirmedTransactions(1, 1, true));
|
||||
assertNotNull(this.transactionsResource.getUnconfirmedTransactions(null, null, null, null));
|
||||
assertNotNull(this.transactionsResource.getUnconfirmedTransactions(null, 1, 1, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user