@@ -16,7 +16,7 @@ use chainhook_event_observer::hord::db::{
16
16
delete_data_in_hord_db, fetch_and_cache_blocks_in_hord_db,
17
17
find_inscriptions_at_wached_outpoint, find_latest_compacted_block_known, initialize_hord_db,
18
18
open_readonly_hord_db_conn, open_readwrite_hord_db_conn,
19
- retrieve_satoshi_point_using_local_storage,
19
+ retrieve_satoshi_point_using_local_storage, find_all_inscriptions , find_compacted_block_at_block_height , patch_inscription_number ,
20
20
} ;
21
21
use chainhook_event_observer:: observer:: BitcoinConfig ;
22
22
use chainhook_event_observer:: utils:: Context ;
@@ -198,6 +198,9 @@ enum DbCommand {
198
198
/// Rebuild inscriptions entries for a given block
199
199
#[ clap( name = "drop" , bin_name = "drop" ) ]
200
200
Drop ( DropHordDbCommand ) ,
201
+ /// Patch DB
202
+ #[ clap( name = "patch" , bin_name = "patch" ) ]
203
+ Patch ( PatchHordDbCommand ) ,
201
204
}
202
205
203
206
#[ derive( Subcommand , PartialEq , Clone , Debug ) ]
@@ -298,6 +301,13 @@ struct DropHordDbCommand {
298
301
pub config_path : Option < String > ,
299
302
}
300
303
304
+ #[ derive( Parser , PartialEq , Clone , Debug ) ]
305
+ struct PatchHordDbCommand {
306
+ /// Load config file path
307
+ #[ clap( long = "config-path" ) ]
308
+ pub config_path : Option < String > ,
309
+ }
310
+
301
311
pub fn main ( ) {
302
312
let logger = hiro_system_kit:: log:: setup_logger ( ) ;
303
313
let _guard = hiro_system_kit:: log:: setup_global_logger ( logger. clone ( ) ) ;
@@ -618,6 +628,35 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
618
628
cmd. end_block - cmd. start_block + 1
619
629
) ;
620
630
}
631
+ DbCommand :: Patch ( cmd) => {
632
+ let config = Config :: default ( false , false , false , & cmd. config_path ) ?;
633
+ let rw_hord_db_conn =
634
+ open_readwrite_hord_db_conn ( & config. expected_cache_path ( ) , & ctx) ?;
635
+
636
+ let inscriptions_per_blocks = find_all_inscriptions ( & rw_hord_db_conn) ;
637
+ let mut inscription_number = 0 ;
638
+ 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) {
640
+ Some ( block) => block,
641
+ None => continue ,
642
+ } ;
643
+
644
+ for ( txid, _) in inscriptions. iter ( ) {
645
+ for ( txid_n, _, _) in block. 0 . 1 . iter ( ) {
646
+ if txid. hash [ 2 ..10 ] . eq ( & hex:: encode ( txid_n) ) {
647
+ let inscription_id = format ! ( "{}i0" , & txid. hash[ 2 ..] ) ;
648
+ patch_inscription_number ( & inscription_id, inscription_number, & rw_hord_db_conn, & ctx) ;
649
+ info ! (
650
+ ctx. expect_logger( ) ,
651
+ "Patch inscription_number: {} {}" ,
652
+ inscription_id, inscription_number
653
+ ) ;
654
+ }
655
+ }
656
+ inscription_number += 1 ;
657
+ }
658
+ }
659
+ }
621
660
} ,
622
661
}
623
662
Ok ( ( ) )
0 commit comments