Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions components/chainhook-cli/src/storage/database_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use chainhook_sdk::types::BlockIdentifier;
use chainhook_sdk::utils::Context;
use std::path::PathBuf;

use crate::storage::{is_stacks_block_present, open_readonly_stacks_db_conn_with_retry};
use crate::storage::{get_stacks_block_at_block_height, open_readonly_stacks_db_conn_with_retry};

/// Implementation of DatabaseAccess trait for chainhook-cli
/// This provides database access to the SDK without creating circular dependencies
Expand All @@ -24,6 +24,15 @@ impl BlocksDatabaseAccess for StacksDatabaseAccess {
ctx: &Context,
) -> Result<bool, String> {
let stacks_db = open_readonly_stacks_db_conn_with_retry(&self.db_path, 0, ctx)?;
Ok(is_stacks_block_present(block_identifier, 0, &stacks_db))
// We have to retrieve the full block to check and compare both its hash and index. There's a function called
// `is_stacks_block_present` that sounds like could be used here but it only checks the index.
if let Some(block) =
get_stacks_block_at_block_height(block_identifier.index, true, 0, &stacks_db)?
{
if block.block_identifier.hash == block_identifier.hash {
return Ok(true);
}
}
return Ok(false);
}
}
Loading