Browse Source

Added exists() test to BlockRepository & HSQLDB implementation

split-DB
catbref 5 years ago
parent
commit
40d879813d
  1. 5
      src/main/java/org/qora/repository/BlockRepository.java
  2. 9
      src/main/java/org/qora/repository/hsqldb/HSQLDBBlockRepository.java

5
src/main/java/org/qora/repository/BlockRepository.java

@ -37,6 +37,11 @@ public interface BlockRepository {
*/ */
public BlockData fromHeight(int height) throws DataException; 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. * Return height of block in blockchain using block's signature.
* *

9
src/main/java/org/qora/repository/hsqldb/HSQLDBBlockRepository.java

@ -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 @Override
public int getHeightFromSignature(byte[] signature) throws DataException { public int getHeightFromSignature(byte[] signature) throws DataException {
try (ResultSet resultSet = this.repository.checkedExecute("SELECT height FROM Blocks WHERE signature = ? LIMIT 1", signature)) { try (ResultSet resultSet = this.repository.checkedExecute("SELECT height FROM Blocks WHERE signature = ? LIMIT 1", signature)) {

Loading…
Cancel
Save