Skip to content

Commit 55e293b

Browse files
author
Ludo Galabru
committed
fix: db init command
1 parent ff957ea commit 55e293b

File tree

2 files changed

+11
-5
lines changed
  • components
    • chainhook-cli/src/cli
    • chainhook-event-observer/src/hord/db

2 files changed

+11
-5
lines changed

components/chainhook-cli/src/cli/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use chainhook_event_observer::chainhooks::types::{
1414
};
1515
use chainhook_event_observer::hord::db::{
1616
delete_data_in_hord_db, fetch_and_cache_blocks_in_hord_db,
17-
find_inscriptions_at_wached_outpoint, find_latest_compacted_block_known,
17+
find_inscriptions_at_wached_outpoint, find_latest_compacted_block_known, initialize_hord_db,
1818
open_readonly_hord_db_conn, open_readwrite_hord_db_conn,
1919
retrieve_satoshi_point_using_local_storage,
2020
};
@@ -534,6 +534,8 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
534534
}
535535
};
536536

537+
let _ = initialize_hord_db(&config.expected_cache_path(), &ctx);
538+
537539
perform_hord_db_update(0, end_block, cmd.network_threads, &config, &ctx).await?;
538540
}
539541
DbCommand::Update(cmd) => {

components/chainhook-event-observer/src/hord/db/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,14 @@ impl CompactedBlock {
247247

248248
pub fn find_latest_compacted_block_known(hord_db_conn: &Connection) -> u32 {
249249
let args: &[&dyn ToSql] = &[];
250-
let mut stmt = hord_db_conn
251-
.prepare("SELECT id FROM blocks ORDER BY id DESC LIMIT 1")
252-
.unwrap();
253-
let mut rows = stmt.query(args).unwrap();
250+
let mut stmt = match hord_db_conn.prepare("SELECT id FROM blocks ORDER BY id DESC LIMIT 1") {
251+
Ok(stmt) => stmt,
252+
Err(_) => return 0,
253+
};
254+
let mut rows = match stmt.query(args) {
255+
Ok(rows) => rows,
256+
Err(_) => return 0,
257+
};
254258
while let Ok(Some(row)) = rows.next() {
255259
let id: u32 = row.get(0).unwrap();
256260
return id;

0 commit comments

Comments
 (0)