Include proxy-forged blocks in BlockRepository.countForgedBlocks.

As used during validity check for ENABLE_FORGING transaction.
This commit is contained in:
catbref 2019-05-20 12:24:09 +01:00
parent ae6b41a893
commit 7409c024f6
2 changed files with 6 additions and 2 deletions

View File

@ -94,7 +94,7 @@ public interface BlockRepository {
}
/**
* Returns number of blocks forged by account with given public key.
* Returns number of blocks forged by account with given public key, including proxy-forged blocks.
*
* @param publicKey
* @return number of blocks

View File

@ -156,7 +156,11 @@ public class HSQLDBBlockRepository implements BlockRepository {
@Override
public int countForgedBlocks(byte[] publicKey) throws DataException {
try (ResultSet resultSet = this.repository.checkedExecute("SELECT COUNT(*) FROM Blocks WHERE generator = ? LIMIT 1", publicKey)) {
String subquerySql = "SELECT proxy_public_key FROM ProxyForgers WHERE forger = ?";
String sql = "SELECT COUNT(*) FROM Blocks WHERE generator IN (?, (" + subquerySql + ")) LIMIT 1";
try (ResultSet resultSet = this.repository.checkedExecute(sql, publicKey, publicKey)) {
return resultSet.getInt(1);
} catch (SQLException e) {
throw new DataException("Unable to fetch forged blocks count from repository", e);