fix: db init command

This commit is contained in:
Ludo Galabru
2023-03-31 08:27:31 -07:00
parent ff957ea644
commit 55e293b3ca
2 changed files with 11 additions and 5 deletions

View File

@@ -14,7 +14,7 @@ use chainhook_event_observer::chainhooks::types::{
};
use chainhook_event_observer::hord::db::{
delete_data_in_hord_db, fetch_and_cache_blocks_in_hord_db,
find_inscriptions_at_wached_outpoint, find_latest_compacted_block_known,
find_inscriptions_at_wached_outpoint, find_latest_compacted_block_known, initialize_hord_db,
open_readonly_hord_db_conn, open_readwrite_hord_db_conn,
retrieve_satoshi_point_using_local_storage,
};
@@ -534,6 +534,8 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
}
};
let _ = initialize_hord_db(&config.expected_cache_path(), &ctx);
perform_hord_db_update(0, end_block, cmd.network_threads, &config, &ctx).await?;
}
DbCommand::Update(cmd) => {

View File

@@ -247,10 +247,14 @@ impl CompactedBlock {
pub fn find_latest_compacted_block_known(hord_db_conn: &Connection) -> u32 {
let args: &[&dyn ToSql] = &[];
let mut stmt = hord_db_conn
.prepare("SELECT id FROM blocks ORDER BY id DESC LIMIT 1")
.unwrap();
let mut rows = stmt.query(args).unwrap();
let mut stmt = match hord_db_conn.prepare("SELECT id FROM blocks ORDER BY id DESC LIMIT 1") {
Ok(stmt) => stmt,
Err(_) => return 0,
};
let mut rows = match stmt.query(args) {
Ok(rows) => rows,
Err(_) => return 0,
};
while let Ok(Some(row)) = rows.next() {
let id: u32 = row.get(0).unwrap();
return id;