mirror of
https://github.com/Qortal/qortal.git
synced 2025-02-11 17:55:50 +00:00
added MintershipReport endpoint, restructured the sponsorship report logic, so the MintershipReport could take advantage of the common logic, fixed some of the annotations in the sponsorship report endpoints
This commit is contained in:
parent
639e1df531
commit
68a2e65fc7
@ -637,19 +637,19 @@ public class AddressesResource {
|
|||||||
responses = {
|
responses = {
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
description = "the statistics",
|
description = "the statistics",
|
||||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, array = @ArraySchema(schema = @Schema(implementation = SponsorshipReport.class)))
|
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = MintershipReport.class))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
||||||
public SponsorshipReport getSponsorshipReport(
|
public MintershipReport getSponsorshipReport(
|
||||||
@PathParam("address") String address,
|
@PathParam("address") String address,
|
||||||
@QueryParam(("realRewardShareRecipient")) String[] realRewardShareRecipients) {
|
@QueryParam(("realRewardShareRecipient")) String[] realRewardShareRecipients) {
|
||||||
if (!Crypto.isValidAddress(address))
|
if (!Crypto.isValidAddress(address))
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
||||||
|
|
||||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||||
SponsorshipReport report = repository.getAccountRepository().getSponsorshipReport(address, realRewardShareRecipients);
|
MintershipReport report = repository.getAccountRepository().getSponsorshipReport(address, realRewardShareRecipients);
|
||||||
// Not found?
|
// Not found?
|
||||||
if (report == null)
|
if (report == null)
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||||
@ -667,13 +667,13 @@ public class AddressesResource {
|
|||||||
description = "Returns sponsorship statistics for an account's sponsor, excluding the recipients that get real reward shares",
|
description = "Returns sponsorship statistics for an account's sponsor, excluding the recipients that get real reward shares",
|
||||||
responses = {
|
responses = {
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
description = "statistics",
|
description = "the statistics",
|
||||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, array = @ArraySchema(schema = @Schema(implementation = SponsorshipReport.class)))
|
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = MintershipReport.class))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
||||||
public SponsorshipReport getSponsorshipReportForSponsor(
|
public MintershipReport getSponsorshipReportForSponsor(
|
||||||
@PathParam("address") String address,
|
@PathParam("address") String address,
|
||||||
@QueryParam("realRewardShareRecipient") String[] realRewardShareRecipients) {
|
@QueryParam("realRewardShareRecipient") String[] realRewardShareRecipients) {
|
||||||
if (!Crypto.isValidAddress(address))
|
if (!Crypto.isValidAddress(address))
|
||||||
@ -688,7 +688,7 @@ public class AddressesResource {
|
|||||||
if(sponsor.isEmpty()) throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
if(sponsor.isEmpty()) throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||||
|
|
||||||
// get report for sponsor
|
// get report for sponsor
|
||||||
SponsorshipReport report = repository.getAccountRepository().getSponsorshipReport(sponsor.get(), realRewardShareRecipients);
|
MintershipReport report = repository.getAccountRepository().getSponsorshipReport(sponsor.get(), realRewardShareRecipients);
|
||||||
|
|
||||||
// Not found?
|
// Not found?
|
||||||
if (report == null)
|
if (report == null)
|
||||||
@ -700,6 +700,37 @@ public class AddressesResource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/mintership/{address}")
|
||||||
|
@Operation(
|
||||||
|
summary = "Returns mintership statistics for an account",
|
||||||
|
description = "Returns mintership statistics for an account",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(
|
||||||
|
description = "the statistics",
|
||||||
|
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = MintershipReport.class))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
||||||
|
public MintershipReport getMintershipReport(@PathParam("address") String address ) {
|
||||||
|
if (!Crypto.isValidAddress(address))
|
||||||
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
||||||
|
|
||||||
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||||
|
|
||||||
|
// get report for sponsor
|
||||||
|
MintershipReport report = repository.getAccountRepository().getMintershipReport(address, account -> List.of(account));
|
||||||
|
|
||||||
|
// Not found?
|
||||||
|
if (report == null)
|
||||||
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||||
|
|
||||||
|
return report;
|
||||||
|
} catch (DataException e) {
|
||||||
|
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/levels/{minLevel}")
|
@Path("/levels/{minLevel}")
|
||||||
|
@ -6,7 +6,7 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
// All properties to be converted to JSON via JAXB
|
// All properties to be converted to JSON via JAXB
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
public class SponsorshipReport {
|
public class MintershipReport {
|
||||||
|
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
@ -45,10 +45,10 @@ public class SponsorshipReport {
|
|||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
// For JAXB
|
// For JAXB
|
||||||
protected SponsorshipReport() {
|
protected MintershipReport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SponsorshipReport(String address, int level, int blocksMinted, int adjustments, int penalties, boolean transfer, String[] names, int sponseeCount, int nonRegisteredCount, int avgBalance, int arbitraryCount, int transferAssetCount, int transferPrivsCount, int sellCount, int sellAmount, int buyCount, int buyAmount) {
|
public MintershipReport(String address, int level, int blocksMinted, int adjustments, int penalties, boolean transfer, String[] names, int sponseeCount, int nonRegisteredCount, int avgBalance, int arbitraryCount, int transferAssetCount, int transferPrivsCount, int sellCount, int sellAmount, int buyCount, int buyAmount) {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.blocksMinted = blocksMinted;
|
this.blocksMinted = blocksMinted;
|
||||||
@ -141,7 +141,7 @@ public class SponsorshipReport {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SponsorshipReport{" +
|
return "MintershipReport{" +
|
||||||
"address='" + address + '\'' +
|
"address='" + address + '\'' +
|
||||||
", level=" + level +
|
", level=" + level +
|
||||||
", blocksMinted=" + blocksMinted +
|
", blocksMinted=" + blocksMinted +
|
@ -5,6 +5,7 @@ import org.qortal.data.account.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public interface AccountRepository {
|
public interface AccountRepository {
|
||||||
|
|
||||||
@ -132,15 +133,17 @@ public interface AccountRepository {
|
|||||||
/** Returns all account balances for given assetID, optionally excluding zero balances. */
|
/** Returns all account balances for given assetID, optionally excluding zero balances. */
|
||||||
public List<AccountBalanceData> getAssetBalances(long assetId, Boolean excludeZero) throws DataException;
|
public List<AccountBalanceData> getAssetBalances(long assetId, Boolean excludeZero) throws DataException;
|
||||||
|
|
||||||
|
public MintershipReport getSponsorshipReport(String address, String[] realRewardShareRecipients) throws DataException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Sponsorship Report
|
* Get Sponsorship Report
|
||||||
*
|
*
|
||||||
* @param address the sponsor's account address
|
* @param address the account address
|
||||||
* @param realRewardShareRecipients the recipients that get real reward shares, not sponsorship
|
* @param addressFetcher fetches the addresses that this method will aggregate
|
||||||
* @return the report
|
* @return the report
|
||||||
* @throws DataException
|
* @throws DataException
|
||||||
*/
|
*/
|
||||||
public SponsorshipReport getSponsorshipReport(String address, String[] realRewardShareRecipients) throws DataException;
|
public MintershipReport getMintershipReport(String address, Function<String, List<String>> addressFetcher) throws DataException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Sponsee Addresses
|
* Get Sponsee Addresses
|
||||||
|
@ -16,6 +16,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.qortal.utils.Amounts.prettyAmount;
|
import static org.qortal.utils.Amounts.prettyAmount;
|
||||||
@ -1157,7 +1158,15 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SponsorshipReport getSponsorshipReport(String account, String[] realRewardShareRecipients) throws DataException {
|
public MintershipReport getSponsorshipReport(String address, String[] realRewardShareRecipients) throws DataException {
|
||||||
|
|
||||||
|
List<String> sponsees = getSponseeAddresses(address, realRewardShareRecipients);
|
||||||
|
|
||||||
|
return getMintershipReport(address, account -> sponsees);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MintershipReport getMintershipReport(String account, Function<String, List<String>> addressFetcher) throws DataException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ResultSet accountResultSet = getAccountResultSet(account);
|
ResultSet accountResultSet = getAccountResultSet(account);
|
||||||
@ -1170,10 +1179,10 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
|||||||
int penalties = accountResultSet.getInt(5);
|
int penalties = accountResultSet.getInt(5);
|
||||||
boolean transferPrivs = accountResultSet.getBoolean(6);
|
boolean transferPrivs = accountResultSet.getBoolean(6);
|
||||||
|
|
||||||
List<String> sponseeAddresses = getSponseeAddresses(account, realRewardShareRecipients);
|
List<String> sponseeAddresses = addressFetcher.apply(account);
|
||||||
|
|
||||||
if( sponseeAddresses.isEmpty() ){
|
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);
|
return new MintershipReport(account, level, blocksMinted, adjustments, penalties, transferPrivs, new String[0], 0, 0,0, 0, 0, 0, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return produceSponsorShipReport(account, level, blocksMinted, adjustments, penalties, sponseeAddresses, transferPrivs);
|
return produceSponsorShipReport(account, level, blocksMinted, adjustments, penalties, sponseeAddresses, transferPrivs);
|
||||||
@ -1310,7 +1319,7 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
|||||||
* @return the report
|
* @return the report
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
private SponsorshipReport produceSponsorShipReport(
|
private MintershipReport produceSponsorShipReport(
|
||||||
String address,
|
String address,
|
||||||
int level,
|
int level,
|
||||||
int blocksMinted,
|
int blocksMinted,
|
||||||
@ -1401,7 +1410,7 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
|||||||
buyAmount = 0;
|
buyAmount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SponsorshipReport(
|
return new MintershipReport(
|
||||||
address,
|
address,
|
||||||
level,
|
level,
|
||||||
blocksMinted,
|
blocksMinted,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user