Skip to content

Commit 1a9eddb

Browse files
author
Ludo Galabru
committed
feat: always try to initialize tables when starting service
1 parent 3e15da5 commit 1a9eddb

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
441441
if cmd.predicates_paths.len() > 0 && !cmd.start_http_api {
442442
config.http_api = PredicatesApi::Off;
443443
}
444+
445+
let _ = initialize_hord_db(&config.expected_cache_path(), &ctx);
446+
444447
let predicates = cmd
445448
.predicates_paths
446449
.iter()

components/chainhook-sdk/src/hord/db/mod.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -68,36 +68,36 @@ pub fn initialize_hord_db(path: &PathBuf, ctx: &Context) -> Connection {
6868
)",
6969
[],
7070
) {
71-
ctx.try_log(|logger| slog::error!(logger, "{}", e.to_string()));
72-
}
73-
if let Err(e) = conn.execute(
74-
"CREATE TABLE IF NOT EXISTS transfers (
75-
block_height INTEGER NOT NULL PRIMARY KEY
76-
)",
77-
[],
78-
) {
79-
ctx.try_log(|logger| slog::error!(logger, "{}", e.to_string()));
80-
}
71+
ctx.try_log(|logger| slog::warn!(logger, "{}", e.to_string()));
72+
} else {
73+
if let Err(e) = conn.execute(
74+
"CREATE TABLE IF NOT EXISTS transfers (
75+
block_height INTEGER NOT NULL PRIMARY KEY
76+
)",
77+
[],
78+
) {
79+
ctx.try_log(|logger| slog::warn!(logger, "{}", e.to_string()));
80+
}
8181

82-
if let Err(e) = conn.execute(
83-
"CREATE INDEX IF NOT EXISTS index_inscriptions_on_outpoint_to_watch ON inscriptions(outpoint_to_watch);",
84-
[],
85-
) {
86-
ctx.try_log(|logger| slog::error!(logger, "{}", e.to_string()));
87-
}
88-
if let Err(e) = conn.execute(
89-
"CREATE INDEX IF NOT EXISTS index_inscriptions_on_ordinal_number ON inscriptions(ordinal_number);",
90-
[],
91-
) {
92-
ctx.try_log(|logger| slog::error!(logger, "{}", e.to_string()));
93-
}
94-
if let Err(e) = conn.execute(
95-
"CREATE INDEX IF NOT EXISTS index_inscriptions_on_block_height ON inscriptions(block_height);",
96-
[],
97-
) {
98-
ctx.try_log(|logger| slog::error!(logger, "{}", e.to_string()));
82+
if let Err(e) = conn.execute(
83+
"CREATE INDEX IF NOT EXISTS index_inscriptions_on_outpoint_to_watch ON inscriptions(outpoint_to_watch);",
84+
[],
85+
) {
86+
ctx.try_log(|logger| slog::warn!(logger, "{}", e.to_string()));
87+
}
88+
if let Err(e) = conn.execute(
89+
"CREATE INDEX IF NOT EXISTS index_inscriptions_on_ordinal_number ON inscriptions(ordinal_number);",
90+
[],
91+
) {
92+
ctx.try_log(|logger| slog::warn!(logger, "{}", e.to_string()));
93+
}
94+
if let Err(e) = conn.execute(
95+
"CREATE INDEX IF NOT EXISTS index_inscriptions_on_block_height ON inscriptions(block_height);",
96+
[],
97+
) {
98+
ctx.try_log(|logger| slog::warn!(logger, "{}", e.to_string()));
99+
}
99100
}
100-
101101
conn
102102
}
103103

components/chainhook-sdk/src/hord/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ use crate::{
4141

4242
use self::db::{
4343
find_inscription_with_id, find_latest_cursed_inscription_number_at_block_height,
44-
find_latest_inscription_number_at_block_height,
45-
parse_satpoint_to_watch, remove_entry_from_blocks,
46-
remove_entry_from_inscriptions, LazyBlock, LazyBlockTransaction, TraversalResult,
47-
WatchedSatpoint,
44+
find_latest_inscription_number_at_block_height, parse_satpoint_to_watch,
45+
remove_entry_from_blocks, remove_entry_from_inscriptions, LazyBlock, LazyBlockTransaction,
46+
TraversalResult, WatchedSatpoint,
4847
};
4948
use self::inscription::InscriptionParser;
5049
use self::ord::inscription_id::InscriptionId;

0 commit comments

Comments
 (0)