forked from Qortal/qortal
Added exists() test to BlockRepository & HSQLDB implementation
This commit is contained in:
parent
c00481a750
commit
40d879813d
@ -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.
|
||||||
*
|
*
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user