@@ -183,9 +183,12 @@ enum DbCommand {
183
183
/// Init hord db
184
184
#[ clap( name = "init" , bin_name = "init" ) ]
185
185
Init ( InitHordDbCommand ) ,
186
- /// Update hord db
187
- #[ clap( name = "update" , bin_name = "update" ) ]
188
- Update ( UpdateHordDbCommand ) ,
186
+ /// Rewrite hord db
187
+ #[ clap( name = "rewrite" , bin_name = "rewrite" ) ]
188
+ Rewrite ( UpdateHordDbCommand ) ,
189
+ /// Catch-up hord db
190
+ #[ clap( name = "sync" , bin_name = "sync" ) ]
191
+ Sync ( SyncHordDbCommand ) ,
189
192
/// Rebuild inscriptions entries for a given block
190
193
#[ clap( name = "drop" , bin_name = "drop" ) ]
191
194
Drop ( DropHordDbCommand ) ,
@@ -269,6 +272,15 @@ struct UpdateHordDbCommand {
269
272
pub config_path : Option < String > ,
270
273
}
271
274
275
+ #[ derive( Parser , PartialEq , Clone , Debug ) ]
276
+ struct SyncHordDbCommand {
277
+ /// # of Networking thread
278
+ pub network_threads : usize ,
279
+ /// Load config file path
280
+ #[ clap( long = "config-path" ) ]
281
+ pub config_path : Option < String > ,
282
+ }
283
+
272
284
#[ derive( Parser , PartialEq , Clone , Debug ) ]
273
285
struct DropHordDbCommand {
274
286
/// Starting block
@@ -538,7 +550,38 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
538
550
539
551
perform_hord_db_update ( 0 , end_block, cmd. network_threads , & config, & ctx) . await ?;
540
552
}
541
- DbCommand :: Update ( cmd) => {
553
+ DbCommand :: Sync ( cmd) => {
554
+ let config = Config :: default ( false , false , false , & cmd. config_path ) ?;
555
+ let auth = Auth :: UserPass (
556
+ config. network . bitcoind_rpc_username . clone ( ) ,
557
+ config. network . bitcoind_rpc_password . clone ( ) ,
558
+ ) ;
559
+
560
+ let bitcoin_rpc = match Client :: new ( & config. network . bitcoind_rpc_url , auth) {
561
+ Ok ( con) => con,
562
+ Err ( message) => {
563
+ return Err ( format ! ( "Bitcoin RPC error: {}" , message. to_string( ) ) ) ;
564
+ }
565
+ } ;
566
+
567
+ let hord_db_conn = open_readonly_hord_db_conn ( & config. expected_cache_path ( ) , & ctx) ?;
568
+
569
+ let start_block = find_latest_compacted_block_known ( & hord_db_conn) as u64 ;
570
+
571
+ let end_block = match bitcoin_rpc. get_blockchain_info ( ) {
572
+ Ok ( result) => result. blocks ,
573
+ Err ( e) => {
574
+ return Err ( format ! (
575
+ "unable to retrieve Bitcoin chain tip ({})" ,
576
+ e. to_string( )
577
+ ) ) ;
578
+ }
579
+ } ;
580
+
581
+ perform_hord_db_update ( start_block, end_block, cmd. network_threads , & config, & ctx)
582
+ . await ?;
583
+ }
584
+ DbCommand :: Rewrite ( cmd) => {
542
585
let config = Config :: default ( false , false , false , & cmd. config_path ) ?;
543
586
perform_hord_db_update (
544
587
cmd. start_block ,
0 commit comments