mirror of
https://github.com/Qortal/qortal.git
synced 2025-07-22 20:26:50 +00:00
Fixed API call GET /blocks/minter/{address}. Now returns block summaries instead of full block data.
This commit is contained in:
@@ -28,6 +28,7 @@ import org.qortal.api.model.BlockMinterSummary;
|
||||
import org.qortal.crypto.Crypto;
|
||||
import org.qortal.data.account.AccountData;
|
||||
import org.qortal.data.block.BlockData;
|
||||
import org.qortal.data.block.BlockSummaryData;
|
||||
import org.qortal.data.transaction.TransactionData;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.repository.Repository;
|
||||
@@ -423,14 +424,14 @@ public class BlocksResource {
|
||||
@GET
|
||||
@Path("/minter/{address}")
|
||||
@Operation(
|
||||
summary = "Fetch blocks minted by address",
|
||||
summary = "Fetch block summaries for blocks minted by address",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "blocks",
|
||||
description = "block summaries",
|
||||
content = @Content(
|
||||
array = @ArraySchema(
|
||||
schema = @Schema(
|
||||
implementation = BlockData.class
|
||||
implementation = BlockSummaryData.class
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -438,7 +439,7 @@ public class BlocksResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.PUBLIC_KEY_NOT_FOUND, ApiError.REPOSITORY_ISSUE})
|
||||
public List<BlockData> getBlocksByMinter(@PathParam("address") String address, @Parameter(
|
||||
public List<BlockSummaryData> getBlockSummariesByMinter(@PathParam("address") String address, @Parameter(
|
||||
ref = "limit"
|
||||
) @QueryParam("limit") Integer limit, @Parameter(
|
||||
ref = "offset"
|
||||
@@ -454,7 +455,7 @@ public class BlocksResource {
|
||||
if (accountData == null || accountData.getPublicKey() == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.PUBLIC_KEY_NOT_FOUND);
|
||||
|
||||
return repository.getBlockRepository().getBlocksByMinter(accountData.getPublicKey(), limit, offset, reverse);
|
||||
return repository.getBlockRepository().getBlockSummariesByMinter(accountData.getPublicKey(), limit, offset, reverse);
|
||||
} catch (ApiException e) {
|
||||
throw e;
|
||||
} catch (DataException e) {
|
||||
|
@@ -1,7 +1,11 @@
|
||||
package org.qortal.data.block;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
|
||||
import org.qortal.transform.block.BlockTransformer;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class BlockSummaryData {
|
||||
|
||||
// Properties
|
||||
@@ -14,6 +18,10 @@ public class BlockSummaryData {
|
||||
private Integer minterLevel;
|
||||
|
||||
// Constructors
|
||||
|
||||
protected BlockSummaryData() {
|
||||
}
|
||||
|
||||
public BlockSummaryData(int height, byte[] signature, byte[] minterPublicKey, int onlineAccountsCount) {
|
||||
this.height = height;
|
||||
this.signature = signature;
|
||||
|
@@ -114,9 +114,9 @@ public interface BlockRepository {
|
||||
public List<BlockMinterSummary> getBlockMinters(List<String> addresses, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||
|
||||
/**
|
||||
* Returns blocks with passed minter public key.
|
||||
* Returns block summaries for blocks minted by passed public key, or reward-share with minter with passed public key.
|
||||
*/
|
||||
public List<BlockData> getBlocksByMinter(byte[] minterPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||
public List<BlockSummaryData> getBlockSummariesByMinter(byte[] minterPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||
|
||||
/**
|
||||
* Returns blocks within height range.
|
||||
|
@@ -258,27 +258,41 @@ public class HSQLDBBlockRepository implements BlockRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockData> getBlocksByMinter(byte[] minterPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException {
|
||||
public List<BlockSummaryData> getBlockSummariesByMinter(byte[] minterPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException {
|
||||
StringBuilder sql = new StringBuilder(512);
|
||||
sql.append("SELECT " + BLOCK_DB_COLUMNS + " FROM Blocks WHERE minter = ? ORDER BY height ");
|
||||
sql.append("SELECT signature, height, minter, online_accounts_count FROM ");
|
||||
|
||||
// List of minter account's public key and reward-share public keys with minter's public key
|
||||
sql.append("(SELECT * FROM (VALUES (CAST(? AS QortalPublicKey))) UNION (SELECT reward_share_public_key FROM RewardShares WHERE minter_public_key = ?)) AS PublicKeys (public_key) ");
|
||||
|
||||
// Match Blocks signed with public key from above list
|
||||
sql.append("JOIN Blocks ON minter = public_key ");
|
||||
|
||||
sql.append("ORDER BY Blocks.height ");
|
||||
if (reverse != null && reverse)
|
||||
sql.append(" DESC");
|
||||
sql.append("DESC ");
|
||||
|
||||
HSQLDBRepository.limitOffsetSql(sql, limit, offset);
|
||||
|
||||
List<BlockData> blockData = new ArrayList<>();
|
||||
List<BlockSummaryData> blockSummaries = new ArrayList<>();
|
||||
|
||||
try (ResultSet resultSet = this.repository.checkedExecute(sql.toString(), minterPublicKey)) {
|
||||
try (ResultSet resultSet = this.repository.checkedExecute(sql.toString(), minterPublicKey, minterPublicKey)) {
|
||||
if (resultSet == null)
|
||||
return blockData;
|
||||
return blockSummaries;
|
||||
|
||||
do {
|
||||
blockData.add(getBlockFromResultSet(resultSet));
|
||||
byte[] signature = resultSet.getBytes(1);
|
||||
int height = resultSet.getInt(2);
|
||||
byte[] blockMinterPublicKey = resultSet.getBytes(3);
|
||||
int onlineAccountsCount = resultSet.getInt(4);
|
||||
|
||||
BlockSummaryData blockSummary = new BlockSummaryData(height, signature, blockMinterPublicKey, onlineAccountsCount);
|
||||
blockSummaries.add(blockSummary);
|
||||
} while (resultSet.next());
|
||||
|
||||
return blockData;
|
||||
return blockSummaries;
|
||||
} catch (SQLException e) {
|
||||
throw new DataException("Unable to fetch minter's blocks from repository", e);
|
||||
throw new DataException("Unable to fetch minter's block summaries from repository", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user