diff --git a/components/hord-cli/src/cli/mod.rs b/components/hord-cli/src/cli/mod.rs index dbc38cd2..ea57f07f 100644 --- a/components/hord-cli/src/cli/mod.rs +++ b/components/hord-cli/src/cli/mod.rs @@ -9,11 +9,10 @@ use crate::db::{ open_readwrite_hord_db_conn_rocks_db, retrieve_satoshi_point_using_lazy_storage, }; use crate::hord::{ - new_traversals_lazy_cache, retrieve_inscribed_satoshi_points_from_block, + self, new_traversals_lazy_cache, retrieve_inscribed_satoshi_points_from_block, update_storage_and_augment_bitcoin_block_with_inscription_transfer_data, Storage, }; use chainhook_sdk::chainhooks::types::ChainhookFullSpecification; -use chainhook_sdk::indexer; use chainhook_sdk::indexer::bitcoin::{ download_and_parse_block_with_retry, retrieve_block_hash_with_retry, }; @@ -355,7 +354,7 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> { find_last_block_inserted(&hord_db_conn) as u64 }; if cmd.block_height > tip_height { - crate::hord::perform_hord_db_update( + hord::perform_hord_db_update( tip_height, cmd.block_height, &config.get_hord_config(), @@ -427,7 +426,7 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> { let tip_height = find_last_block_inserted(&blocks_db_conn) as u64; let _end_at = match cmd.block_height { Some(block_height) if block_height > tip_height => { - crate::hord::perform_hord_db_update( + hord::perform_hord_db_update( tip_height, block_height, &config.get_hord_config(), @@ -481,8 +480,7 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> { } Command::Db(HordDbCommand::Sync(cmd)) => { let config = Config::default(false, false, false, &cmd.config_path)?; - if let Some((start_block, end_block)) = crate::hord::should_sync_hord_db(&config, &ctx)? - { + if let Some((start_block, end_block)) = hord::should_sync_hord_db(&config, &ctx)? { if start_block == 0 { info!( ctx.expect_logger(), @@ -494,7 +492,7 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> { "Resuming hord indexing from block #{}", start_block ); } - crate::hord::perform_hord_db_update( + hord::perform_hord_db_update( start_block, end_block, &config.get_hord_config(), @@ -525,7 +523,7 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> { )?; } // Update data - crate::hord::perform_hord_db_update( + hord::perform_hord_db_update( cmd.start_block, cmd.end_block, &config.get_hord_config(), @@ -605,6 +603,6 @@ pub async fn fetch_and_standardize_block( let block_breakdown = download_and_parse_block_with_retry(&block_hash, &bitcoin_config, &ctx).await?; - indexer::bitcoin::standardize_bitcoin_block(block_breakdown, &bitcoin_config.network, &ctx) + hord::parse_ordinals_and_standardize_block(block_breakdown, &bitcoin_config.network, &ctx) .map_err(|(e, _)| e) } diff --git a/components/hord-cli/src/db/mod.rs b/components/hord-cli/src/db/mod.rs index 9c4c5a62..2316e714 100644 --- a/components/hord-cli/src/db/mod.rs +++ b/components/hord-cli/src/db/mod.rs @@ -22,14 +22,13 @@ use threadpool::ThreadPool; use chainhook_sdk::{ indexer::bitcoin::{ - download_block_with_retry, retrieve_block_hash_with_retry, standardize_bitcoin_block, - BitcoinBlockFullBreakdown, + download_block_with_retry, retrieve_block_hash_with_retry, BitcoinBlockFullBreakdown, }, observer::BitcoinConfig, utils::Context, }; -use crate::hord::HordConfig; +use crate::hord::{self, HordConfig}; use crate::hord::{new_traversals_lazy_cache, update_hord_db_and_augment_bitcoin_block}; use crate::ord::{height::Height, sat::Sat}; @@ -979,19 +978,21 @@ pub async fn fetch_and_cache_blocks_in_hord_db( inbox.len() ) }); - let mut new_block = - match standardize_bitcoin_block(next_block, &bitcoin_network, &ctx) { - Ok(block) => block, - Err((e, _)) => { - ctx.try_log(|logger| { - slog::error!(logger, "Unable to standardize bitcoin block: {e}",) - }); - return Err(e); - } - }; + let mut new_block = match hord::parse_ordinals_and_standardize_block( + next_block, + &bitcoin_network, + &ctx, + ) { + Ok(block) => block, + Err((e, _)) => { + ctx.try_log(|logger| { + slog::error!(logger, "Unable to standardize bitcoin block: {e}",) + }); + return Err(e); + } + }; let _ = blocks_db_rw.flush(); - if let Err(e) = update_hord_db_and_augment_bitcoin_block( &mut new_block, blocks_db_rw, diff --git a/components/hord-cli/src/hord/mod.rs b/components/hord-cli/src/hord/mod.rs index 70baa949..591f0304 100644 --- a/components/hord-cli/src/hord/mod.rs +++ b/components/hord-cli/src/hord/mod.rs @@ -41,7 +41,9 @@ use crate::ord::height::Height; use crate::config::Config; use crate::db::format_outpoint_to_watch; -use chainhook_sdk::indexer::bitcoin::BitcoinTransactionFullBreakdown; +use chainhook_sdk::indexer::bitcoin::{ + standardize_bitcoin_block, BitcoinBlockFullBreakdown, BitcoinTransactionFullBreakdown, +}; use crate::db::{ fetch_and_cache_blocks_in_hord_db, find_last_block_inserted, @@ -54,9 +56,9 @@ use self::inscription::InscriptionParser; use crate::db::{ find_inscription_with_id, find_latest_cursed_inscription_number_at_block_height, find_latest_inscription_number_at_block_height, format_satpoint_to_watch, - insert_transfer_in_locations, parse_outpoint_to_watch, parse_satpoint_to_watch, - remove_entry_from_blocks, remove_entry_from_inscriptions, LazyBlock, LazyBlockTransaction, - TraversalResult, WatchedSatpoint, + insert_transfer_in_locations, parse_satpoint_to_watch, remove_entry_from_blocks, + remove_entry_from_inscriptions, LazyBlock, LazyBlockTransaction, TraversalResult, + WatchedSatpoint, }; use crate::ord::inscription_id::InscriptionId; @@ -69,6 +71,29 @@ pub struct HordConfig { pub first_inscription_height: u64, } +pub fn parse_ordinals_and_standardize_block( + raw_block: BitcoinBlockFullBreakdown, + network: &BitcoinNetwork, + ctx: &Context, +) -> Result { + let mut ordinal_operations = BTreeMap::new(); + + for tx in raw_block.tx.iter() { + ordinal_operations.insert(tx.txid.to_string(), parse_ordinal_operations(&tx, ctx)); + } + + let mut block = standardize_bitcoin_block(raw_block, network, ctx)?; + + for tx in block.transactions.iter_mut() { + if let Some(ordinal_operations) = + ordinal_operations.remove(tx.transaction_identifier.get_hash_bytes_str()) + { + tx.metadata.ordinal_operations = ordinal_operations; + } + } + Ok(block) +} + pub fn parse_ordinal_operations( tx: &BitcoinTransactionFullBreakdown, _ctx: &Context, diff --git a/components/hord-cli/src/scan/bitcoin.rs b/components/hord-cli/src/scan/bitcoin.rs index 6dbb09d8..196ddde6 100644 --- a/components/hord-cli/src/scan/bitcoin.rs +++ b/components/hord-cli/src/scan/bitcoin.rs @@ -4,7 +4,7 @@ use crate::db::{ find_all_inscriptions_in_block, get_any_entry_in_ordinal_activities, open_readonly_hord_db_conn, }; use crate::hord::{ - get_inscriptions_revealed_in_block, + self, get_inscriptions_revealed_in_block, update_storage_and_augment_bitcoin_block_with_inscription_reveal_data, update_storage_and_augment_bitcoin_block_with_inscription_transfer_data, Storage, }; @@ -19,7 +19,6 @@ use chainhook_sdk::chainhooks::bitcoin::{ BitcoinChainhookOccurrence, BitcoinTriggerChainhook, }; use chainhook_sdk::chainhooks::types::{BitcoinChainhookSpecification, BitcoinPredicateType}; -use chainhook_sdk::indexer; use chainhook_sdk::indexer::bitcoin::{ download_and_parse_block_with_retry, retrieve_block_hash_with_retry, }; @@ -111,7 +110,7 @@ pub async fn scan_bitcoin_chainstate_via_rpc_using_predicate( let block_hash = retrieve_block_hash_with_retry(&cursor, &bitcoin_config, ctx).await?; let block_breakdown = download_and_parse_block_with_retry(&block_hash, &bitcoin_config, ctx).await?; - let mut block = match indexer::bitcoin::standardize_bitcoin_block( + let mut block = match hord::parse_ordinals_and_standardize_block( block_breakdown, &event_observer_config.bitcoin_network, ctx,