mirror of
https://github.com/Qortal/qortal.git
synced 2025-02-11 17:55:50 +00:00
in sponsorship reports, exclude the recipients that get real reward shares
This commit is contained in:
parent
7c4b0bd7f2
commit
639e1df531
@ -633,7 +633,7 @@ public class AddressesResource {
|
||||
@Path("/sponsorship/{address}")
|
||||
@Operation(
|
||||
summary = "Returns sponsorship statistics for an account",
|
||||
description = "Returns sponsorship statistics for an account",
|
||||
description = "Returns sponsorship statistics for an account, excluding the recipients that get real reward shares",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "the statistics",
|
||||
@ -642,12 +642,14 @@ public class AddressesResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
||||
public SponsorshipReport getSponsorshipReport(@PathParam("address") String address) {
|
||||
public SponsorshipReport getSponsorshipReport(
|
||||
@PathParam("address") String address,
|
||||
@QueryParam(("realRewardShareRecipient")) String[] realRewardShareRecipients) {
|
||||
if (!Crypto.isValidAddress(address))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
SponsorshipReport report = repository.getAccountRepository().getSponsorshipReport(address);
|
||||
SponsorshipReport report = repository.getAccountRepository().getSponsorshipReport(address, realRewardShareRecipients);
|
||||
// Not found?
|
||||
if (report == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||
@ -662,7 +664,7 @@ public class AddressesResource {
|
||||
@Path("/sponsorship/{address}/sponsor")
|
||||
@Operation(
|
||||
summary = "Returns sponsorship statistics for an account's sponsor",
|
||||
description = "Returns sponsorship statistics for an account's sponsor",
|
||||
description = "Returns sponsorship statistics for an account's sponsor, excluding the recipients that get real reward shares",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "statistics",
|
||||
@ -671,7 +673,9 @@ public class AddressesResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
||||
public SponsorshipReport getSponsorshipReportForSponsor(@PathParam("address") String address) {
|
||||
public SponsorshipReport getSponsorshipReportForSponsor(
|
||||
@PathParam("address") String address,
|
||||
@QueryParam("realRewardShareRecipient") String[] realRewardShareRecipients) {
|
||||
if (!Crypto.isValidAddress(address))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
||||
|
||||
@ -684,7 +688,7 @@ public class AddressesResource {
|
||||
if(sponsor.isEmpty()) throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||
|
||||
// get report for sponsor
|
||||
SponsorshipReport report = repository.getAccountRepository().getSponsorshipReport(sponsor.get());
|
||||
SponsorshipReport report = repository.getAccountRepository().getSponsorshipReport(sponsor.get(), realRewardShareRecipients);
|
||||
|
||||
// Not found?
|
||||
if (report == null)
|
||||
|
@ -135,24 +135,22 @@ public interface AccountRepository {
|
||||
/**
|
||||
* Get Sponsorship Report
|
||||
*
|
||||
* @param address the sponsor's account address
|
||||
*
|
||||
* @param address the sponsor's account address
|
||||
* @param realRewardShareRecipients the recipients that get real reward shares, not sponsorship
|
||||
* @return the report
|
||||
*
|
||||
* @throws DataException
|
||||
*/
|
||||
public SponsorshipReport getSponsorshipReport(String address) throws DataException;
|
||||
public SponsorshipReport getSponsorshipReport(String address, String[] realRewardShareRecipients) throws DataException;
|
||||
|
||||
/**
|
||||
* Get Sponsee Addresses
|
||||
*
|
||||
* @param account the sponsor's account address
|
||||
*
|
||||
* @param account the sponsor's account address
|
||||
* @param realRewardShareRecipients the recipients that get real reward shares, not sponsorship
|
||||
* @return the sponsee addresses
|
||||
*
|
||||
* @throws DataException
|
||||
*/
|
||||
public List<String> getSponseeAddresses(String account) throws DataException;
|
||||
public List<String> getSponseeAddresses(String account, String[] realRewardShareRecipients) throws DataException;
|
||||
|
||||
/**
|
||||
* Get Sponsor
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.qortal.repository.hsqldb;
|
||||
|
||||
import cash.z.wallet.sdk.rpc.Service;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.asset.Asset;
|
||||
@ -1158,7 +1157,7 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SponsorshipReport getSponsorshipReport(String account) throws DataException {
|
||||
public SponsorshipReport getSponsorshipReport(String account, String[] realRewardShareRecipients) throws DataException {
|
||||
|
||||
try {
|
||||
ResultSet accountResultSet = getAccountResultSet(account);
|
||||
@ -1171,7 +1170,7 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
||||
int penalties = accountResultSet.getInt(5);
|
||||
boolean transferPrivs = accountResultSet.getBoolean(6);
|
||||
|
||||
List<String> sponseeAddresses = getSponseeAddresses(account);
|
||||
List<String> sponseeAddresses = getSponseeAddresses(account, realRewardShareRecipients);
|
||||
|
||||
if( sponseeAddresses.isEmpty() ){
|
||||
return new SponsorshipReport(account, level, blocksMinted, adjustments, penalties, transferPrivs, new String[0], 0, 0,0, 0, 0, 0, 0, 0, 0, 0);
|
||||
@ -1187,7 +1186,7 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSponseeAddresses(String account) throws DataException {
|
||||
public List<String> getSponseeAddresses(String account, String[] realRewardShareRecipients) throws DataException {
|
||||
StringBuffer sponseeSql = new StringBuffer();
|
||||
|
||||
sponseeSql.append( "SELECT DISTINCT t.recipient sponsees " );
|
||||
@ -1196,7 +1195,30 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
||||
sponseeSql.append( "WHERE account = ? and t.recipient != a.account");
|
||||
|
||||
try {
|
||||
ResultSet sponseeResultSet = this.repository.checkedExecute(sponseeSql.toString(), account);
|
||||
ResultSet sponseeResultSet;
|
||||
|
||||
// if there are real reward share recipeints to exclude
|
||||
if (realRewardShareRecipients != null && realRewardShareRecipients.length > 0) {
|
||||
|
||||
// add constraint to where clause
|
||||
sponseeSql.append(" and t.recipient NOT IN (");
|
||||
sponseeSql.append(String.join(", ", Collections.nCopies(realRewardShareRecipients.length, "?")));
|
||||
sponseeSql.append(")");
|
||||
|
||||
// Create a new array to hold both
|
||||
String[] combinedArray = new String[realRewardShareRecipients.length + 1];
|
||||
|
||||
// Add the single string to the first position
|
||||
combinedArray[0] = account;
|
||||
|
||||
// Copy the elements from realRewardShareRecipients to the combinedArray starting from index 1
|
||||
System.arraycopy(realRewardShareRecipients, 0, combinedArray, 1, realRewardShareRecipients.length);
|
||||
|
||||
sponseeResultSet = this.repository.checkedExecute(sponseeSql.toString(), combinedArray);
|
||||
}
|
||||
else {
|
||||
sponseeResultSet = this.repository.checkedExecute(sponseeSql.toString(), account);
|
||||
}
|
||||
|
||||
List<String> sponseeAddresses;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user