fix: build errors

This commit is contained in:
Ludo Galabru
2023-07-19 20:29:02 -04:00
parent f052e08469
commit 60cd4d0c61
3 changed files with 33 additions and 12 deletions

View File

@@ -7,7 +7,7 @@ use crate::db::{
delete_data_in_hord_db, find_all_inscription_transfers, find_all_inscriptions_in_block,
find_all_transfers_in_block, find_inscription_with_id, find_last_block_inserted,
find_latest_inscription_block_height, find_lazy_block_at_block_height,
find_watched_satpoint_for_inscription, initialize_hord_db, insert_entry_in_locations,
initialize_hord_db, insert_entry_in_locations,
open_readonly_hord_db_conn, open_readonly_hord_db_conn_rocks_db, open_readwrite_hord_db_conn,
open_readwrite_hord_db_conn_rocks_db, rebuild_rocks_db,
remove_entries_from_locations_at_block_height, retrieve_satoshi_point_using_lazy_storage,
@@ -23,13 +23,14 @@ use chainhook_sdk::chainhooks::types::{
ChainhookFullSpecification, HookAction, OrdinalOperations,
};
use chainhook_sdk::indexer::bitcoin::{
download_and_parse_block_with_retry, retrieve_block_hash_with_retry,
build_http_client, download_and_parse_block_with_retry, retrieve_block_hash_with_retry,
};
use chainhook_sdk::observer::BitcoinConfig;
use chainhook_sdk::types::{BitcoinBlockData, BlockIdentifier, TransactionIdentifier};
use chainhook_sdk::utils::Context;
use clap::{Parser, Subcommand};
use hiro_system_kit;
use reqwest::Client as HttpClient;
use std::collections::BTreeMap;
use std::io::{BufReader, Read};
use std::path::PathBuf;
@@ -654,9 +655,14 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
let event_observer_config = config.get_event_observer_config();
let hord_config = config.get_hord_config();
let bitcoin_config = event_observer_config.get_bitcoin_config();
let block =
fetch_and_standardize_block(cmd.block_height, &bitcoin_config, &ctx)
.await?;
let http_client: HttpClient = build_http_client();
let block = fetch_and_standardize_block(
&http_client,
cmd.block_height,
&bitcoin_config,
&ctx,
)
.await?;
let traversals_cache = Arc::new(new_traversals_lazy_cache(1024));
let _traversals = retrieve_inscribed_satoshi_points_from_block(
@@ -782,12 +788,18 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
};
let (tx, rx) = channel();
let moved_ctx = ctx.clone();
let http_client = build_http_client();
hiro_system_kit::thread_named("Block fetch")
.spawn(move || {
for cursor in cmd.start_block..=cmd.end_block {
println!("Fetching block {}", cursor);
let future =
fetch_and_standardize_block(cursor, &bitcoin_config, &moved_ctx);
let future = fetch_and_standardize_block(
&http_client,
cursor,
&bitcoin_config,
&moved_ctx,
);
let block = hiro_system_kit::nestable_block_on(future).unwrap();
@@ -901,13 +913,16 @@ pub fn load_predicate_from_path(
}
pub async fn fetch_and_standardize_block(
http_client: &HttpClient,
block_height: u64,
bitcoin_config: &BitcoinConfig,
ctx: &Context,
) -> Result<BitcoinBlockData, String> {
let block_hash = retrieve_block_hash_with_retry(&block_height, &bitcoin_config, &ctx).await?;
let block_hash =
retrieve_block_hash_with_retry(http_client, &block_height, &bitcoin_config, &ctx).await?;
let block_breakdown =
download_and_parse_block_with_retry(&block_hash, &bitcoin_config, &ctx).await?;
download_and_parse_block_with_retry(http_client, &block_hash, &bitcoin_config, &ctx)
.await?;
hord::parse_ordinals_and_standardize_block(block_breakdown, &bitcoin_config.network, &ctx)
.map_err(|(e, _)| e)

View File

@@ -4,12 +4,11 @@ use std::{
hash::BuildHasherDefault,
path::PathBuf,
sync::{mpsc::Sender, Arc},
time::Duration,
};
use chainhook_sdk::{
indexer::bitcoin::{
build_http_client, download_block_with_retry, parse_downloaded_block,
build_http_client, download_block_with_retry,
retrieve_block_hash_with_retry,
},
types::{

View File

@@ -24,6 +24,7 @@ use chainhook_sdk::chainhooks::types::{
ChainhookSpecification,
};
use chainhook_sdk::indexer::bitcoin::build_http_client;
use chainhook_sdk::observer::{start_event_observer, BitcoinConfig, ObserverEvent};
use chainhook_sdk::types::{
BitcoinBlockData, BitcoinChainEvent, BitcoinNetwork, OrdinalInscriptionTransferData,
@@ -435,9 +436,15 @@ impl Service {
let moved_ctx = self.ctx.clone();
hiro_system_kit::thread_named("Block fetch")
.spawn(move || {
let http_client = build_http_client();
for cursor in start_block..=end_block {
info!(moved_ctx.expect_logger(), "Fetching block {}", cursor);
let future = fetch_and_standardize_block(cursor, &bitcoin_config, &moved_ctx);
let future = fetch_and_standardize_block(
&http_client,
cursor,
&bitcoin_config,
&moved_ctx,
);
let block = hiro_system_kit::nestable_block_on(future).unwrap();