@@ -31,7 +31,7 @@ use chainhook_event_observer::observer::{
31
31
use chainhook_event_observer:: redb:: ReadableTable ;
32
32
use chainhook_event_observer:: utils:: { file_append, send_request, Context } ;
33
33
use chainhook_types:: {
34
- BitcoinTransactionData , OrdinalInscriptionRevealData , OrdinalOperation , TransactionIdentifier ,
34
+ BitcoinTransactionData , OrdinalInscriptionRevealData , OrdinalOperation , TransactionIdentifier , BlockIdentifier ,
35
35
} ;
36
36
use reqwest:: Client as HttpClient ;
37
37
use rusqlite:: { Connection , OpenFlags , Result , ToSql } ;
@@ -43,14 +43,15 @@ use std::time::Duration;
43
43
44
44
pub fn initialize_bitcoin_block_traversal_cache ( path : & PathBuf ) -> Connection {
45
45
let conn = create_or_open_readwrite_db ( path) ;
46
- conn. execute (
46
+ if let Err ( e ) = conn. execute (
47
47
"CREATE TABLE blocks (
48
48
id INTEGER NOT NULL PRIMARY KEY,
49
49
compacted_bytes TEXT NOT NULL
50
50
)" ,
51
51
[ ] ,
52
- )
53
- . unwrap ( ) ;
52
+ ) {
53
+ println ! ( "Error: {}" , e. to_string( ) ) ;
54
+ }
54
55
conn
55
56
}
56
57
@@ -189,12 +190,14 @@ pub fn write_compacted_block_to_index(
189
190
storage_conn : & Connection ,
190
191
) {
191
192
let serialized_compacted_block = compacted_block. to_hex_bytes ( ) ;
192
- storage_conn
193
- . execute (
194
- "INSERT INTO blocks (id, compacted_bytes) VALUES (?1, ?2)" ,
195
- rusqlite:: params![ & block_id, & serialized_compacted_block] ,
196
- )
197
- . unwrap ( ) ;
193
+
194
+ if let Err ( e) = storage_conn
195
+ . execute (
196
+ "INSERT INTO blocks (id, compacted_bytes) VALUES (?1, ?2)" ,
197
+ rusqlite:: params![ & block_id, & serialized_compacted_block] ,
198
+ ) {
199
+ println ! ( "Error: {}" , e. to_string( ) ) ;
200
+ }
198
201
}
199
202
200
203
pub async fn scan_bitcoin_chain_with_predicate (
@@ -341,17 +344,16 @@ pub async fn scan_bitcoin_chain_with_predicate(
341
344
let mut total_hits = vec ! [ ] ;
342
345
343
346
let ( retrieve_ordinal_tx, retrieve_ordinal_rx) =
344
- channel :: < std:: option:: Option < ( ( BitcoinTransactionData , Vec < HookAction > ) ) > > ( ) ;
347
+ channel :: < std:: option:: Option < ( BlockIdentifier , BitcoinTransactionData , Vec < HookAction > ) > > ( ) ;
345
348
let ( process_ordinal_tx, process_ordinal_rx) = channel ( ) ;
346
349
let ( cache_block_tx, cache_block_rx) = channel ( ) ;
347
350
348
351
let _config = config. clone ( ) ;
349
352
let handle_1 = hiro_system_kit:: thread_named ( "Ordinal retrieval" )
350
353
. spawn ( move || {
351
- while let Ok ( Some ( ( mut transaction, actions) ) ) = retrieve_ordinal_rx. recv ( ) {
352
- let txid = & transaction. transaction_identifier . hash [ 2 ..] ;
353
- println ! ( "Retrieving satoshi point for {txid}" ) ;
354
- let f = retrieve_satoshi_point_using_bitcoin_rpc ( & _config, & txid, 0 ) ;
354
+ while let Ok ( Some ( ( block_identifier, mut transaction, actions) ) ) = retrieve_ordinal_rx. recv ( ) {
355
+ println ! ( "Retrieving satoshi point for {}" , transaction. transaction_identifier. hash) ;
356
+ let f = retrieve_satoshi_point_using_local_storage ( & _config, & block_identifier, & transaction. transaction_identifier ) ;
355
357
let ( block_number, block_offset) = match hiro_system_kit:: nestable_block_on ( f) {
356
358
Ok ( res) => res,
357
359
Err ( err) => {
@@ -461,7 +463,7 @@ pub async fn scan_bitcoin_chain_with_predicate(
461
463
if is_scanning_inscriptions {
462
464
pipeline_started = true ;
463
465
let _ = retrieve_ordinal_tx
464
- . send ( Some ( ( tx. clone ( ) , vec ! [ predicate_spec. action. clone( ) ] ) ) ) ;
466
+ . send ( Some ( ( block . block_identifier . clone ( ) , tx. clone ( ) , vec ! [ predicate_spec. action. clone( ) ] ) ) ) ;
465
467
} else {
466
468
hits. push ( tx) ;
467
469
}
@@ -579,16 +581,16 @@ pub async fn retrieve_block_hash(config: &Config, block_height: &u64) -> Result<
579
581
580
582
pub async fn retrieve_satoshi_point_using_local_storage (
581
583
config : & Config ,
582
- origin_block_height : & u64 ,
584
+ block_identifier : & BlockIdentifier ,
583
585
transaction_identifier : & TransactionIdentifier ,
584
586
) -> Result < ( u64 , u64 ) , String > {
585
587
let path = config. get_bitcoin_block_traversal_db_path ( ) ;
586
588
let storage_conn = open_existing_readonly_db ( & path) ;
587
589
588
590
let mut ordinal_offset = 0 ;
589
- let mut ordinal_block_number = * origin_block_height as u32 ;
591
+ let mut ordinal_block_number = block_identifier . index as u32 ;
590
592
let txid = {
591
- let bytes = hex:: decode ( & transaction_identifier. hash ) . unwrap ( ) ;
593
+ let bytes = hex:: decode ( & transaction_identifier. hash [ 2 .. ] ) . unwrap ( ) ;
592
594
[ bytes[ 0 ] , bytes[ 1 ] , bytes[ 2 ] , bytes[ 3 ] ]
593
595
} ;
594
596
let mut tx_cursor = ( txid, 0 ) ;
0 commit comments