Added exists() test to BlockRepository & HSQLDB implementation

This commit is contained in:
catbref 2019-09-26 17:22:03 +01:00
parent c00481a750
commit 40d879813d
2 changed files with 14 additions and 0 deletions

View File

@ -37,6 +37,11 @@ public interface BlockRepository {
*/
public BlockData fromHeight(int height) throws DataException;
/**
* Returns whether block exists based on passed block signature.
*/
public boolean exists(byte[] signature) throws DataException;
/**
* Return height of block in blockchain using block's signature.
*

View File

@ -88,6 +88,15 @@ public class HSQLDBBlockRepository implements BlockRepository {
}
}
@Override
public boolean exists(byte[] signature) throws DataException {
try {
return this.repository.exists("Blocks", "signature = ?", signature);
} catch (SQLException e) {
throw new DataException("Unable to check for block in repository", e);
}
}
@Override
public int getHeightFromSignature(byte[] signature) throws DataException {
try (ResultSet resultSet = this.repository.checkedExecute("SELECT height FROM Blocks WHERE signature = ? LIMIT 1", signature)) {