Skip to content

Commit

Permalink
feat: always try to initialize tables when starting service
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed Jun 21, 2023
1 parent 3e15da5 commit 1a9eddb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
3 changes: 3 additions & 0 deletions components/chainhook-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
if cmd.predicates_paths.len() > 0 && !cmd.start_http_api {
config.http_api = PredicatesApi::Off;
}

let _ = initialize_hord_db(&config.expected_cache_path(), &ctx);

let predicates = cmd
.predicates_paths
.iter()
Expand Down
56 changes: 28 additions & 28 deletions components/chainhook-sdk/src/hord/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,36 @@ pub fn initialize_hord_db(path: &PathBuf, ctx: &Context) -> Connection {
)",
[],
) {
ctx.try_log(|logger| slog::error!(logger, "{}", e.to_string()));
}
if let Err(e) = conn.execute(
"CREATE TABLE IF NOT EXISTS transfers (
block_height INTEGER NOT NULL PRIMARY KEY
)",
[],
) {
ctx.try_log(|logger| slog::error!(logger, "{}", e.to_string()));
}
ctx.try_log(|logger| slog::warn!(logger, "{}", e.to_string()));
} else {
if let Err(e) = conn.execute(
"CREATE TABLE IF NOT EXISTS transfers (
block_height INTEGER NOT NULL PRIMARY KEY
)",
[],
) {
ctx.try_log(|logger| slog::warn!(logger, "{}", e.to_string()));
}

if let Err(e) = conn.execute(
"CREATE INDEX IF NOT EXISTS index_inscriptions_on_outpoint_to_watch ON inscriptions(outpoint_to_watch);",
[],
) {
ctx.try_log(|logger| slog::error!(logger, "{}", e.to_string()));
}
if let Err(e) = conn.execute(
"CREATE INDEX IF NOT EXISTS index_inscriptions_on_ordinal_number ON inscriptions(ordinal_number);",
[],
) {
ctx.try_log(|logger| slog::error!(logger, "{}", e.to_string()));
}
if let Err(e) = conn.execute(
"CREATE INDEX IF NOT EXISTS index_inscriptions_on_block_height ON inscriptions(block_height);",
[],
) {
ctx.try_log(|logger| slog::error!(logger, "{}", e.to_string()));
if let Err(e) = conn.execute(
"CREATE INDEX IF NOT EXISTS index_inscriptions_on_outpoint_to_watch ON inscriptions(outpoint_to_watch);",
[],
) {
ctx.try_log(|logger| slog::warn!(logger, "{}", e.to_string()));
}
if let Err(e) = conn.execute(
"CREATE INDEX IF NOT EXISTS index_inscriptions_on_ordinal_number ON inscriptions(ordinal_number);",
[],
) {
ctx.try_log(|logger| slog::warn!(logger, "{}", e.to_string()));
}
if let Err(e) = conn.execute(
"CREATE INDEX IF NOT EXISTS index_inscriptions_on_block_height ON inscriptions(block_height);",
[],
) {
ctx.try_log(|logger| slog::warn!(logger, "{}", e.to_string()));
}
}

conn
}

Expand Down
7 changes: 3 additions & 4 deletions components/chainhook-sdk/src/hord/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ use crate::{

use self::db::{
find_inscription_with_id, find_latest_cursed_inscription_number_at_block_height,
find_latest_inscription_number_at_block_height,
parse_satpoint_to_watch, remove_entry_from_blocks,
remove_entry_from_inscriptions, LazyBlock, LazyBlockTransaction, TraversalResult,
WatchedSatpoint,
find_latest_inscription_number_at_block_height, parse_satpoint_to_watch,
remove_entry_from_blocks, remove_entry_from_inscriptions, LazyBlock, LazyBlockTransaction,
TraversalResult, WatchedSatpoint,
};
use self::inscription::InscriptionParser;
use self::ord::inscription_id::InscriptionId;
Expand Down

0 comments on commit 1a9eddb

Please sign in to comment.