mirror of
https://github.com/Qortal/qortal.git
synced 2025-05-10 11:47:51 +00:00
Fixed API call GET /blocks/minter/{address}. Now returns block summaries instead of full block data.
This commit is contained in:
parent
1cb2935cad
commit
774a8f20ee
@ -28,6 +28,7 @@ import org.qortal.api.model.BlockMinterSummary;
|
|||||||
import org.qortal.crypto.Crypto;
|
import org.qortal.crypto.Crypto;
|
||||||
import org.qortal.data.account.AccountData;
|
import org.qortal.data.account.AccountData;
|
||||||
import org.qortal.data.block.BlockData;
|
import org.qortal.data.block.BlockData;
|
||||||
|
import org.qortal.data.block.BlockSummaryData;
|
||||||
import org.qortal.data.transaction.TransactionData;
|
import org.qortal.data.transaction.TransactionData;
|
||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
import org.qortal.repository.Repository;
|
import org.qortal.repository.Repository;
|
||||||
@ -423,14 +424,14 @@ public class BlocksResource {
|
|||||||
@GET
|
@GET
|
||||||
@Path("/minter/{address}")
|
@Path("/minter/{address}")
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Fetch blocks minted by address",
|
summary = "Fetch block summaries for blocks minted by address",
|
||||||
responses = {
|
responses = {
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
description = "blocks",
|
description = "block summaries",
|
||||||
content = @Content(
|
content = @Content(
|
||||||
array = @ArraySchema(
|
array = @ArraySchema(
|
||||||
schema = @Schema(
|
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})
|
@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"
|
ref = "limit"
|
||||||
) @QueryParam("limit") Integer limit, @Parameter(
|
) @QueryParam("limit") Integer limit, @Parameter(
|
||||||
ref = "offset"
|
ref = "offset"
|
||||||
@ -454,7 +455,7 @@ public class BlocksResource {
|
|||||||
if (accountData == null || accountData.getPublicKey() == null)
|
if (accountData == null || accountData.getPublicKey() == null)
|
||||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.PUBLIC_KEY_NOT_FOUND);
|
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) {
|
} catch (ApiException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (DataException e) {
|
} catch (DataException e) {
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package org.qortal.data.block;
|
package org.qortal.data.block;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
|
||||||
import org.qortal.transform.block.BlockTransformer;
|
import org.qortal.transform.block.BlockTransformer;
|
||||||
|
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
public class BlockSummaryData {
|
public class BlockSummaryData {
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
@ -14,6 +18,10 @@ public class BlockSummaryData {
|
|||||||
private Integer minterLevel;
|
private Integer minterLevel;
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
|
protected BlockSummaryData() {
|
||||||
|
}
|
||||||
|
|
||||||
public BlockSummaryData(int height, byte[] signature, byte[] minterPublicKey, int onlineAccountsCount) {
|
public BlockSummaryData(int height, byte[] signature, byte[] minterPublicKey, int onlineAccountsCount) {
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.signature = signature;
|
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;
|
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.
|
* Returns blocks within height range.
|
||||||
|
@ -258,27 +258,41 @@ public class HSQLDBBlockRepository implements BlockRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
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)
|
if (reverse != null && reverse)
|
||||||
sql.append("DESC ");
|
sql.append("DESC ");
|
||||||
|
|
||||||
HSQLDBRepository.limitOffsetSql(sql, limit, offset);
|
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)
|
if (resultSet == null)
|
||||||
return blockData;
|
return blockSummaries;
|
||||||
|
|
||||||
do {
|
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());
|
} while (resultSet.next());
|
||||||
|
|
||||||
return blockData;
|
return blockSummaries;
|
||||||
} catch (SQLException e) {
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public class BlockApiTests extends ApiCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetBlockForgers() {
|
public void testGetBlockMinters() {
|
||||||
List<String> addresses = Arrays.asList(aliceAddress, aliceAddress);
|
List<String> addresses = Arrays.asList(aliceAddress, aliceAddress);
|
||||||
|
|
||||||
assertNotNull(this.blocksResource.getBlockMinters(Collections.emptyList(), null, null, null));
|
assertNotNull(this.blocksResource.getBlockMinters(Collections.emptyList(), null, null, null));
|
||||||
@ -36,9 +36,9 @@ public class BlockApiTests extends ApiCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetBlocksByForger() {
|
public void testGetBlockSummariesByMinter() {
|
||||||
assertNotNull(this.blocksResource.getBlocksByMinter(aliceAddress, null, null, null));
|
assertNotNull(this.blocksResource.getBlockSummariesByMinter(aliceAddress, null, null, null));
|
||||||
assertNotNull(this.blocksResource.getBlocksByMinter(aliceAddress, 1, 1, true));
|
assertNotNull(this.blocksResource.getBlockSummariesByMinter(aliceAddress, 1, 1, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ public class GroupApprovalTests extends Common {
|
|||||||
|
|
||||||
// Transaction fee should have ended up in forging account
|
// Transaction fee should have ended up in forging account
|
||||||
BigDecimal alicePostAssetBalance = aliceAccount.getConfirmedBalance(Asset.QORT);
|
BigDecimal alicePostAssetBalance = aliceAccount.getConfirmedBalance(Asset.QORT);
|
||||||
Common.assertEqualBigDecimals("block forger's balance incorrect", aliceOriginalBalance.add(blockReward).add(fee), alicePostAssetBalance);
|
Common.assertEqualBigDecimals("block minter's balance incorrect", aliceOriginalBalance.add(blockReward).add(fee), alicePostAssetBalance);
|
||||||
|
|
||||||
// Have Bob do a non-approval transaction to change his last-reference
|
// Have Bob do a non-approval transaction to change his last-reference
|
||||||
Transaction bobPaymentTransaction = buildPaymentTransaction(repository, "bob", "chloe", amount, Group.NO_GROUP);
|
Transaction bobPaymentTransaction = buildPaymentTransaction(repository, "bob", "chloe", amount, Group.NO_GROUP);
|
||||||
@ -122,7 +122,7 @@ public class GroupApprovalTests extends Common {
|
|||||||
// Have Alice approve Bob's approval-needed transaction
|
// Have Alice approve Bob's approval-needed transaction
|
||||||
GroupUtils.approveTransaction(repository, "alice", bobAssetTransaction.getTransactionData().getSignature(), true);
|
GroupUtils.approveTransaction(repository, "alice", bobAssetTransaction.getTransactionData().getSignature(), true);
|
||||||
|
|
||||||
// Now forge a few blocks so transaction is approved
|
// Now mint a few blocks so transaction is approved
|
||||||
for (int blockCount = 0; blockCount < minBlockDelay; ++blockCount)
|
for (int blockCount = 0; blockCount < minBlockDelay; ++blockCount)
|
||||||
BlockUtils.mintBlock(repository);
|
BlockUtils.mintBlock(repository);
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ public class GroupApprovalTests extends Common {
|
|||||||
// Have Alice approve Bob's approval-needed transaction
|
// Have Alice approve Bob's approval-needed transaction
|
||||||
GroupUtils.approveTransaction(repository, "alice", bobAssetTransaction.getTransactionData().getSignature(), true);
|
GroupUtils.approveTransaction(repository, "alice", bobAssetTransaction.getTransactionData().getSignature(), true);
|
||||||
|
|
||||||
// Now forge a few blocks so transaction is approved
|
// Now mint a few blocks so transaction is approved
|
||||||
for (int blockCount = 0; blockCount < minBlockDelay; ++blockCount)
|
for (int blockCount = 0; blockCount < minBlockDelay; ++blockCount)
|
||||||
BlockUtils.mintBlock(repository);
|
BlockUtils.mintBlock(repository);
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ public class GroupApprovalTests extends Common {
|
|||||||
// Have Alice reject Bob's approval-needed transaction
|
// Have Alice reject Bob's approval-needed transaction
|
||||||
GroupUtils.approveTransaction(repository, "alice", bobAssetTransaction.getTransactionData().getSignature(), false);
|
GroupUtils.approveTransaction(repository, "alice", bobAssetTransaction.getTransactionData().getSignature(), false);
|
||||||
|
|
||||||
// Now forge a few blocks so transaction is approved
|
// Now mint a few blocks so transaction is approved
|
||||||
for (int blockCount = 0; blockCount < minBlockDelay; ++blockCount)
|
for (int blockCount = 0; blockCount < minBlockDelay; ++blockCount)
|
||||||
BlockUtils.mintBlock(repository);
|
BlockUtils.mintBlock(repository);
|
||||||
|
|
||||||
@ -314,7 +314,7 @@ public class GroupApprovalTests extends Common {
|
|||||||
Integer approvalHeight = GroupUtils.getApprovalHeight(repository, bobAssetTransaction.getTransactionData().getSignature());
|
Integer approvalHeight = GroupUtils.getApprovalHeight(repository, bobAssetTransaction.getTransactionData().getSignature());
|
||||||
assertNull("group-approval decision height should be null", approvalHeight);
|
assertNull("group-approval decision height should be null", approvalHeight);
|
||||||
|
|
||||||
// Now forge a few blocks so group-approval for transaction expires
|
// Now mint a few blocks so group-approval for transaction expires
|
||||||
for (int blockCount = 0; blockCount <= maxBlockDelay; ++blockCount)
|
for (int blockCount = 0; blockCount <= maxBlockDelay; ++blockCount)
|
||||||
BlockUtils.mintBlock(repository);
|
BlockUtils.mintBlock(repository);
|
||||||
|
|
||||||
@ -374,7 +374,7 @@ public class GroupApprovalTests extends Common {
|
|||||||
approvalStatus = GroupUtils.getApprovalStatus(repository, aliceAssetTransaction.getTransactionData().getSignature());
|
approvalStatus = GroupUtils.getApprovalStatus(repository, aliceAssetTransaction.getTransactionData().getSignature());
|
||||||
assertEquals("incorrect transaction approval status", ApprovalStatus.NOT_REQUIRED, approvalStatus);
|
assertEquals("incorrect transaction approval status", ApprovalStatus.NOT_REQUIRED, approvalStatus);
|
||||||
|
|
||||||
// Now forge a few blocks so transaction is approved
|
// Now mint a few blocks so transaction is approved
|
||||||
for (int blockCount = 0; blockCount < minBlockDelay; ++blockCount)
|
for (int blockCount = 0; blockCount < minBlockDelay; ++blockCount)
|
||||||
BlockUtils.mintBlock(repository);
|
BlockUtils.mintBlock(repository);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user