@@ -13,10 +13,11 @@ use chainhook_event_observer::chainhooks::types::{
13
13
StacksPrintEventBasedPredicate ,
14
14
} ;
15
15
use chainhook_event_observer:: hord:: db:: {
16
- delete_data_in_hord_db, fetch_and_cache_blocks_in_hord_db,
17
- find_inscriptions_at_wached_outpoint, find_latest_compacted_block_known, initialize_hord_db,
18
- open_readonly_hord_db_conn, open_readwrite_hord_db_conn,
19
- retrieve_satoshi_point_using_local_storage, find_all_inscriptions, find_compacted_block_at_block_height, patch_inscription_number,
16
+ delete_data_in_hord_db, fetch_and_cache_blocks_in_hord_db, find_all_inscriptions,
17
+ find_compacted_block_at_block_height, find_inscriptions_at_wached_outpoint,
18
+ find_latest_compacted_block_known, initialize_hord_db, open_readonly_hord_db_conn,
19
+ open_readwrite_hord_db_conn, patch_inscription_number,
20
+ retrieve_satoshi_point_using_local_storage,
20
21
} ;
21
22
use chainhook_event_observer:: observer:: BitcoinConfig ;
22
23
use chainhook_event_observer:: utils:: Context ;
@@ -608,6 +609,11 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
608
609
}
609
610
DbCommand :: Rewrite ( cmd) => {
610
611
let config = Config :: default ( false , false , false , & cmd. config_path ) ?;
612
+ // Delete data, if any
613
+ let rw_hord_db_conn =
614
+ open_readwrite_hord_db_conn ( & config. expected_cache_path ( ) , & ctx) ?;
615
+ delete_data_in_hord_db ( cmd. start_block , cmd. end_block , & rw_hord_db_conn, & ctx) ?;
616
+ // Update data
611
617
perform_hord_db_update (
612
618
cmd. start_block ,
613
619
cmd. end_block ,
@@ -636,20 +642,30 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
636
642
let inscriptions_per_blocks = find_all_inscriptions ( & rw_hord_db_conn) ;
637
643
let mut inscription_number = 0 ;
638
644
for ( block_height, inscriptions) in inscriptions_per_blocks. iter ( ) {
639
- let block = match find_compacted_block_at_block_height ( * block_height as u32 , & rw_hord_db_conn) {
645
+ let block = match find_compacted_block_at_block_height (
646
+ * block_height as u32 ,
647
+ & rw_hord_db_conn,
648
+ ) {
640
649
Some ( block) => block,
641
650
None => continue ,
642
651
} ;
643
652
644
653
for ( txid, _) in inscriptions. iter ( ) {
645
- for ( txid_n, _, _) in block. 0 . 1 . iter ( ) {
654
+ for ( txid_n, _, _) in block. 0 . 1 . iter ( ) {
646
655
if txid. hash [ 2 ..10 ] . eq ( & hex:: encode ( txid_n) ) {
647
656
let inscription_id = format ! ( "{}i0" , & txid. hash[ 2 ..] ) ;
648
- patch_inscription_number ( & inscription_id, inscription_number, & rw_hord_db_conn, & ctx) ;
657
+ patch_inscription_number (
658
+ & inscription_id,
659
+ inscription_number,
660
+ & rw_hord_db_conn,
661
+ & ctx,
662
+ ) ;
649
663
info ! (
650
664
ctx. expect_logger( ) ,
651
- "Patch inscription_number: {} {}" ,
652
- inscription_id, inscription_number
665
+ "Patch inscription_number: {}\t {}\t ({})" ,
666
+ inscription_id,
667
+ inscription_number,
668
+ block_height
653
669
) ;
654
670
}
655
671
}
0 commit comments