grab latest block directly instead of via height

This commit is contained in:
catbref 2019-04-26 15:01:57 +01:00
parent b4d0f9ab68
commit db77901026

View File

@ -59,7 +59,7 @@ public class HSQLDBBlockRepository implements BlockRepository {
try (ResultSet resultSet = this.repository.checkedExecute("SELECT " + BLOCK_DB_COLUMNS + " FROM Blocks WHERE signature = ?", signature)) { try (ResultSet resultSet = this.repository.checkedExecute("SELECT " + BLOCK_DB_COLUMNS + " FROM Blocks WHERE signature = ?", signature)) {
return getBlockFromResultSet(resultSet); return getBlockFromResultSet(resultSet);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataException("Error loading data from DB", e); throw new DataException("Error fetching block by signature from repository", e);
} }
} }
@ -68,7 +68,7 @@ public class HSQLDBBlockRepository implements BlockRepository {
try (ResultSet resultSet = this.repository.checkedExecute("SELECT " + BLOCK_DB_COLUMNS + " FROM Blocks WHERE reference = ?", reference)) { try (ResultSet resultSet = this.repository.checkedExecute("SELECT " + BLOCK_DB_COLUMNS + " FROM Blocks WHERE reference = ?", reference)) {
return getBlockFromResultSet(resultSet); return getBlockFromResultSet(resultSet);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataException("Error loading data from DB", e); throw new DataException("Error fetching block by reference from repository", e);
} }
} }
@ -77,7 +77,7 @@ public class HSQLDBBlockRepository implements BlockRepository {
try (ResultSet resultSet = this.repository.checkedExecute("SELECT " + BLOCK_DB_COLUMNS + " FROM Blocks WHERE height = ?", height)) { try (ResultSet resultSet = this.repository.checkedExecute("SELECT " + BLOCK_DB_COLUMNS + " FROM Blocks WHERE height = ?", height)) {
return getBlockFromResultSet(resultSet); return getBlockFromResultSet(resultSet);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataException("Error loading data from DB", e); throw new DataException("Error fetching block by height from repository", e);
} }
} }
@ -89,7 +89,7 @@ public class HSQLDBBlockRepository implements BlockRepository {
return resultSet.getInt(1); return resultSet.getInt(1);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataException("Error obtaining block height from repository", e); throw new DataException("Error obtaining block height by signature from repository", e);
} }
} }
@ -103,7 +103,7 @@ public class HSQLDBBlockRepository implements BlockRepository {
return resultSet.getInt(1); return resultSet.getInt(1);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataException("Error obtaining block height from repository", e); throw new DataException("Error obtaining block height by timestamp from repository", e);
} }
} }
@ -121,7 +121,11 @@ public class HSQLDBBlockRepository implements BlockRepository {
@Override @Override
public BlockData getLastBlock() throws DataException { public BlockData getLastBlock() throws DataException {
return fromHeight(getBlockchainHeight()); try (ResultSet resultSet = this.repository.checkedExecute("SELECT " + BLOCK_DB_COLUMNS + " FROM Blocks ORDER BY height DESC LIMIT 1")) {
return getBlockFromResultSet(resultSet);
} catch (SQLException e) {
throw new DataException("Error fetching last block from repository", e);
}
} }
@Override @Override