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.
This commit is contained in:
catbref 2020-06-16 16:58:34 +01:00
parent b9d2bbb78b
commit e5e60a5032
5 changed files with 44 additions and 44 deletions

View File

@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import org.qortal.crypto.Crypto; import org.qortal.crypto.Crypto;
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
public class BlockMinterSummary { public class BlockSignerSummary {
// Properties // Properties
@ -20,19 +20,19 @@ public class BlockMinterSummary {
// Constructors // Constructors
protected BlockMinterSummary() { protected BlockSignerSummary() {
} }
/** Constructs BlockMinterSummary in non-reward-share context. */ /** Constructs BlockSignerSummary in non-reward-share context. */
public BlockMinterSummary(byte[] blockMinterPublicKey, int blockCount) { public BlockSignerSummary(byte[] blockMinterPublicKey, int blockCount) {
this.blockCount = blockCount; this.blockCount = blockCount;
this.mintingAccountPublicKey = blockMinterPublicKey; this.mintingAccountPublicKey = blockMinterPublicKey;
this.mintingAccount = Crypto.toAddress(this.mintingAccountPublicKey); this.mintingAccount = Crypto.toAddress(this.mintingAccountPublicKey);
} }
/** Constructs BlockMinterSummary in reward-share context. */ /** Constructs BlockSignerSummary in reward-share context. */
public BlockMinterSummary(byte[] rewardSharePublicKey, int blockCount, byte[] mintingAccountPublicKey, String minterAccount, String recipientAccount) { public BlockSignerSummary(byte[] rewardSharePublicKey, int blockCount, byte[] mintingAccountPublicKey, String minterAccount, String recipientAccount) {
this.rewardSharePublicKey = rewardSharePublicKey; this.rewardSharePublicKey = rewardSharePublicKey;
this.blockCount = blockCount; this.blockCount = blockCount;

View File

@ -23,7 +23,7 @@ import javax.ws.rs.core.MediaType;
import org.qortal.api.ApiError; import org.qortal.api.ApiError;
import org.qortal.api.ApiErrors; import org.qortal.api.ApiErrors;
import org.qortal.api.ApiExceptionFactory; 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.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;
@ -405,9 +405,9 @@ public class BlocksResource {
} }
@GET @GET
@Path("/minter/{address}") @Path("/signer/{address}")
@Operation( @Operation(
summary = "Fetch block summaries for blocks minted by address", summary = "Fetch block summaries for blocks signed by address",
responses = { responses = {
@ApiResponse( @ApiResponse(
description = "block summaries", description = "block summaries",
@ -422,7 +422,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<BlockSummaryData> getBlockSummariesByMinter(@PathParam("address") String address, @Parameter( public List<BlockSummaryData> getBlockSummariesBySigner(@PathParam("address") String address, @Parameter(
ref = "limit" ref = "limit"
) @QueryParam("limit") Integer limit, @Parameter( ) @QueryParam("limit") Integer limit, @Parameter(
ref = "offset" ref = "offset"
@ -438,30 +438,30 @@ 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().getBlockSummariesByMinter(accountData.getPublicKey(), limit, offset, reverse); return repository.getBlockRepository().getBlockSummariesBySigner(accountData.getPublicKey(), limit, offset, reverse);
} catch (DataException e) { } catch (DataException e) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e); throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
} }
} }
@GET @GET
@Path("/minters") @Path("/signers")
@Operation( @Operation(
summary = "Show summary of block minters", summary = "Show summary of block signers",
description = "Returns count of blocks minted, optionally limited to minters/recipients in passed address(es).", description = "Returns count of blocks signed, optionally limited to minters/recipients in passed address(es).",
responses = { responses = {
@ApiResponse( @ApiResponse(
content = @Content( content = @Content(
array = @ArraySchema( array = @ArraySchema(
schema = @Schema( schema = @Schema(
implementation = BlockMinterSummary.class implementation = BlockSignerSummary.class
) )
) )
) )
) )
} }
) )
public List<BlockMinterSummary> getBlockMinters(@QueryParam("address") List<String> addresses, public List<BlockSignerSummary> getBlockSigners(@QueryParam("address") List<String> addresses,
@Parameter( @Parameter(
ref = "limit" ref = "limit"
) @QueryParam("limit") Integer limit, @Parameter( ) @QueryParam("limit") Integer limit, @Parameter(
@ -474,7 +474,7 @@ public class BlocksResource {
if (!Crypto.isValidAddress(address)) if (!Crypto.isValidAddress(address))
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_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) { } catch (DataException e) {
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e); throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
} }

View File

@ -2,7 +2,7 @@ package org.qortal.repository;
import java.util.List; 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.BlockData;
import org.qortal.data.block.BlockSummaryData; import org.qortal.data.block.BlockSummaryData;
import org.qortal.data.block.BlockTransactionData; 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 * @param publicKey
* @return number of blocks * @return number of blocks
* @throws DataException * @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<BlockMinterSummary> getBlockMinters(List<String> addresses, Integer limit, Integer offset, Boolean reverse) throws DataException; public List<BlockSignerSummary> getBlockSigners(List<String> 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<BlockSummaryData> getBlockSummariesByMinter(byte[] minterPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException; public List<BlockSummaryData> getBlockSummariesBySigner(byte[] signerPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException;
/** /**
* Returns blocks within height range. * Returns blocks within height range.

View File

@ -6,7 +6,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; 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.BlockData;
import org.qortal.data.block.BlockSummaryData; import org.qortal.data.block.BlockSummaryData;
import org.qortal.data.block.BlockTransactionData; import org.qortal.data.block.BlockTransactionData;
@ -187,7 +187,7 @@ public class HSQLDBBlockRepository implements BlockRepository {
} }
@Override @Override
public int countMintedBlocks(byte[] minterPublicKey) throws DataException { public int countSignedBlocks(byte[] signerPublicKey) throws DataException {
String directSql = "SELECT COUNT(*) FROM Blocks WHERE minter = ?"; String directSql = "SELECT COUNT(*) FROM Blocks WHERE minter = ?";
String rewardShareSql = "SELECT COUNT(*) FROM RewardShares " String rewardShareSql = "SELECT COUNT(*) FROM RewardShares "
@ -196,13 +196,13 @@ public class HSQLDBBlockRepository implements BlockRepository {
int totalCount = 0; int totalCount = 0;
try (ResultSet resultSet = this.repository.checkedExecute(directSql, minterPublicKey)) { try (ResultSet resultSet = this.repository.checkedExecute(directSql, signerPublicKey)) {
totalCount += resultSet.getInt(1); totalCount += resultSet.getInt(1);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataException("Unable to count minted blocks in repository", 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); totalCount += resultSet.getInt(1);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataException("Unable to count reward-share minted blocks in repository", e); throw new DataException("Unable to count reward-share minted blocks in repository", e);
@ -212,7 +212,7 @@ public class HSQLDBBlockRepository implements BlockRepository {
} }
@Override @Override
public List<BlockMinterSummary> getBlockMinters(List<String> addresses, Integer limit, Integer offset, Boolean reverse) throws DataException { public List<BlockSignerSummary> getBlockSigners(List<String> addresses, Integer limit, Integer offset, Boolean reverse) throws DataException {
String subquerySql = "SELECT minter, COUNT(signature) FROM Blocks GROUP BY minter"; String subquerySql = "SELECT minter, COUNT(signature) FROM Blocks GROUP BY minter";
StringBuilder sql = new StringBuilder(1024); StringBuilder sql = new StringBuilder(1024);
@ -245,7 +245,7 @@ public class HSQLDBBlockRepository implements BlockRepository {
HSQLDBRepository.limitOffsetSql(sql, limit, offset); HSQLDBRepository.limitOffsetSql(sql, limit, offset);
List<BlockMinterSummary> summaries = new ArrayList<>(); List<BlockSignerSummary> summaries = new ArrayList<>();
try (ResultSet resultSet = this.repository.checkedExecute(sql.toString(), addresses.toArray())) { try (ResultSet resultSet = this.repository.checkedExecute(sql.toString(), addresses.toArray())) {
if (resultSet == null) if (resultSet == null)
@ -260,13 +260,13 @@ public class HSQLDBBlockRepository implements BlockRepository {
String minterAccount = resultSet.getString(4); String minterAccount = resultSet.getString(4);
String recipientAccount = resultSet.getString(5); String recipientAccount = resultSet.getString(5);
BlockMinterSummary blockMinterSummary; BlockSignerSummary blockSignerSummary;
if (recipientAccount == null) if (recipientAccount == null)
blockMinterSummary = new BlockMinterSummary(blockMinterPublicKey, nBlocks); blockSignerSummary = new BlockSignerSummary(blockMinterPublicKey, nBlocks);
else 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()); } while (resultSet.next());
return summaries; return summaries;
@ -276,7 +276,7 @@ public class HSQLDBBlockRepository implements BlockRepository {
} }
@Override @Override
public List<BlockSummaryData> getBlockSummariesByMinter(byte[] minterPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException { public List<BlockSummaryData> getBlockSummariesBySigner(byte[] signerPublicKey, Integer limit, Integer offset, Boolean reverse) throws DataException {
StringBuilder sql = new StringBuilder(512); StringBuilder sql = new StringBuilder(512);
sql.append("SELECT signature, height, Blocks.minter, online_accounts_count FROM "); sql.append("SELECT signature, height, Blocks.minter, online_accounts_count FROM ");
@ -294,7 +294,7 @@ public class HSQLDBBlockRepository implements BlockRepository {
List<BlockSummaryData> blockSummaries = new ArrayList<>(); List<BlockSummaryData> 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) if (resultSet == null)
return blockSummaries; return blockSummaries;

View File

@ -85,27 +85,27 @@ public class BlockApiTests extends ApiCommon {
} }
@Test @Test
public void testGetBlockMinters() throws DataException { public void testGetBlockSigners() throws DataException {
try (final Repository repository = RepositoryManager.getRepository()) { try (final Repository repository = RepositoryManager.getRepository()) {
PrivateKeyAccount mintingAccount = Common.getTestAccount(repository, "alice-reward-share"); PrivateKeyAccount mintingAccount = Common.getTestAccount(repository, "alice-reward-share");
BlockUtils.mintBlock(repository); BlockUtils.mintBlock(repository);
List<String> addresses = Arrays.asList(aliceAddress, mintingAccount.getAddress(), bobAddress); List<String> addresses = Arrays.asList(aliceAddress, mintingAccount.getAddress(), bobAddress);
assertNotNull(this.blocksResource.getBlockMinters(Collections.emptyList(), null, null, null)); assertNotNull(this.blocksResource.getBlockSigners(Collections.emptyList(), null, null, null));
assertNotNull(this.blocksResource.getBlockMinters(addresses, null, null, null)); assertNotNull(this.blocksResource.getBlockSigners(addresses, null, null, null));
assertNotNull(this.blocksResource.getBlockMinters(Collections.emptyList(), 1, 1, true)); assertNotNull(this.blocksResource.getBlockSigners(Collections.emptyList(), 1, 1, true));
assertNotNull(this.blocksResource.getBlockMinters(addresses, 1, 1, true)); assertNotNull(this.blocksResource.getBlockSigners(addresses, 1, 1, true));
} }
} }
@Test @Test
public void testGetBlockSummariesByMinter() throws DataException { public void testGetBlockSummariesBySigner() throws DataException {
try (final Repository repository = RepositoryManager.getRepository()) { try (final Repository repository = RepositoryManager.getRepository()) {
BlockUtils.mintBlock(repository); BlockUtils.mintBlock(repository);
assertNotNull(this.blocksResource.getBlockSummariesByMinter(aliceAddress, null, null, null)); assertNotNull(this.blocksResource.getBlockSummariesBySigner(aliceAddress, null, null, null));
assertNotNull(this.blocksResource.getBlockSummariesByMinter(aliceAddress, 1, 1, true)); assertNotNull(this.blocksResource.getBlockSummariesBySigner(aliceAddress, 1, 1, true));
} }
} }