diff --git a/src/main/java/org/qortal/api/resource/AddressesResource.java b/src/main/java/org/qortal/api/resource/AddressesResource.java index de9de821..6a716f97 100644 --- a/src/main/java/org/qortal/api/resource/AddressesResource.java +++ b/src/main/java/org/qortal/api/resource/AddressesResource.java @@ -637,19 +637,19 @@ public class AddressesResource { responses = { @ApiResponse( 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}) - public SponsorshipReport getSponsorshipReport( + public MintershipReport 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, realRewardShareRecipients); + MintershipReport report = repository.getAccountRepository().getSponsorshipReport(address, realRewardShareRecipients); // Not found? if (report == null) 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", responses = { @ApiResponse( - description = "statistics", - content = @Content(mediaType = MediaType.APPLICATION_JSON, array = @ArraySchema(schema = @Schema(implementation = SponsorshipReport.class))) + 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 SponsorshipReport getSponsorshipReportForSponsor( + public MintershipReport getSponsorshipReportForSponsor( @PathParam("address") String address, @QueryParam("realRewardShareRecipient") String[] realRewardShareRecipients) { if (!Crypto.isValidAddress(address)) @@ -688,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(), realRewardShareRecipients); + MintershipReport report = repository.getAccountRepository().getSponsorshipReport(sponsor.get(), realRewardShareRecipients); // Not found? 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 @Path("/levels/{minLevel}") diff --git a/src/main/java/org/qortal/data/account/SponsorshipReport.java b/src/main/java/org/qortal/data/account/MintershipReport.java similarity index 87% rename from src/main/java/org/qortal/data/account/SponsorshipReport.java rename to src/main/java/org/qortal/data/account/MintershipReport.java index b08051ef..c1f2674e 100644 --- a/src/main/java/org/qortal/data/account/SponsorshipReport.java +++ b/src/main/java/org/qortal/data/account/MintershipReport.java @@ -6,7 +6,7 @@ import java.util.Arrays; // All properties to be converted to JSON via JAXB @XmlAccessorType(XmlAccessType.FIELD) -public class SponsorshipReport { +public class MintershipReport { private String address; @@ -45,10 +45,10 @@ public class SponsorshipReport { // Constructors // 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.level = level; this.blocksMinted = blocksMinted; @@ -141,7 +141,7 @@ public class SponsorshipReport { @Override public String toString() { - return "SponsorshipReport{" + + return "MintershipReport{" + "address='" + address + '\'' + ", level=" + level + ", blocksMinted=" + blocksMinted + diff --git a/src/main/java/org/qortal/repository/AccountRepository.java b/src/main/java/org/qortal/repository/AccountRepository.java index f0631d95..8d1390f4 100644 --- a/src/main/java/org/qortal/repository/AccountRepository.java +++ b/src/main/java/org/qortal/repository/AccountRepository.java @@ -5,6 +5,7 @@ import org.qortal.data.account.*; import java.util.List; import java.util.Optional; import java.util.Set; +import java.util.function.Function; public interface AccountRepository { @@ -132,15 +133,17 @@ public interface AccountRepository { /** Returns all account balances for given assetID, optionally excluding zero balances. */ public List getAssetBalances(long assetId, Boolean excludeZero) throws DataException; + public MintershipReport getSponsorshipReport(String address, String[] realRewardShareRecipients) throws DataException; + /** * Get Sponsorship Report * - * @param address the sponsor's account address - * @param realRewardShareRecipients the recipients that get real reward shares, not sponsorship + * @param address the account address + * @param addressFetcher fetches the addresses that this method will aggregate * @return the report * @throws DataException */ - public SponsorshipReport getSponsorshipReport(String address, String[] realRewardShareRecipients) throws DataException; + public MintershipReport getMintershipReport(String address, Function> addressFetcher) throws DataException; /** * Get Sponsee Addresses diff --git a/src/main/java/org/qortal/repository/hsqldb/HSQLDBAccountRepository.java b/src/main/java/org/qortal/repository/hsqldb/HSQLDBAccountRepository.java index 9a3ddd9a..5ea8e3b0 100644 --- a/src/main/java/org/qortal/repository/hsqldb/HSQLDBAccountRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/HSQLDBAccountRepository.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.function.Function; import java.util.stream.Collectors; import static org.qortal.utils.Amounts.prettyAmount; @@ -1157,7 +1158,15 @@ public class HSQLDBAccountRepository implements AccountRepository { } @Override - public SponsorshipReport getSponsorshipReport(String account, String[] realRewardShareRecipients) throws DataException { + public MintershipReport getSponsorshipReport(String address, String[] realRewardShareRecipients) throws DataException { + + List sponsees = getSponseeAddresses(address, realRewardShareRecipients); + + return getMintershipReport(address, account -> sponsees); + } + + @Override + public MintershipReport getMintershipReport(String account, Function> addressFetcher) throws DataException { try { ResultSet accountResultSet = getAccountResultSet(account); @@ -1170,10 +1179,10 @@ public class HSQLDBAccountRepository implements AccountRepository { int penalties = accountResultSet.getInt(5); boolean transferPrivs = accountResultSet.getBoolean(6); - List sponseeAddresses = getSponseeAddresses(account, realRewardShareRecipients); + List sponseeAddresses = addressFetcher.apply(account); 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 { return produceSponsorShipReport(account, level, blocksMinted, adjustments, penalties, sponseeAddresses, transferPrivs); @@ -1310,7 +1319,7 @@ public class HSQLDBAccountRepository implements AccountRepository { * @return the report * @throws SQLException */ - private SponsorshipReport produceSponsorShipReport( + private MintershipReport produceSponsorShipReport( String address, int level, int blocksMinted, @@ -1401,7 +1410,7 @@ public class HSQLDBAccountRepository implements AccountRepository { buyAmount = 0; } - return new SponsorshipReport( + return new MintershipReport( address, level, blocksMinted,