Skip to content

Commit

Permalink
fix: broken test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed May 18, 2023
1 parent efc498b commit 239b26a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 45 deletions.
2 changes: 1 addition & 1 deletion components/chainhook-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
cmd.end_block - cmd.start_block + 1
);
}
DbCommand::Patch(cmd) => {
DbCommand::Patch(_cmd) => {
unimplemented!()
}
DbCommand::Migrate(cmd) => {
Expand Down
94 changes: 50 additions & 44 deletions components/chainhook-event-observer/src/observer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::hord::db::open_readwrite_hord_dbs;
use crate::hord::new_traversals_lazy_cache;
#[cfg(feature = "ordinals")]
use crate::hord::{
db::{open_readwrite_hord_db_conn, open_readwrite_hord_db_conn_rocks_db},
revert_hord_db_with_augmented_bitcoin_block, update_hord_db_and_augment_bitcoin_block,
};
use crate::indexer::bitcoin::{
Expand Down Expand Up @@ -653,51 +652,9 @@ pub async fn start_observer_commands_handler(
BlockchainEvent::BlockchainUpdatedWithHeaders(data) => {
let mut new_blocks = vec![];

#[cfg(feature = "ordinals")]
let (blocks_db, inscriptions_db_conn_rw) =
match open_readwrite_hord_dbs(&config.get_cache_path_buf(), &ctx) {
Ok(dbs) => dbs,
Err(e) => {
if let Some(ref tx) = observer_events_tx {
let _ = tx.send(ObserverEvent::Error(format!(
"Channel error: {:?}",
e
)));
} else {
ctx.try_log(|logger| {
slog::error!(
logger,
"Unable to open readwtite connection",
)
});
}
continue;
}
};

for header in data.new_headers.iter() {
match bitcoin_block_store.get_mut(&header.block_identifier) {
match bitcoin_block_store.get(&header.block_identifier) {
Some(block) => {
#[cfg(feature = "ordinals")]
{
if let Err(e) = update_hord_db_and_augment_bitcoin_block(
block,
&blocks_db,
&inscriptions_db_conn_rw,
true,
&config.get_cache_path_buf(),
&traversals_cache,
&ctx,
) {
ctx.try_log(|logger| {
slog::error!(
logger,
"Unable to insert bitcoin block {} in hord_db: {e}",
block.block_identifier.index
)
});
}
}
new_blocks.push(block.clone());
}
None => {
Expand All @@ -712,6 +669,55 @@ pub async fn start_observer_commands_handler(
}
}

#[cfg(feature = "ordinals")]
{
if config.ordinals_enabled {
let (blocks_db, inscriptions_db_conn_rw) =
match open_readwrite_hord_dbs(
&config.get_cache_path_buf(),
&ctx,
) {
Ok(dbs) => dbs,
Err(e) => {
if let Some(ref tx) = observer_events_tx {
let _ = tx.send(ObserverEvent::Error(format!(
"Channel error: {:?}",
e
)));
} else {
ctx.try_log(|logger| {
slog::error!(
logger,
"Unable to open readwtite connection",
)
});
}
continue;
}
};

for block in new_blocks.iter_mut() {
if let Err(e) = update_hord_db_and_augment_bitcoin_block(
block,
&blocks_db,
&inscriptions_db_conn_rw,
true,
&config.get_cache_path_buf(),
&traversals_cache,
&ctx,
) {
ctx.try_log(|logger| {
slog::error!(
logger,
"Unable to insert bitcoin block {} in hord_db: {e}",
block.block_identifier.index
)
});
}
}
}
};

for header in data.confirmed_headers.iter() {
match bitcoin_block_store.remove(&header.block_identifier) {
Some(block) => {
Expand Down

0 comments on commit 239b26a

Please sign in to comment.