@@ -13,8 +13,8 @@ use chainhook_event_observer::chainhooks::types::{
13
13
StacksPrintEventBasedPredicate ,
14
14
} ;
15
15
use chainhook_event_observer:: hord:: db:: {
16
- fetch_and_cache_blocks_in_hord_db, find_inscriptions_at_wached_outpoint, initialize_hord_db ,
17
- open_readonly_hord_db_conn, open_readwrite_hord_db_conn,
16
+ fetch_and_cache_blocks_in_hord_db, find_inscriptions_at_wached_outpoint,
17
+ find_latest_compacted_block_known , open_readonly_hord_db_conn, open_readwrite_hord_db_conn,
18
18
retrieve_satoshi_point_using_local_storage,
19
19
} ;
20
20
use chainhook_event_observer:: observer:: BitcoinConfig ;
@@ -203,8 +203,6 @@ struct FindSatPointCommand {
203
203
pub block_height : u64 ,
204
204
/// Txid
205
205
pub txid : String ,
206
- /// Output index
207
- pub output_index : usize ,
208
206
/// Target Devnet network
209
207
#[ clap(
210
208
long = "devnet" ,
@@ -455,6 +453,21 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
455
453
FindCommand :: SatPoint ( cmd) => {
456
454
let config =
457
455
Config :: default ( cmd. devnet , cmd. testnet , cmd. mainnet , & cmd. config_path ) ?;
456
+
457
+ info ! (
458
+ ctx. expect_logger( ) ,
459
+ "Computing satoshi number for satoshi at offet 0 in 1st output of transaction {} (block ${})" , cmd. txid, cmd. block_height
460
+ ) ;
461
+
462
+ let hord_db_conn =
463
+ open_readonly_hord_db_conn ( & config. expected_cache_path ( ) , & ctx) . unwrap ( ) ;
464
+
465
+ let tip_height = find_latest_compacted_block_known ( & hord_db_conn) as u64 ;
466
+
467
+ if cmd. block_height > tip_height {
468
+ perform_hord_db_update ( tip_height, cmd. block_height , 8 , & config, & ctx) . await ?;
469
+ }
470
+
458
471
let transaction_identifier = TransactionIdentifier {
459
472
hash : cmd. txid . clone ( ) ,
460
473
} ;
@@ -463,10 +476,7 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
463
476
hash : "" . into ( ) ,
464
477
} ;
465
478
466
- let hord_db_conn =
467
- open_readonly_hord_db_conn ( & config. expected_cache_path ( ) , & ctx) . unwrap ( ) ;
468
-
469
- let ( block_height, offset, ordinal_number) =
479
+ let ( block_height, offset, ordinal_number, hops) =
470
480
retrieve_satoshi_point_using_local_storage (
471
481
& hord_db_conn,
472
482
& block_identifier,
@@ -475,7 +485,7 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
475
485
) ?;
476
486
info ! (
477
487
ctx. expect_logger( ) ,
478
- "Block: { block_height}, Offset {offset}:, Ordinal number: {ordinal_number} " ,
488
+ "Satoshi #{ordinal_number} was minted in block #{ block_height} at offset {offset} and was transferred {hops} times. " ,
479
489
) ;
480
490
}
481
491
FindCommand :: Inscription ( cmd) => {
@@ -491,14 +501,6 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
491
501
Command :: Hord ( HordCommand :: Db ( subcmd) ) => match subcmd {
492
502
DbCommand :: Init ( cmd) => {
493
503
let config = Config :: default ( false , false , false , & cmd. config_path ) ?;
494
-
495
- let bitcoin_config = BitcoinConfig {
496
- username : config. network . bitcoin_node_rpc_username . clone ( ) ,
497
- password : config. network . bitcoin_node_rpc_password . clone ( ) ,
498
- rpc_url : config. network . bitcoin_node_rpc_url . clone ( ) ,
499
- network : config. network . bitcoin_network . clone ( ) ,
500
- } ;
501
-
502
504
let auth = Auth :: UserPass (
503
505
config. network . bitcoin_node_rpc_username . clone ( ) ,
504
506
config. network . bitcoin_node_rpc_password . clone ( ) ,
@@ -521,38 +523,16 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
521
523
}
522
524
} ;
523
525
524
- let rw_hord_db_conn = initialize_hord_db ( & config. expected_cache_path ( ) , & ctx) ;
525
-
526
- let _ = fetch_and_cache_blocks_in_hord_db (
527
- & bitcoin_config,
528
- & rw_hord_db_conn,
529
- 0 ,
530
- end_block,
531
- & ctx,
532
- cmd. network_threads ,
533
- )
534
- . await ?;
526
+ perform_hord_db_update ( 0 , end_block, cmd. network_threads , & config, & ctx) . await ?;
535
527
}
536
528
DbCommand :: Update ( cmd) => {
537
529
let config = Config :: default ( false , false , false , & cmd. config_path ) ?;
538
-
539
- let bitcoin_config = BitcoinConfig {
540
- username : config. network . bitcoin_node_rpc_username . clone ( ) ,
541
- password : config. network . bitcoin_node_rpc_password . clone ( ) ,
542
- rpc_url : config. network . bitcoin_node_rpc_url . clone ( ) ,
543
- network : config. network . bitcoin_network . clone ( ) ,
544
- } ;
545
-
546
- let rw_hord_db_conn =
547
- open_readwrite_hord_db_conn ( & config. expected_cache_path ( ) , & ctx) ?;
548
-
549
- let _ = fetch_and_cache_blocks_in_hord_db (
550
- & bitcoin_config,
551
- & rw_hord_db_conn,
530
+ perform_hord_db_update (
552
531
cmd. start_block ,
553
532
cmd. end_block ,
554
- & ctx,
555
533
cmd. network_threads ,
534
+ & config,
535
+ & ctx,
556
536
)
557
537
. await ?;
558
538
}
@@ -561,6 +541,40 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
561
541
Ok ( ( ) )
562
542
}
563
543
544
+ pub async fn perform_hord_db_update (
545
+ start_block : u64 ,
546
+ end_block : u64 ,
547
+ network_threads : usize ,
548
+ config : & Config ,
549
+ ctx : & Context ,
550
+ ) -> Result < ( ) , String > {
551
+ info ! (
552
+ ctx. expect_logger( ) ,
553
+ "Syncing hord_db: {} blocks to download ({start_block}: {end_block}), using {network_threads} network threads" , end_block - start_block
554
+ ) ;
555
+
556
+ let bitcoin_config = BitcoinConfig {
557
+ username : config. network . bitcoin_node_rpc_username . clone ( ) ,
558
+ password : config. network . bitcoin_node_rpc_password . clone ( ) ,
559
+ rpc_url : config. network . bitcoin_node_rpc_url . clone ( ) ,
560
+ network : config. network . bitcoin_network . clone ( ) ,
561
+ } ;
562
+
563
+ let rw_hord_db_conn = open_readwrite_hord_db_conn ( & config. expected_cache_path ( ) , & ctx) ?;
564
+
565
+ let _ = fetch_and_cache_blocks_in_hord_db (
566
+ & bitcoin_config,
567
+ & rw_hord_db_conn,
568
+ start_block,
569
+ end_block,
570
+ & ctx,
571
+ network_threads,
572
+ )
573
+ . await ?;
574
+
575
+ Ok ( ( ) )
576
+ }
577
+
564
578
#[ allow( dead_code) ]
565
579
pub fn install_ctrlc_handler ( terminate_tx : Sender < DigestingCommand > , ctx : Context ) {
566
580
ctrlc:: set_handler ( move || {
0 commit comments