From e5e60a50326ba5acf17a1878352571aa10cd6c67 Mon Sep 17 00:00:00 2001 From: catbref Date: Tue, 16 Jun 2020 16:58:34 +0100 Subject: [PATCH] Fix badly named API calls refering to block signers as block minters! Renamed GET /blocks/minters to /blocks/signers Renamed GET /blocks/minter/{address} to /blocks/signer/{address} Changed corresponding repository methods and data classes. --- ...erSummary.java => BlockSignerSummary.java} | 12 +++++----- .../qortal/api/resource/BlocksResource.java | 22 ++++++++--------- .../qortal/repository/BlockRepository.java | 14 +++++------ .../hsqldb/HSQLDBBlockRepository.java | 24 +++++++++---------- .../org/qortal/test/api/BlockApiTests.java | 16 ++++++------- 5 files changed, 44 insertions(+), 44 deletions(-) rename src/main/java/org/qortal/api/model/{BlockMinterSummary.java => BlockSignerSummary.java} (73%) diff --git a/src/main/java/org/qortal/api/model/BlockMinterSummary.java b/src/main/java/org/qortal/api/model/BlockSignerSummary.java similarity index 73% rename from src/main/java/org/qortal/api/model/BlockMinterSummary.java rename to src/main/java/org/qortal/api/model/BlockSignerSummary.java index 33b45be1..61961f28 100644 --- a/src/main/java/org/qortal/api/model/BlockMinterSummary.java +++ b/src/main/java/org/qortal/api/model/BlockSignerSummary.java @@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlAccessorType; import org.qortal.crypto.Crypto; @XmlAccessorType(XmlAccessType.FIELD) -public class BlockMinterSummary { +public class BlockSignerSummary { // Properties @@ -20,19 +20,19 @@ public class BlockMinterSummary { // Constructors - protected BlockMinterSummary() { + protected BlockSignerSummary() { } - /** Constructs BlockMinterSummary in non-reward-share context. */ - public BlockMinterSummary(byte[] blockMinterPublicKey, int blockCount) { + /** Constructs BlockSignerSummary in non-reward-share context. */ + public BlockSignerSummary(byte[] blockMinterPublicKey, int blockCount) { this.blockCount = blockCount; this.mintingAccountPublicKey = blockMinterPublicKey; this.mintingAccount = Crypto.toAddress(this.mintingAccountPublicKey); } - /** Constructs BlockMinterSummary in reward-share context. */ - public BlockMinterSummary(byte[] rewardSharePublicKey, int blockCount, byte[] mintingAccountPublicKey, String minterAccount, String recipientAccount) { + /** Constructs BlockSignerSummary in reward-share context. */ + public BlockSignerSummary(byte[] rewardSharePublicKey, int blockCount, byte[] mintingAccountPublicKey, String minterAccount, String recipientAccount) { this.rewardSharePublicKey = rewardSharePublicKey; this.blockCount = blockCount; diff --git a/src/main/java/org/qortal/api/resource/BlocksResource.java b/src/main/java/org/qortal/api/resource/BlocksResource.java index ddb37a67..6686268e 100644 --- a/src/main/java/org/qortal/api/resource/BlocksResource.java +++ b/src/main/java/org/qortal/api/resource/BlocksResource.java @@ -23,7 +23,7 @@ import javax.ws.rs.core.MediaType; import org.qortal.api.ApiError; import org.qortal.api.ApiErrors; import org.qortal.api.ApiExceptionFactory; -import org.qortal.api.model.BlockMinterSummary; +import org.qortal.api.model.BlockSignerSummary; import org.qortal.crypto.Crypto; import org.qortal.data.account.AccountData; import org.qortal.data.block.BlockData; @@ -405,9 +405,9 @@ public class BlocksResource { } @GET - @Path("/minter/{address}") + @Path("/signer/{address}") @Operation( - summary = "Fetch block summaries for blocks minted by address", + summary = "Fetch block summaries for blocks signed by address", responses = { @ApiResponse( description = "block summaries", @@ -422,7 +422,7 @@ public class BlocksResource { } ) @ApiErrors({ApiError.INVALID_ADDRESS, ApiError.PUBLIC_KEY_NOT_FOUND, ApiError.REPOSITORY_ISSUE}) - public List getBlockSummariesByMinter(@PathParam("address") String address, @Parameter( + public List getBlockSummariesBySigner(@PathParam("address") String address, @Parameter( ref = "limit" ) @QueryParam("limit") Integer limit, @Parameter( ref = "offset" @@ -438,30 +438,30 @@ public class BlocksResource { if (accountData == null || accountData.getPublicKey() == null) throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.PUBLIC_KEY_NOT_FOUND); - return repository.getBlockRepository().getBlockSummariesByMinter(accountData.getPublicKey(), limit, offset, reverse); + return repository.getBlockRepository().getBlockSummariesBySigner(accountData.getPublicKey(), limit, offset, reverse); } catch (DataException e) { throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e); } } @GET - @Path("/minters") + @Path("/signers") @Operation( - summary = "Show summary of block minters", - description = "Returns count of blocks minted, optionally limited to minters/recipients in passed address(es).", + summary = "Show summary of block signers", + description = "Returns count of blocks signed, optionally limited to minters/recipients in passed address(es).", responses = { @ApiResponse( content = @Content( array = @ArraySchema( schema = @Schema( - implementation = BlockMinterSummary.class + implementation = BlockSignerSummary.class ) ) ) ) } ) - public List getBlockMinters(@QueryParam("address") List addresses, + public List getBlockSigners(@QueryParam("address") List addresses, @Parameter( ref = "limit" ) @QueryParam("limit") Integer limit, @Parameter( @@ -474,7 +474,7 @@ public class BlocksResource { if (!Crypto.isValidAddress(address)) throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS); - return repository.getBlockRepository().getBlockMinters(addresses, limit, offset, reverse); + return repository.getBlockRepository().getBlockSigners(addresses, limit, offset, reverse); } catch (DataException e) { throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e); } diff --git a/src/main/java/org/qortal/repository/BlockRepository.java b/src/main/java/org/qortal/repository/BlockRepository.java index a7f8e1f9..24372212 100644 --- a/src/main/java/org/qortal/repository/BlockRepository.java +++ b/src/main/java/org/qortal/repository/BlockRepository.java @@ -2,7 +2,7 @@ package org.qortal.repository; import java.util.List; -import org.qortal.api.model.BlockMinterSummary; +import org.qortal.api.model.BlockSignerSummary; import org.qortal.data.block.BlockData; import org.qortal.data.block.BlockSummaryData; import org.qortal.data.block.BlockTransactionData; @@ -100,23 +100,23 @@ public interface BlockRepository { } /** - * Returns number of blocks minted by account/reward-share with given public key. + * Returns number of blocks signed by account/reward-share with given public key. * * @param publicKey * @return number of blocks * @throws DataException */ - public int countMintedBlocks(byte[] publicKey) throws DataException; + public int countSignedBlocks(byte[] publicKey) throws DataException; /** - * Returns summaries of block minters, optionally limited to passed addresses. + * Returns summaries of block signers, optionally limited to passed addresses. */ - public List getBlockMinters(List addresses, Integer limit, Integer offset, Boolean reverse) throws DataException; + public List getBlockSigners(List addresses, Integer limit, Integer offset, Boolean reverse) throws DataException; /** - * Returns block summaries for blocks minted by passed public key, or reward-share with minter with passed public key. + * Returns block summaries for blocks signed by passed public key, or reward-share with minter with passed public key. */ - public List getBlockSummariesByMinter(byte[] minterPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException; + public List getBlockSummariesBySigner(byte[] signerPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException; /** * Returns blocks within height range. diff --git a/src/main/java/org/qortal/repository/hsqldb/HSQLDBBlockRepository.java b/src/main/java/org/qortal/repository/hsqldb/HSQLDBBlockRepository.java index fc6477ad..0860e1b1 100644 --- a/src/main/java/org/qortal/repository/hsqldb/HSQLDBBlockRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/HSQLDBBlockRepository.java @@ -6,7 +6,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.qortal.api.model.BlockMinterSummary; +import org.qortal.api.model.BlockSignerSummary; import org.qortal.data.block.BlockData; import org.qortal.data.block.BlockSummaryData; import org.qortal.data.block.BlockTransactionData; @@ -187,7 +187,7 @@ public class HSQLDBBlockRepository implements BlockRepository { } @Override - public int countMintedBlocks(byte[] minterPublicKey) throws DataException { + public int countSignedBlocks(byte[] signerPublicKey) throws DataException { String directSql = "SELECT COUNT(*) FROM Blocks WHERE minter = ?"; String rewardShareSql = "SELECT COUNT(*) FROM RewardShares " @@ -196,13 +196,13 @@ public class HSQLDBBlockRepository implements BlockRepository { int totalCount = 0; - try (ResultSet resultSet = this.repository.checkedExecute(directSql, minterPublicKey)) { + try (ResultSet resultSet = this.repository.checkedExecute(directSql, signerPublicKey)) { totalCount += resultSet.getInt(1); } catch (SQLException e) { throw new DataException("Unable to count minted blocks in repository", e); } - try (ResultSet resultSet = this.repository.checkedExecute(rewardShareSql, minterPublicKey)) { + try (ResultSet resultSet = this.repository.checkedExecute(rewardShareSql, signerPublicKey)) { totalCount += resultSet.getInt(1); } catch (SQLException e) { throw new DataException("Unable to count reward-share minted blocks in repository", e); @@ -212,7 +212,7 @@ public class HSQLDBBlockRepository implements BlockRepository { } @Override - public List getBlockMinters(List addresses, Integer limit, Integer offset, Boolean reverse) throws DataException { + public List getBlockSigners(List addresses, Integer limit, Integer offset, Boolean reverse) throws DataException { String subquerySql = "SELECT minter, COUNT(signature) FROM Blocks GROUP BY minter"; StringBuilder sql = new StringBuilder(1024); @@ -245,7 +245,7 @@ public class HSQLDBBlockRepository implements BlockRepository { HSQLDBRepository.limitOffsetSql(sql, limit, offset); - List summaries = new ArrayList<>(); + List summaries = new ArrayList<>(); try (ResultSet resultSet = this.repository.checkedExecute(sql.toString(), addresses.toArray())) { if (resultSet == null) @@ -260,13 +260,13 @@ public class HSQLDBBlockRepository implements BlockRepository { String minterAccount = resultSet.getString(4); String recipientAccount = resultSet.getString(5); - BlockMinterSummary blockMinterSummary; + BlockSignerSummary blockSignerSummary; if (recipientAccount == null) - blockMinterSummary = new BlockMinterSummary(blockMinterPublicKey, nBlocks); + blockSignerSummary = new BlockSignerSummary(blockMinterPublicKey, nBlocks); else - blockMinterSummary = new BlockMinterSummary(blockMinterPublicKey, nBlocks, mintingAccountPublicKey, minterAccount, recipientAccount); + blockSignerSummary = new BlockSignerSummary(blockMinterPublicKey, nBlocks, mintingAccountPublicKey, minterAccount, recipientAccount); - summaries.add(blockMinterSummary); + summaries.add(blockSignerSummary); } while (resultSet.next()); return summaries; @@ -276,7 +276,7 @@ public class HSQLDBBlockRepository implements BlockRepository { } @Override - public List getBlockSummariesByMinter(byte[] minterPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException { + public List getBlockSummariesBySigner(byte[] signerPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException { StringBuilder sql = new StringBuilder(512); sql.append("SELECT signature, height, Blocks.minter, online_accounts_count FROM "); @@ -294,7 +294,7 @@ public class HSQLDBBlockRepository implements BlockRepository { List blockSummaries = new ArrayList<>(); - try (ResultSet resultSet = this.repository.checkedExecute(sql.toString(), minterPublicKey, minterPublicKey)) { + try (ResultSet resultSet = this.repository.checkedExecute(sql.toString(), signerPublicKey, signerPublicKey)) { if (resultSet == null) return blockSummaries; diff --git a/src/test/java/org/qortal/test/api/BlockApiTests.java b/src/test/java/org/qortal/test/api/BlockApiTests.java index 09286a01..384c9858 100644 --- a/src/test/java/org/qortal/test/api/BlockApiTests.java +++ b/src/test/java/org/qortal/test/api/BlockApiTests.java @@ -85,27 +85,27 @@ public class BlockApiTests extends ApiCommon { } @Test - public void testGetBlockMinters() throws DataException { + public void testGetBlockSigners() throws DataException { try (final Repository repository = RepositoryManager.getRepository()) { PrivateKeyAccount mintingAccount = Common.getTestAccount(repository, "alice-reward-share"); BlockUtils.mintBlock(repository); List addresses = Arrays.asList(aliceAddress, mintingAccount.getAddress(), bobAddress); - assertNotNull(this.blocksResource.getBlockMinters(Collections.emptyList(), null, null, null)); - assertNotNull(this.blocksResource.getBlockMinters(addresses, null, null, null)); - assertNotNull(this.blocksResource.getBlockMinters(Collections.emptyList(), 1, 1, true)); - assertNotNull(this.blocksResource.getBlockMinters(addresses, 1, 1, true)); + assertNotNull(this.blocksResource.getBlockSigners(Collections.emptyList(), null, null, null)); + assertNotNull(this.blocksResource.getBlockSigners(addresses, null, null, null)); + assertNotNull(this.blocksResource.getBlockSigners(Collections.emptyList(), 1, 1, true)); + assertNotNull(this.blocksResource.getBlockSigners(addresses, 1, 1, true)); } } @Test - public void testGetBlockSummariesByMinter() throws DataException { + public void testGetBlockSummariesBySigner() throws DataException { try (final Repository repository = RepositoryManager.getRepository()) { BlockUtils.mintBlock(repository); - assertNotNull(this.blocksResource.getBlockSummariesByMinter(aliceAddress, null, null, null)); - assertNotNull(this.blocksResource.getBlockSummariesByMinter(aliceAddress, 1, 1, true)); + assertNotNull(this.blocksResource.getBlockSummariesBySigner(aliceAddress, null, null, null)); + assertNotNull(this.blocksResource.getBlockSummariesBySigner(aliceAddress, 1, 1, true)); } }