forked from Qortal/qortal
Add "involved" optional query param to API call GET /address/proxying, for convenience
This commit is contained in:
parent
e42c3e60bc
commit
a2cc4983a0
@ -305,6 +305,7 @@ public class AddressesResource {
|
|||||||
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.INVALID_CRITERIA, ApiError.REPOSITORY_ISSUE})
|
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.INVALID_CRITERIA, ApiError.REPOSITORY_ISSUE})
|
||||||
public List<ProxyForgerData> getProxying(@QueryParam("proxiedFor") List<String> recipients,
|
public List<ProxyForgerData> getProxying(@QueryParam("proxiedFor") List<String> recipients,
|
||||||
@QueryParam("proxiedBy") List<String> forgers,
|
@QueryParam("proxiedBy") List<String> forgers,
|
||||||
|
@QueryParam("involving") List<String> addresses,
|
||||||
@Parameter(
|
@Parameter(
|
||||||
ref = "limit"
|
ref = "limit"
|
||||||
) @QueryParam("limit") Integer limit, @Parameter(
|
) @QueryParam("limit") Integer limit, @Parameter(
|
||||||
@ -313,7 +314,7 @@ public class AddressesResource {
|
|||||||
ref = "reverse"
|
ref = "reverse"
|
||||||
) @QueryParam("reverse") Boolean reverse) {
|
) @QueryParam("reverse") Boolean reverse) {
|
||||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||||
return repository.getAccountRepository().findProxyAccounts(recipients, forgers, limit, offset, reverse);
|
return repository.getAccountRepository().findProxyAccounts(recipients, forgers, addresses, limit, offset, reverse);
|
||||||
} catch (DataException e) {
|
} catch (DataException e) {
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ public interface AccountRepository {
|
|||||||
|
|
||||||
public boolean isProxyPublicKey(byte[] publicKey) throws DataException;
|
public boolean isProxyPublicKey(byte[] publicKey) throws DataException;
|
||||||
|
|
||||||
public List<ProxyForgerData> findProxyAccounts(List<String> recipients, List<String> forgers, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
public List<ProxyForgerData> findProxyAccounts(List<String> recipients, List<String> forgers, List<String> involvedAddresses, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||||
|
|
||||||
public void save(ProxyForgerData proxyForgerData) throws DataException;
|
public void save(ProxyForgerData proxyForgerData) throws DataException;
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import org.qora.repository.AccountRepository;
|
|||||||
import org.qora.repository.DataException;
|
import org.qora.repository.DataException;
|
||||||
|
|
||||||
import static org.qora.repository.hsqldb.HSQLDBRepository.nPlaceholders;
|
import static org.qora.repository.hsqldb.HSQLDBRepository.nPlaceholders;
|
||||||
|
import static org.qora.repository.hsqldb.HSQLDBRepository.nValuesPlaceholders;
|
||||||
|
|
||||||
public class HSQLDBAccountRepository implements AccountRepository {
|
public class HSQLDBAccountRepository implements AccountRepository {
|
||||||
|
|
||||||
@ -362,24 +363,35 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ProxyForgerData> findProxyAccounts(List<String> recipients, List<String> forgers, Integer limit, Integer offset, Boolean reverse) throws DataException {
|
public List<ProxyForgerData> findProxyAccounts(List<String> recipients, List<String> forgers, List<String> involvedAddresses,
|
||||||
String sql = "SELECT forger, recipient, share, proxy_public_key FROM ProxyForgers ";
|
Integer limit, Integer offset, Boolean reverse) throws DataException {
|
||||||
|
String sql = "SELECT DISTINCT forger, recipient, share, proxy_public_key FROM ProxyForgers ";
|
||||||
|
|
||||||
List<Object> args = new ArrayList<>();
|
List<Object> args = new ArrayList<>();
|
||||||
|
|
||||||
if (!forgers.isEmpty()) {
|
final boolean hasRecipients = recipients != null && !recipients.isEmpty();
|
||||||
sql += "JOIN Accounts ON Accounts.public_key = ProxyForgers.forger "
|
final boolean hasForgers = forgers != null && !forgers.isEmpty();
|
||||||
+ "WHERE Accounts.account IN (" + nPlaceholders(forgers.size()) + ") ";
|
final boolean hasInvolved = involvedAddresses != null && !involvedAddresses.isEmpty();
|
||||||
args.addAll(forgers);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!recipients.isEmpty()) {
|
if (hasForgers || hasInvolved)
|
||||||
sql += forgers.isEmpty() ? "WHERE " : "AND ";
|
sql += "JOIN Accounts ON Accounts.public_key = ProxyForgers.forger ";
|
||||||
sql += "recipient IN (" + nPlaceholders(recipients.size()) + ") ";
|
|
||||||
|
if (hasRecipients) {
|
||||||
|
sql += "JOIN (VALUES " + nValuesPlaceholders(recipients.size()) + ") AS Recipients (address) ON ProxyForgers.recipient = Recipients.address ";
|
||||||
args.addAll(recipients);
|
args.addAll(recipients);
|
||||||
}
|
}
|
||||||
|
|
||||||
sql += "ORDER BY recipient, share";
|
if (hasForgers) {
|
||||||
|
sql += "JOIN (VALUES " + nValuesPlaceholders(forgers.size()) + ") AS Forgers (address) ON Accounts.account = Forgers.address ";
|
||||||
|
args.addAll(forgers);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasInvolved) {
|
||||||
|
sql += "JOIN (VALUES " + nValuesPlaceholders(involvedAddresses.size()) + ") AS Involved (address) ON Involved.address IN (ProxyForgers.recipient, Accounts.account) ";
|
||||||
|
args.addAll(involvedAddresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
sql += "ORDER BY recipient, share";
|
||||||
if (reverse != null && reverse)
|
if (reverse != null && reverse)
|
||||||
sql += " DESC";
|
sql += " DESC";
|
||||||
|
|
||||||
|
@ -534,4 +534,9 @@ public class HSQLDBRepository implements Repository {
|
|||||||
return String.join(", ", Collections.nCopies(n, "?"));
|
return String.join(", ", Collections.nCopies(n, "?"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Convenience method to return n comma-separated, bracketed, placeholders as a string. */
|
||||||
|
public static String nValuesPlaceholders(int n) {
|
||||||
|
return String.join(", ", Collections.nCopies(n, "(?)"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user