mirror of
https://github.com/Qortal/qortal.git
synced 2025-02-11 17:55:50 +00:00
sponsorship endpoints now return a different report type than the mintership endpoint
This commit is contained in:
parent
39da7edf5a
commit
d9ad0bd663
@ -637,19 +637,19 @@ public class AddressesResource {
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "the statistics",
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = MintershipReport.class))
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = SponsorshipReport.class))
|
||||
)
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
||||
public MintershipReport getSponsorshipReport(
|
||||
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()) {
|
||||
MintershipReport report = repository.getAccountRepository().getSponsorshipReport(address, realRewardShareRecipients);
|
||||
SponsorshipReport report = repository.getAccountRepository().getSponsorshipReport(address, realRewardShareRecipients);
|
||||
// Not found?
|
||||
if (report == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||
@ -668,12 +668,12 @@ public class AddressesResource {
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "the statistics",
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = MintershipReport.class))
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = SponsorshipReport.class))
|
||||
)
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
||||
public MintershipReport getSponsorshipReportForSponsor(
|
||||
public SponsorshipReport 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
|
||||
MintershipReport report = repository.getAccountRepository().getSponsorshipReport(sponsor.get(), realRewardShareRecipients);
|
||||
SponsorshipReport report = repository.getAccountRepository().getSponsorshipReport(sponsor.get(), realRewardShareRecipients);
|
||||
|
||||
// Not found?
|
||||
if (report == null)
|
||||
@ -713,20 +713,48 @@ public class AddressesResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
||||
public MintershipReport getMintershipReport(@PathParam("address") String address ) {
|
||||
public MintershipReport getMintershipReport(@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()) {
|
||||
|
||||
// get report for sponsor
|
||||
MintershipReport report = repository.getAccountRepository().getMintershipReport(address, account -> List.of(account));
|
||||
// get sponsorship report for minter, fetch a list of one minter
|
||||
SponsorshipReport report = repository.getAccountRepository().getMintershipReport(address, account -> List.of(account));
|
||||
|
||||
// Not found?
|
||||
if (report == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||
|
||||
return report;
|
||||
// since the report is for one minter, must get sponsee count separately
|
||||
int sponseeCount = repository.getAccountRepository().getSponseeAddresses(address, realRewardShareRecipients).size();
|
||||
|
||||
// since the report is for one minter, must get the first name from a array of names that should be size 1
|
||||
String name = report.getNames().length > 0 ? report.getNames()[0] : null;
|
||||
|
||||
// transform sponsorship report to mintership report
|
||||
MintershipReport mintershipReport
|
||||
= new MintershipReport(
|
||||
report.getAddress(),
|
||||
report.getLevel(),
|
||||
report.getBlocksMinted(),
|
||||
report.getAdjustments(),
|
||||
report.getPenalties(),
|
||||
report.isTransfer(),
|
||||
name,
|
||||
sponseeCount,
|
||||
report.getAvgBalance(),
|
||||
report.getArbitraryCount(),
|
||||
report.getTransferAssetCount(),
|
||||
report.getTransferPrivsCount(),
|
||||
report.getSellCount(),
|
||||
report.getSellAmount(),
|
||||
report.getBuyCount(),
|
||||
report.getBuyAmount()
|
||||
);
|
||||
|
||||
return mintershipReport;
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
|
@ -20,13 +20,11 @@ public class MintershipReport {
|
||||
|
||||
private boolean transfer;
|
||||
|
||||
private String[] names;
|
||||
private String name;
|
||||
|
||||
private int sponseeCount;
|
||||
|
||||
private int nonRegisteredCount;
|
||||
|
||||
private int avgBalance;
|
||||
private int balance;
|
||||
|
||||
private int arbitraryCount;
|
||||
|
||||
@ -48,17 +46,16 @@ public class MintershipReport {
|
||||
protected MintershipReport() {
|
||||
}
|
||||
|
||||
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) {
|
||||
public MintershipReport(String address, int level, int blocksMinted, int adjustments, int penalties, boolean transfer, String name, int sponseeCount, int balance, int arbitraryCount, int transferAssetCount, int transferPrivsCount, int sellCount, int sellAmount, int buyCount, int buyAmount) {
|
||||
this.address = address;
|
||||
this.level = level;
|
||||
this.blocksMinted = blocksMinted;
|
||||
this.adjustments = adjustments;
|
||||
this.penalties = penalties;
|
||||
this.transfer = transfer;
|
||||
this.names = names;
|
||||
this.name = name;
|
||||
this.sponseeCount = sponseeCount;
|
||||
this.nonRegisteredCount = nonRegisteredCount;
|
||||
this.avgBalance = avgBalance;
|
||||
this.balance = balance;
|
||||
this.arbitraryCount = arbitraryCount;
|
||||
this.transferAssetCount = transferAssetCount;
|
||||
this.transferPrivsCount = transferPrivsCount;
|
||||
@ -95,20 +92,16 @@ public class MintershipReport {
|
||||
return transfer;
|
||||
}
|
||||
|
||||
public String[] getNames() {
|
||||
return names;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getSponseeCount() {
|
||||
return sponseeCount;
|
||||
}
|
||||
|
||||
public int getNonRegisteredCount() {
|
||||
return nonRegisteredCount;
|
||||
}
|
||||
|
||||
public int getAvgBalance() {
|
||||
return avgBalance;
|
||||
public int getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public int getArbitraryCount() {
|
||||
@ -148,10 +141,9 @@ public class MintershipReport {
|
||||
", adjustments=" + adjustments +
|
||||
", penalties=" + penalties +
|
||||
", transfer=" + transfer +
|
||||
", names=" + Arrays.toString(names) +
|
||||
", name='" + name + '\'' +
|
||||
", sponseeCount=" + sponseeCount +
|
||||
", nonRegisteredCount=" + nonRegisteredCount +
|
||||
", avgBalance=" + avgBalance +
|
||||
", balance=" + balance +
|
||||
", arbitraryCount=" + arbitraryCount +
|
||||
", transferAssetCount=" + transferAssetCount +
|
||||
", transferPrivsCount=" + transferPrivsCount +
|
||||
|
164
src/main/java/org/qortal/data/account/SponsorshipReport.java
Normal file
164
src/main/java/org/qortal/data/account/SponsorshipReport.java
Normal file
@ -0,0 +1,164 @@
|
||||
package org.qortal.data.account;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import java.util.Arrays;
|
||||
|
||||
// All properties to be converted to JSON via JAXB
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class SponsorshipReport {
|
||||
|
||||
private String address;
|
||||
|
||||
private int level;
|
||||
|
||||
private int blocksMinted;
|
||||
|
||||
private int adjustments;
|
||||
|
||||
private int penalties;
|
||||
|
||||
private boolean transfer;
|
||||
|
||||
private String[] names;
|
||||
|
||||
private int sponseeCount;
|
||||
|
||||
private int nonRegisteredCount;
|
||||
|
||||
private int avgBalance;
|
||||
|
||||
private int arbitraryCount;
|
||||
|
||||
private int transferAssetCount;
|
||||
|
||||
private int transferPrivsCount;
|
||||
|
||||
private int sellCount;
|
||||
|
||||
private int sellAmount;
|
||||
|
||||
private int buyCount;
|
||||
|
||||
private int buyAmount;
|
||||
|
||||
// Constructors
|
||||
|
||||
// For JAXB
|
||||
protected SponsorshipReport() {
|
||||
}
|
||||
|
||||
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) {
|
||||
this.address = address;
|
||||
this.level = level;
|
||||
this.blocksMinted = blocksMinted;
|
||||
this.adjustments = adjustments;
|
||||
this.penalties = penalties;
|
||||
this.transfer = transfer;
|
||||
this.names = names;
|
||||
this.sponseeCount = sponseeCount;
|
||||
this.nonRegisteredCount = nonRegisteredCount;
|
||||
this.avgBalance = avgBalance;
|
||||
this.arbitraryCount = arbitraryCount;
|
||||
this.transferAssetCount = transferAssetCount;
|
||||
this.transferPrivsCount = transferPrivsCount;
|
||||
this.sellCount = sellCount;
|
||||
this.sellAmount = sellAmount;
|
||||
this.buyCount = buyCount;
|
||||
this.buyAmount = buyAmount;
|
||||
}
|
||||
|
||||
// Getters / setters
|
||||
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public int getBlocksMinted() {
|
||||
return blocksMinted;
|
||||
}
|
||||
|
||||
public int getAdjustments() {
|
||||
return adjustments;
|
||||
}
|
||||
|
||||
public int getPenalties() {
|
||||
return penalties;
|
||||
}
|
||||
|
||||
public boolean isTransfer() {
|
||||
return transfer;
|
||||
}
|
||||
|
||||
public String[] getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
public int getSponseeCount() {
|
||||
return sponseeCount;
|
||||
}
|
||||
|
||||
public int getNonRegisteredCount() {
|
||||
return nonRegisteredCount;
|
||||
}
|
||||
|
||||
public int getAvgBalance() {
|
||||
return avgBalance;
|
||||
}
|
||||
|
||||
public int getArbitraryCount() {
|
||||
return arbitraryCount;
|
||||
}
|
||||
|
||||
public int getTransferAssetCount() {
|
||||
return transferAssetCount;
|
||||
}
|
||||
|
||||
public int getTransferPrivsCount() {
|
||||
return transferPrivsCount;
|
||||
}
|
||||
|
||||
public int getSellCount() {
|
||||
return sellCount;
|
||||
}
|
||||
|
||||
public int getSellAmount() {
|
||||
return sellAmount;
|
||||
}
|
||||
|
||||
public int getBuyCount() {
|
||||
return buyCount;
|
||||
}
|
||||
|
||||
public int getBuyAmount() {
|
||||
return buyAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MintershipReport{" +
|
||||
"address='" + address + '\'' +
|
||||
", level=" + level +
|
||||
", blocksMinted=" + blocksMinted +
|
||||
", adjustments=" + adjustments +
|
||||
", penalties=" + penalties +
|
||||
", transfer=" + transfer +
|
||||
", names=" + Arrays.toString(names) +
|
||||
", sponseeCount=" + sponseeCount +
|
||||
", nonRegisteredCount=" + nonRegisteredCount +
|
||||
", avgBalance=" + avgBalance +
|
||||
", arbitraryCount=" + arbitraryCount +
|
||||
", transferAssetCount=" + transferAssetCount +
|
||||
", transferPrivsCount=" + transferPrivsCount +
|
||||
", sellCount=" + sellCount +
|
||||
", sellAmount=" + sellAmount +
|
||||
", buyCount=" + buyCount +
|
||||
", buyAmount=" + buyAmount +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -133,7 +133,7 @@ public interface AccountRepository {
|
||||
/** Returns all account balances for given assetID, optionally excluding zero balances. */
|
||||
public List<AccountBalanceData> getAssetBalances(long assetId, Boolean excludeZero) throws DataException;
|
||||
|
||||
public MintershipReport getSponsorshipReport(String address, String[] realRewardShareRecipients) throws DataException;
|
||||
public SponsorshipReport getSponsorshipReport(String address, String[] realRewardShareRecipients) throws DataException;
|
||||
|
||||
/**
|
||||
* Get Sponsorship Report
|
||||
@ -143,7 +143,7 @@ public interface AccountRepository {
|
||||
* @return the report
|
||||
* @throws DataException
|
||||
*/
|
||||
public MintershipReport getMintershipReport(String address, Function<String, List<String>> addressFetcher) throws DataException;
|
||||
public SponsorshipReport getMintershipReport(String address, Function<String, List<String>> addressFetcher) throws DataException;
|
||||
|
||||
/**
|
||||
* Get Sponsee Addresses
|
||||
|
@ -1158,7 +1158,7 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MintershipReport getSponsorshipReport(String address, String[] realRewardShareRecipients) throws DataException {
|
||||
public SponsorshipReport getSponsorshipReport(String address, String[] realRewardShareRecipients) throws DataException {
|
||||
|
||||
List<String> sponsees = getSponseeAddresses(address, realRewardShareRecipients);
|
||||
|
||||
@ -1166,7 +1166,7 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MintershipReport getMintershipReport(String account, Function<String, List<String>> addressFetcher) throws DataException {
|
||||
public SponsorshipReport getMintershipReport(String account, Function<String, List<String>> addressFetcher) throws DataException {
|
||||
|
||||
try {
|
||||
ResultSet accountResultSet = getAccountResultSet(account);
|
||||
@ -1182,7 +1182,7 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
||||
List<String> sponseeAddresses = addressFetcher.apply(account);
|
||||
|
||||
if( sponseeAddresses.isEmpty() ){
|
||||
return new MintershipReport(account, level, blocksMinted, adjustments, penalties, transferPrivs, new String[0], 0, 0,0, 0, 0, 0, 0, 0, 0, 0);
|
||||
return new SponsorshipReport(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);
|
||||
@ -1319,7 +1319,7 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
||||
* @return the report
|
||||
* @throws SQLException
|
||||
*/
|
||||
private MintershipReport produceSponsorShipReport(
|
||||
private SponsorshipReport produceSponsorShipReport(
|
||||
String address,
|
||||
int level,
|
||||
int blocksMinted,
|
||||
@ -1418,7 +1418,7 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
||||
buyAmount = 0;
|
||||
}
|
||||
|
||||
return new MintershipReport(
|
||||
return new SponsorshipReport(
|
||||
address,
|
||||
level,
|
||||
blocksMinted,
|
||||
|
Loading…
x
Reference in New Issue
Block a user