@@ -30,7 +30,7 @@ use ordhook::db::{
30
30
} ;
31
31
use ordhook:: download:: download_ordinals_dataset_if_required;
32
32
use ordhook:: scan:: bitcoin:: scan_bitcoin_chainstate_via_rpc_using_predicate;
33
- use ordhook:: service:: Service ;
33
+ use ordhook:: service:: { start_observer_forwarding , Service } ;
34
34
use reqwest:: Client as HttpClient ;
35
35
use std:: collections:: BTreeMap ;
36
36
use std:: io:: { BufReader , Read } ;
@@ -155,31 +155,56 @@ enum RepairCommand {
155
155
Inscriptions ( RepairStorageCommand ) ,
156
156
/// Rewrite transfers data in hord.sqlite
157
157
#[ clap( name = "transfers" , bin_name = "transfers" ) ]
158
- Transfers ( RepairTransfersCommand ) ,
158
+ Transfers ( RepairStorageCommand ) ,
159
159
}
160
160
161
161
#[ derive( Parser , PartialEq , Clone , Debug ) ]
162
162
struct RepairStorageCommand {
163
- /// Starting block
164
- pub start_block : u64 ,
165
- /// Ending block
166
- pub end_block : u64 ,
163
+ /// Interval of blocks (--interval 767430:800000)
164
+ #[ clap( long = "interval" , conflicts_with = "blocks" ) ]
165
+ pub blocks_interval : Option < String > ,
166
+ /// List of blocks (--blocks 767430,767431,767433,800000)
167
+ #[ clap( long = "blocks" , conflicts_with = "interval" ) ]
168
+ pub blocks : Option < String > ,
167
169
/// Network threads
168
- pub network_threads : usize ,
170
+ #[ clap( long = "network-threads" ) ]
171
+ pub network_threads : Option < usize > ,
169
172
/// Load config file path
170
173
#[ clap( long = "config-path" ) ]
171
174
pub config_path : Option < String > ,
175
+ /// Cascade to observers
176
+ #[ clap( short, long, action = clap:: ArgAction :: SetTrue ) ]
177
+ pub repair_observers : Option < bool > ,
172
178
}
173
179
174
- #[ derive( Parser , PartialEq , Clone , Debug ) ]
175
- struct RepairTransfersCommand {
176
- /// Starting block
177
- pub start_block : u64 ,
178
- /// Ending block
179
- pub end_block : u64 ,
180
- /// Load config file path
181
- #[ clap( long = "config-path" ) ]
182
- pub config_path : Option < String > ,
180
+ impl RepairStorageCommand {
181
+ pub fn get_blocks ( & self ) -> Vec < u64 > {
182
+ let blocks = match ( & self . blocks_interval , & self . blocks ) {
183
+ ( Some ( interval) , None ) => {
184
+ let blocks = interval. split ( ":" ) . collect :: < Vec < _ > > ( ) ;
185
+ let start_block: u64 = blocks
186
+ . get ( 0 )
187
+ . expect ( "unable to get start_block" )
188
+ . parse :: < u64 > ( )
189
+ . expect ( "unable to parse start_block" ) ;
190
+ let end_block: u64 = blocks
191
+ . get ( 1 )
192
+ . expect ( "unable to get end_block" )
193
+ . parse :: < u64 > ( )
194
+ . expect ( "unable to parse end_block" ) ;
195
+ BlockHeights :: BlockRange ( start_block, end_block) . get_sorted_entries ( )
196
+ }
197
+ ( None , Some ( blocks) ) => {
198
+ let blocks = blocks
199
+ . split ( "," )
200
+ . map ( |b| b. parse :: < u64 > ( ) . expect ( "unable to parse block" ) )
201
+ . collect :: < Vec < _ > > ( ) ;
202
+ BlockHeights :: Blocks ( blocks) . get_sorted_entries ( )
203
+ }
204
+ _ => unreachable ! ( ) ,
205
+ } ;
206
+ blocks. into ( )
207
+ }
183
208
}
184
209
185
210
#[ derive( Subcommand , PartialEq , Clone , Debug ) ]
@@ -650,15 +675,18 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
650
675
RepairCommand :: Blocks ( cmd) => {
651
676
let config = ConfigFile :: default ( false , false , false , & cmd. config_path ) ?;
652
677
let mut ordhook_config = config. get_ordhook_config ( ) ;
653
- ordhook_config. network_thread_max = cmd. network_threads ;
654
-
678
+ if let Some ( network_threads) = cmd. network_threads {
679
+ ordhook_config. network_thread_max = network_threads;
680
+ }
681
+ if let Some ( network_threads) = cmd. network_threads {
682
+ ordhook_config. network_thread_max = network_threads;
683
+ }
684
+ let blocks = cmd. get_blocks ( ) ;
655
685
let block_ingestion_processor =
656
686
start_block_archiving_processor ( & config, ctx, false , None ) ;
657
-
658
687
download_and_pipeline_blocks (
659
688
& config,
660
- cmd. start_block ,
661
- cmd. end_block ,
689
+ blocks,
662
690
ordhook_config. first_inscription_height ,
663
691
Some ( & block_ingestion_processor) ,
664
692
10_000 ,
@@ -669,15 +697,24 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
669
697
RepairCommand :: Inscriptions ( cmd) => {
670
698
let config = ConfigFile :: default ( false , false , false , & cmd. config_path ) ?;
671
699
let mut ordhook_config = config. get_ordhook_config ( ) ;
672
- ordhook_config. network_thread_max = cmd. network_threads ;
673
-
700
+ if let Some ( network_threads) = cmd. network_threads {
701
+ ordhook_config. network_thread_max = network_threads;
702
+ }
703
+ let block_post_processor = match cmd. repair_observers {
704
+ Some ( true ) => {
705
+ let tx_replayer =
706
+ start_observer_forwarding ( & config. get_event_observer_config ( ) , & ctx) ;
707
+ Some ( tx_replayer)
708
+ }
709
+ _ => None ,
710
+ } ;
711
+ let blocks = cmd. get_blocks ( ) ;
674
712
let inscription_indexing_processor =
675
- start_inscription_indexing_processor ( & config, ctx, None ) ;
713
+ start_inscription_indexing_processor ( & config, ctx, block_post_processor ) ;
676
714
677
715
download_and_pipeline_blocks (
678
716
& config,
679
- cmd. start_block ,
680
- cmd. end_block ,
717
+ blocks,
681
718
ordhook_config. first_inscription_height ,
682
719
Some ( & inscription_indexing_processor) ,
683
720
10_000 ,
@@ -687,9 +724,18 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
687
724
}
688
725
RepairCommand :: Transfers ( cmd) => {
689
726
let config = ConfigFile :: default ( false , false , false , & cmd. config_path ) ?;
727
+ let block_post_processor = match cmd. repair_observers {
728
+ Some ( true ) => {
729
+ let tx_replayer =
730
+ start_observer_forwarding ( & config. get_event_observer_config ( ) , & ctx) ;
731
+ Some ( tx_replayer)
732
+ }
733
+ _ => None ,
734
+ } ;
690
735
let service = Service :: new ( config, ctx. clone ( ) ) ;
736
+ let blocks = cmd. get_blocks ( ) ;
691
737
service
692
- . replay_transfers ( cmd . start_block , cmd . end_block , None )
738
+ . replay_transfers ( blocks , block_post_processor )
693
739
. await ?;
694
740
}
695
741
} ,
0 commit comments