mirror of
https://github.com/Qortal/qortal.git
synced 2025-03-13 19:12:33 +00:00
Improve API call showing block forger summaries to include proxy info
This commit is contained in:
parent
92e60e2531
commit
ae6b41a893
@ -1,20 +0,0 @@
|
|||||||
package org.qora.api.model;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
|
||||||
|
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
|
||||||
public class BlockForgeSummary {
|
|
||||||
|
|
||||||
public String address;
|
|
||||||
public int blockCount;
|
|
||||||
|
|
||||||
protected BlockForgeSummary() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlockForgeSummary(String address, int blockCount) {
|
|
||||||
this.address = address;
|
|
||||||
this.blockCount = blockCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
34
src/main/java/org/qora/api/model/BlockForgerSummary.java
Normal file
34
src/main/java/org/qora/api/model/BlockForgerSummary.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package org.qora.api.model;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
|
||||||
|
import org.qora.crypto.Crypto;
|
||||||
|
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
public class BlockForgerSummary {
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
|
||||||
|
public String generatorAddress;
|
||||||
|
public int blockCount;
|
||||||
|
|
||||||
|
public String forgedBy;
|
||||||
|
public String forgedFor;
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
protected BlockForgerSummary() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockForgerSummary(byte[] generator, int blockCount, byte[] forger, String recipient) {
|
||||||
|
this.generatorAddress = Crypto.toAddress(generator);
|
||||||
|
this.blockCount = blockCount;
|
||||||
|
|
||||||
|
if (recipient != null) {
|
||||||
|
this.forgedBy = Crypto.toAddress(forger);
|
||||||
|
this.forgedFor = recipient;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -27,7 +27,7 @@ import org.qora.api.ApiError;
|
|||||||
import org.qora.api.ApiErrors;
|
import org.qora.api.ApiErrors;
|
||||||
import org.qora.api.ApiException;
|
import org.qora.api.ApiException;
|
||||||
import org.qora.api.ApiExceptionFactory;
|
import org.qora.api.ApiExceptionFactory;
|
||||||
import org.qora.api.model.BlockForgeSummary;
|
import org.qora.api.model.BlockForgerSummary;
|
||||||
import org.qora.block.Block;
|
import org.qora.block.Block;
|
||||||
import org.qora.crypto.Crypto;
|
import org.qora.crypto.Crypto;
|
||||||
import org.qora.data.account.AccountData;
|
import org.qora.data.account.AccountData;
|
||||||
@ -574,14 +574,14 @@ public class BlocksResource {
|
|||||||
content = @Content(
|
content = @Content(
|
||||||
array = @ArraySchema(
|
array = @ArraySchema(
|
||||||
schema = @Schema(
|
schema = @Schema(
|
||||||
implementation = BlockForgeSummary.class
|
implementation = BlockForgerSummary.class
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public List<BlockForgeSummary> getBlockForgers(@Parameter(
|
public List<BlockForgerSummary> getBlockForgers(@Parameter(
|
||||||
ref = "limit"
|
ref = "limit"
|
||||||
) @QueryParam("limit") Integer limit, @Parameter(
|
) @QueryParam("limit") Integer limit, @Parameter(
|
||||||
ref = "offset"
|
ref = "offset"
|
||||||
|
@ -2,7 +2,7 @@ package org.qora.repository;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.qora.api.model.BlockForgeSummary;
|
import org.qora.api.model.BlockForgerSummary;
|
||||||
import org.qora.data.block.BlockData;
|
import org.qora.data.block.BlockData;
|
||||||
import org.qora.data.block.BlockTransactionData;
|
import org.qora.data.block.BlockTransactionData;
|
||||||
import org.qora.data.transaction.TransactionData;
|
import org.qora.data.transaction.TransactionData;
|
||||||
@ -105,7 +105,7 @@ public interface BlockRepository {
|
|||||||
/**
|
/**
|
||||||
* Returns summaries of block forgers.
|
* Returns summaries of block forgers.
|
||||||
*/
|
*/
|
||||||
public List<BlockForgeSummary> getBlockForgers(Integer limit, Integer offset, Boolean reverse) throws DataException;
|
public List<BlockForgerSummary> getBlockForgers(Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns blocks with passed generator public key.
|
* Returns blocks with passed generator public key.
|
||||||
|
@ -6,8 +6,7 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.qora.api.model.BlockForgeSummary;
|
import org.qora.api.model.BlockForgerSummary;
|
||||||
import org.qora.crypto.Crypto;
|
|
||||||
import org.qora.data.block.BlockData;
|
import org.qora.data.block.BlockData;
|
||||||
import org.qora.data.block.BlockTransactionData;
|
import org.qora.data.block.BlockTransactionData;
|
||||||
import org.qora.data.transaction.TransactionData;
|
import org.qora.data.transaction.TransactionData;
|
||||||
@ -165,14 +164,17 @@ public class HSQLDBBlockRepository implements BlockRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BlockForgeSummary> getBlockForgers(Integer limit, Integer offset, Boolean reverse) throws DataException {
|
public List<BlockForgerSummary> getBlockForgers(Integer limit, Integer offset, Boolean reverse) throws DataException {
|
||||||
String sql = "SELECT generator, COUNT(signature) FROM Blocks GROUP BY generator ORDER BY COUNT(signature) ";
|
String subquerySql = "SELECT generator, COUNT(signature) FROM Blocks GROUP BY generator ORDER BY COUNT(signature) ";
|
||||||
if (reverse != null && reverse)
|
if (reverse != null && reverse)
|
||||||
sql += " DESC";
|
subquerySql += " DESC";
|
||||||
|
|
||||||
|
String sql = "SELECT generator, n_blocks, forger, recipient FROM (" + subquerySql + ") AS Forgers (generator, n_blocks) "
|
||||||
|
+ " LEFT OUTER JOIN ProxyForgers ON proxy_public_key = generator ";
|
||||||
|
|
||||||
sql += HSQLDBRepository.limitOffsetSql(limit, offset);
|
sql += HSQLDBRepository.limitOffsetSql(limit, offset);
|
||||||
|
|
||||||
List<BlockForgeSummary> summaries = new ArrayList<>();
|
List<BlockForgerSummary> summaries = new ArrayList<>();
|
||||||
|
|
||||||
try (ResultSet resultSet = this.repository.checkedExecute(sql)) {
|
try (ResultSet resultSet = this.repository.checkedExecute(sql)) {
|
||||||
if (resultSet == null)
|
if (resultSet == null)
|
||||||
@ -180,9 +182,11 @@ public class HSQLDBBlockRepository implements BlockRepository {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
byte[] generator = resultSet.getBytes(1);
|
byte[] generator = resultSet.getBytes(1);
|
||||||
int count = resultSet.getInt(2);
|
int nBlocks = resultSet.getInt(2);
|
||||||
|
byte[] forger = resultSet.getBytes(3);
|
||||||
|
String recipient = resultSet.getString(4);
|
||||||
|
|
||||||
summaries.add(new BlockForgeSummary(Crypto.toAddress(generator), count));
|
summaries.add(new BlockForgerSummary(generator, nBlocks, forger, recipient));
|
||||||
} while (resultSet.next());
|
} while (resultSet.next());
|
||||||
|
|
||||||
return summaries;
|
return summaries;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user