forked from Qortal/qortal
added transfer privs inquiries to sponsorship analytics
This commit is contained in:
parent
f82533370d
commit
a530b64ae7
@ -18,6 +18,8 @@ public class SponsorshipReport {
|
|||||||
|
|
||||||
private int penalties;
|
private int penalties;
|
||||||
|
|
||||||
|
private boolean transfer;
|
||||||
|
|
||||||
private String[] names;
|
private String[] names;
|
||||||
|
|
||||||
private int sponseeCount;
|
private int sponseeCount;
|
||||||
@ -30,6 +32,8 @@ public class SponsorshipReport {
|
|||||||
|
|
||||||
private int transferAssetCount;
|
private int transferAssetCount;
|
||||||
|
|
||||||
|
private int transferPrivsCount;
|
||||||
|
|
||||||
private int sellCount;
|
private int sellCount;
|
||||||
|
|
||||||
private int sellAmount;
|
private int sellAmount;
|
||||||
@ -44,18 +48,20 @@ public class SponsorshipReport {
|
|||||||
protected SponsorshipReport() {
|
protected SponsorshipReport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SponsorshipReport(String address, int level, int blocksMinted, int adjustments, int penalties, String[] names, int sponseeCount, int nonRegisteredCount, int avgBalance, int arbitraryCount, int transferAssetCount, int sellCount, int sellAmount, int buyCount, int buyAmount) {
|
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.address = address;
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.blocksMinted = blocksMinted;
|
this.blocksMinted = blocksMinted;
|
||||||
this.adjustments = adjustments;
|
this.adjustments = adjustments;
|
||||||
this.penalties = penalties;
|
this.penalties = penalties;
|
||||||
|
this.transfer = transfer;
|
||||||
this.names = names;
|
this.names = names;
|
||||||
this.sponseeCount = sponseeCount;
|
this.sponseeCount = sponseeCount;
|
||||||
this.nonRegisteredCount = nonRegisteredCount;
|
this.nonRegisteredCount = nonRegisteredCount;
|
||||||
this.avgBalance = avgBalance;
|
this.avgBalance = avgBalance;
|
||||||
this.arbitraryCount = arbitraryCount;
|
this.arbitraryCount = arbitraryCount;
|
||||||
this.transferAssetCount = transferAssetCount;
|
this.transferAssetCount = transferAssetCount;
|
||||||
|
this.transferPrivsCount = transferPrivsCount;
|
||||||
this.sellCount = sellCount;
|
this.sellCount = sellCount;
|
||||||
this.sellAmount = sellAmount;
|
this.sellAmount = sellAmount;
|
||||||
this.buyCount = buyCount;
|
this.buyCount = buyCount;
|
||||||
@ -85,6 +91,10 @@ public class SponsorshipReport {
|
|||||||
return penalties;
|
return penalties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTransfer() {
|
||||||
|
return transfer;
|
||||||
|
}
|
||||||
|
|
||||||
public String[] getNames() {
|
public String[] getNames() {
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
@ -109,6 +119,10 @@ public class SponsorshipReport {
|
|||||||
return transferAssetCount;
|
return transferAssetCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getTransferPrivsCount() {
|
||||||
|
return transferPrivsCount;
|
||||||
|
}
|
||||||
|
|
||||||
public int getSellCount() {
|
public int getSellCount() {
|
||||||
return sellCount;
|
return sellCount;
|
||||||
}
|
}
|
||||||
@ -133,12 +147,14 @@ public class SponsorshipReport {
|
|||||||
", blocksMinted=" + blocksMinted +
|
", blocksMinted=" + blocksMinted +
|
||||||
", adjustments=" + adjustments +
|
", adjustments=" + adjustments +
|
||||||
", penalties=" + penalties +
|
", penalties=" + penalties +
|
||||||
|
", transfer=" + transfer +
|
||||||
", names=" + Arrays.toString(names) +
|
", names=" + Arrays.toString(names) +
|
||||||
", sponseeCount=" + sponseeCount +
|
", sponseeCount=" + sponseeCount +
|
||||||
", nonRegisteredCount=" + nonRegisteredCount +
|
", nonRegisteredCount=" + nonRegisteredCount +
|
||||||
", avgBalance=" + avgBalance +
|
", avgBalance=" + avgBalance +
|
||||||
", arbitraryCount=" + arbitraryCount +
|
", arbitraryCount=" + arbitraryCount +
|
||||||
", transferAssetCount=" + transferAssetCount +
|
", transferAssetCount=" + transferAssetCount +
|
||||||
|
", transferPrivsCount=" + transferPrivsCount +
|
||||||
", sellCount=" + sellCount +
|
", sellCount=" + sellCount +
|
||||||
", sellAmount=" + sellAmount +
|
", sellAmount=" + sellAmount +
|
||||||
", buyCount=" + buyCount +
|
", buyCount=" + buyCount +
|
||||||
|
@ -1168,14 +1168,15 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
|||||||
int blocksMinted = accountResultSet.getInt(3);
|
int blocksMinted = accountResultSet.getInt(3);
|
||||||
int adjustments = accountResultSet.getInt(4);
|
int adjustments = accountResultSet.getInt(4);
|
||||||
int penalties = accountResultSet.getInt(5);
|
int penalties = accountResultSet.getInt(5);
|
||||||
|
boolean transferPrivs = accountResultSet.getBoolean(6);
|
||||||
|
|
||||||
List<String> sponseeAddresses = getSponseeAddresses(account);
|
List<String> sponseeAddresses = getSponseeAddresses(account);
|
||||||
|
|
||||||
if( sponseeAddresses.isEmpty() ){
|
if( sponseeAddresses.isEmpty() ){
|
||||||
return new SponsorshipReport(account, level, blocksMinted, adjustments, penalties, new String[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 {
|
else {
|
||||||
return produceSponsorShipReport(account, level, blocksMinted, adjustments, penalties, sponseeAddresses);
|
return produceSponsorShipReport(account, level, blocksMinted, adjustments, penalties, sponseeAddresses, transferPrivs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@ -1249,9 +1250,8 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
|||||||
* @param blocksMintedAdjustment
|
* @param blocksMintedAdjustment
|
||||||
* @param blocksMintedPenalty
|
* @param blocksMintedPenalty
|
||||||
* @param sponseeAddresses
|
* @param sponseeAddresses
|
||||||
*
|
* @param transferPrivs true if this account was involved in a TRANSFER_PRIVS transaction
|
||||||
* @return the report
|
* @return the report
|
||||||
*
|
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
private SponsorshipReport produceSponsorShipReport(
|
private SponsorshipReport produceSponsorShipReport(
|
||||||
@ -1260,7 +1260,8 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
|||||||
int blocksMinted,
|
int blocksMinted,
|
||||||
int blocksMintedAdjustment,
|
int blocksMintedAdjustment,
|
||||||
int blocksMintedPenalty,
|
int blocksMintedPenalty,
|
||||||
List<String> sponseeAddresses) throws SQLException {
|
List<String> sponseeAddresses,
|
||||||
|
boolean transferPrivs) throws SQLException, DataException {
|
||||||
|
|
||||||
int sponseeCount = sponseeAddresses.size();
|
int sponseeCount = sponseeAddresses.size();
|
||||||
|
|
||||||
@ -1275,32 +1276,41 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
|||||||
// count the arbitrary and transfer asset transactions for all sponsees
|
// count the arbitrary and transfer asset transactions for all sponsees
|
||||||
ResultSet txTypeResultSet = getTxTypeResultSet(sponseeAddresses, sponseeCount);
|
ResultSet txTypeResultSet = getTxTypeResultSet(sponseeAddresses, sponseeCount);
|
||||||
|
|
||||||
int arbitraryCount = 0;
|
int arbitraryCount;
|
||||||
int transferAssetCount = 0;
|
int transferAssetCount;
|
||||||
|
int transferPrivsCount;
|
||||||
|
|
||||||
if( txTypeResultSet != null) {
|
if( txTypeResultSet != null) {
|
||||||
int txType = txTypeResultSet.getInt(1);
|
|
||||||
|
|
||||||
// if arbitrary transaction type, then get the count and move to the next result
|
Map<Integer, Integer> countsByType = new HashMap<>(2);
|
||||||
if (txType == 10) {
|
|
||||||
arbitraryCount = txTypeResultSet.getInt(2);
|
|
||||||
|
|
||||||
// if there is another result, then get
|
do{
|
||||||
if (txTypeResultSet.next())
|
Integer type = txTypeResultSet.getInt(1);
|
||||||
txType = txTypeResultSet.getInt(1);
|
|
||||||
|
if( type != null ) {
|
||||||
|
countsByType.put(type, txTypeResultSet.getInt(2));
|
||||||
|
}
|
||||||
|
} while( txTypeResultSet.next());
|
||||||
|
|
||||||
|
arbitraryCount = countsByType.getOrDefault(10, 0);
|
||||||
|
transferAssetCount = countsByType.getOrDefault(12, 0);
|
||||||
|
transferPrivsCount = countsByType.getOrDefault(40, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new DataException("trouble fetching counts for transaction types");
|
||||||
}
|
}
|
||||||
|
|
||||||
// if asset transfer type, then get the count and move to the next result
|
|
||||||
if (txType == 12) {
|
|
||||||
transferAssetCount = txTypeResultSet.getInt(2);
|
|
||||||
txTypeResultSet.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// count up the each the buy and sell foreign coin exchanges for all sponsees
|
// count up the each the buy and sell foreign coin exchanges for all sponsees
|
||||||
// also sum up the balances of these exchanges
|
// also sum up the balances of these exchanges
|
||||||
ResultSet buySellResultSet = getBuySellResultSet(sponseeAddresses, sponseeCount);
|
ResultSet buySellResultSet = getBuySellResultSet(sponseeAddresses, sponseeCount);
|
||||||
|
|
||||||
|
int sellCount;
|
||||||
|
int sellAmount;
|
||||||
|
|
||||||
|
int buyCount;
|
||||||
|
int buyAmount;
|
||||||
|
|
||||||
// if there are results, then fill in the buy/sell amount/counts
|
// if there are results, then fill in the buy/sell amount/counts
|
||||||
if( buySellResultSet != null ) {
|
if( buySellResultSet != null ) {
|
||||||
|
|
||||||
@ -1317,11 +1327,15 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
|||||||
} while( buySellResultSet.next());
|
} while( buySellResultSet.next());
|
||||||
|
|
||||||
|
|
||||||
int sellCount = countsByDirection.getOrDefault(SELL, 0);
|
sellCount = countsByDirection.getOrDefault(SELL, 0);
|
||||||
int sellAmount = amountsByDirection.getOrDefault(SELL, 0);
|
sellAmount = amountsByDirection.getOrDefault(SELL, 0);
|
||||||
|
|
||||||
int buyCount = countsByDirection.getOrDefault(BUY, 0);
|
buyCount = countsByDirection.getOrDefault(BUY, 0);
|
||||||
int buyAmount = amountsByDirection.getOrDefault(BUY, 0);
|
buyAmount = amountsByDirection.getOrDefault(BUY, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new DataException("trouble fetching counts for buy/sell transactions");
|
||||||
|
}
|
||||||
|
|
||||||
return new SponsorshipReport(
|
return new SponsorshipReport(
|
||||||
address,
|
address,
|
||||||
@ -1329,36 +1343,18 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
|||||||
blocksMinted,
|
blocksMinted,
|
||||||
blocksMintedAdjustment,
|
blocksMintedAdjustment,
|
||||||
blocksMintedPenalty,
|
blocksMintedPenalty,
|
||||||
|
transferPrivs,
|
||||||
sponseeNames.toArray(new String[sponseeNames.size()]),
|
sponseeNames.toArray(new String[sponseeNames.size()]),
|
||||||
sponseeCount,
|
sponseeCount,
|
||||||
sponseeCount - sponseeNames.size(),
|
sponseeCount - sponseeNames.size(),
|
||||||
avgBalance,
|
avgBalance,
|
||||||
arbitraryCount,
|
arbitraryCount,
|
||||||
transferAssetCount,
|
transferAssetCount,
|
||||||
|
transferPrivsCount,
|
||||||
sellCount,
|
sellCount,
|
||||||
sellAmount,
|
sellAmount,
|
||||||
buyCount,
|
buyCount,
|
||||||
buyAmount);
|
buyAmount);
|
||||||
|
|
||||||
}
|
|
||||||
// otherwise use zeros for the counts and amounts
|
|
||||||
|
|
||||||
return new SponsorshipReport(
|
|
||||||
address,
|
|
||||||
level,
|
|
||||||
blocksMinted,
|
|
||||||
blocksMintedAdjustment,
|
|
||||||
blocksMintedPenalty,
|
|
||||||
sponseeNames.toArray(new String[sponseeNames.size()]),
|
|
||||||
sponseeCount,
|
|
||||||
sponseeCount - sponseeNames.size(),
|
|
||||||
avgBalance,
|
|
||||||
arbitraryCount,
|
|
||||||
transferAssetCount,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResultSet getBuySellResultSet(List<String> sponseeAddresses, int sponseeCount) throws SQLException {
|
private ResultSet getBuySellResultSet(List<String> sponseeAddresses, int sponseeCount) throws SQLException {
|
||||||
@ -1392,8 +1388,9 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
|||||||
|
|
||||||
StringBuffer accountSql = new StringBuffer();
|
StringBuffer accountSql = new StringBuffer();
|
||||||
|
|
||||||
accountSql.append( "SELECT DISTINCT account, level, blocks_minted, blocks_minted_adjustment, blocks_minted_penalty ");
|
accountSql.append( "SELECT DISTINCT a.account, a.level, a.blocks_minted, a.blocks_minted_adjustment, a.blocks_minted_penalty, tx.sender IS NOT NULL as transfer ");
|
||||||
accountSql.append( "FROM ACCOUNTS ");
|
accountSql.append( "FROM ACCOUNTS a ");
|
||||||
|
accountSql.append( "LEFT JOIN TRANSFERPRIVSTRANSACTIONS tx on a.public_key = tx.sender or a.account = tx.recipient ");
|
||||||
accountSql.append( "WHERE account = ? ");
|
accountSql.append( "WHERE account = ? ");
|
||||||
|
|
||||||
ResultSet accountResultSet = this.repository.checkedExecute( accountSql.toString(), account);
|
ResultSet accountResultSet = this.repository.checkedExecute( accountSql.toString(), account);
|
||||||
@ -1413,7 +1410,7 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
|||||||
txTypeTotalsSql.append("INNER JOIN TRANSACTIONS USING (signature) ");
|
txTypeTotalsSql.append("INNER JOIN TRANSACTIONS USING (signature) ");
|
||||||
txTypeTotalsSql.append("where participant in ( ");
|
txTypeTotalsSql.append("where participant in ( ");
|
||||||
txTypeTotalsSql.append(String.join(", ", Collections.nCopies(sponseeCount, "?")));
|
txTypeTotalsSql.append(String.join(", ", Collections.nCopies(sponseeCount, "?")));
|
||||||
txTypeTotalsSql.append(") and type in (10, 12) ");
|
txTypeTotalsSql.append(") and type in (10, 12, 40) ");
|
||||||
txTypeTotalsSql.append("group by type order by type");
|
txTypeTotalsSql.append("group by type order by type");
|
||||||
|
|
||||||
String[] sponsees = sponseeAddresses.toArray(new String[sponseeCount]);
|
String[] sponsees = sponseeAddresses.toArray(new String[sponseeCount]);
|
||||||
|
Loading…
Reference in New Issue
Block a user