@@ -10,22 +10,20 @@ use crate::storage::{
10
10
open_readonly_stacks_db_conn,
11
11
} ;
12
12
13
- use chainhook_sdk:: bitcoincore_rpc:: { Auth , Client , RpcApi } ;
14
-
15
13
use chainhook_sdk:: chainhooks:: types:: {
16
14
BitcoinChainhookFullSpecification , BitcoinChainhookNetworkSpecification , BitcoinPredicateType , ChainhookFullSpecification , FileHook ,
17
15
HookAction , OrdinalOperations , StacksChainhookFullSpecification ,
18
16
StacksChainhookNetworkSpecification , StacksPredicate , StacksPrintEventBasedPredicate ,
19
17
} ;
20
18
use chainhook_sdk:: hord:: db:: {
21
- delete_data_in_hord_db, fetch_and_cache_blocks_in_hord_db , find_last_block_inserted ,
22
- find_lazy_block_at_block_height , find_watched_satpoint_for_inscription, initialize_hord_db,
23
- open_readonly_hord_db_conn , open_readonly_hord_db_conn_rocks_db, open_readwrite_hord_db_conn,
19
+ delete_data_in_hord_db, find_last_block_inserted , find_lazy_block_at_block_height ,
20
+ find_watched_satpoint_for_inscription, initialize_hord_db, open_readonly_hord_db_conn ,
21
+ open_readonly_hord_db_conn_rocks_db, open_readwrite_hord_db_conn,
24
22
open_readwrite_hord_db_conn_rocks_db, retrieve_satoshi_point_using_lazy_storage,
25
23
} ;
26
24
use chainhook_sdk:: hord:: {
27
25
new_traversals_lazy_cache, retrieve_inscribed_satoshi_points_from_block,
28
- update_storage_and_augment_bitcoin_block_with_inscription_transfer_data, HordConfig , Storage ,
26
+ update_storage_and_augment_bitcoin_block_with_inscription_transfer_data, Storage ,
29
27
} ;
30
28
use chainhook_sdk:: indexer;
31
29
use chainhook_sdk:: indexer:: bitcoin:: {
@@ -474,35 +472,6 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
474
472
475
473
info ! ( ctx. expect_logger( ) , "Starting service..." , ) ;
476
474
477
- if !cmd. hord_disabled {
478
- info ! (
479
- ctx. expect_logger( ) ,
480
- "Ordinal indexing is enabled by default hord, checking index... (use --no-hord to disable ordinals)"
481
- ) ;
482
-
483
- if let Some ( ( start_block, end_block) ) = should_sync_hord_db ( & config, & ctx) ? {
484
- if start_block == 0 {
485
- info ! (
486
- ctx. expect_logger( ) ,
487
- "Initializing hord indexing from block #{}" , start_block
488
- ) ;
489
- } else {
490
- info ! (
491
- ctx. expect_logger( ) ,
492
- "Resuming hord indexing from block #{}" , start_block
493
- ) ;
494
- }
495
- perform_hord_db_update (
496
- start_block,
497
- end_block,
498
- & config. get_hord_config ( ) ,
499
- & config,
500
- & ctx,
501
- )
502
- . await ?;
503
- }
504
- }
505
-
506
475
let mut service = Service :: new ( config, ctx) ;
507
476
return service. run ( predicates, cmd. hord_disabled ) . await ;
508
477
}
@@ -673,7 +642,8 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
673
642
) ) ;
674
643
}
675
644
} ;
676
-
645
+ // TODO: if a stacks.rocksdb is present, use it.
646
+ // TODO: update Stacks archive file if required.
677
647
scan_stacks_chainstate_via_csv_using_predicate (
678
648
& predicate_spec,
679
649
& mut config,
@@ -731,11 +701,12 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
731
701
find_last_block_inserted ( & hord_db_conn) as u64
732
702
} ;
733
703
if cmd. block_height > tip_height {
734
- perform_hord_db_update (
704
+ crate :: hord :: perform_hord_db_update (
735
705
tip_height,
736
706
cmd. block_height ,
737
707
& config. get_hord_config ( ) ,
738
708
& config,
709
+ None ,
739
710
& ctx,
740
711
)
741
712
. await ?;
@@ -802,11 +773,12 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
802
773
let tip_height = find_last_block_inserted ( & blocks_db_conn) as u64 ;
803
774
let _end_at = match cmd. block_height {
804
775
Some ( block_height) if block_height > tip_height => {
805
- perform_hord_db_update (
776
+ crate :: hord :: perform_hord_db_update (
806
777
tip_height,
807
778
block_height,
808
779
& config. get_hord_config ( ) ,
809
780
& config,
781
+ None ,
810
782
& ctx,
811
783
)
812
784
. await ?;
@@ -860,7 +832,9 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
860
832
Command :: Hord ( HordCommand :: Db ( subcmd) ) => match subcmd {
861
833
HordDbCommand :: Sync ( cmd) => {
862
834
let config = Config :: default ( false , false , false , & cmd. config_path ) ?;
863
- if let Some ( ( start_block, end_block) ) = should_sync_hord_db ( & config, & ctx) ? {
835
+ if let Some ( ( start_block, end_block) ) =
836
+ crate :: hord:: should_sync_hord_db ( & config, & ctx) ?
837
+ {
864
838
if start_block == 0 {
865
839
info ! (
866
840
ctx. expect_logger( ) ,
@@ -872,11 +846,12 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
872
846
"Resuming hord indexing from block #{}" , start_block
873
847
) ;
874
848
}
875
- perform_hord_db_update (
849
+ crate :: hord :: perform_hord_db_update (
876
850
start_block,
877
851
end_block,
878
852
& config. get_hord_config ( ) ,
879
853
& config,
854
+ None ,
880
855
& ctx,
881
856
)
882
857
. await ?;
@@ -902,11 +877,12 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
902
877
) ?;
903
878
}
904
879
// Update data
905
- perform_hord_db_update (
880
+ crate :: hord :: perform_hord_db_update (
906
881
cmd. start_block ,
907
882
cmd. end_block ,
908
883
& config. get_hord_config ( ) ,
909
884
& config,
885
+ None ,
910
886
& ctx,
911
887
)
912
888
. await ?;
@@ -1023,87 +999,6 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
1023
999
Ok ( ( ) )
1024
1000
}
1025
1001
1026
- pub fn should_sync_hord_db ( config : & Config , ctx : & Context ) -> Result < Option < ( u64 , u64 ) > , String > {
1027
- let auth = Auth :: UserPass (
1028
- config. network . bitcoind_rpc_username . clone ( ) ,
1029
- config. network . bitcoind_rpc_password . clone ( ) ,
1030
- ) ;
1031
-
1032
- let bitcoin_rpc = match Client :: new ( & config. network . bitcoind_rpc_url , auth) {
1033
- Ok ( con) => con,
1034
- Err ( message) => {
1035
- return Err ( format ! ( "Bitcoin RPC error: {}" , message. to_string( ) ) ) ;
1036
- }
1037
- } ;
1038
-
1039
- let start_block = match open_readonly_hord_db_conn_rocks_db ( & config. expected_cache_path ( ) , & ctx)
1040
- {
1041
- Ok ( blocks_db) => find_last_block_inserted ( & blocks_db) as u64 ,
1042
- Err ( err) => {
1043
- warn ! ( ctx. expect_logger( ) , "{}" , err) ;
1044
- 0
1045
- }
1046
- } ;
1047
-
1048
- if start_block == 0 {
1049
- let _ = initialize_hord_db ( & config. expected_cache_path ( ) , & ctx) ;
1050
- }
1051
-
1052
- let end_block = match bitcoin_rpc. get_blockchain_info ( ) {
1053
- Ok ( result) => result. blocks ,
1054
- Err ( e) => {
1055
- return Err ( format ! (
1056
- "unable to retrieve Bitcoin chain tip ({})" ,
1057
- e. to_string( )
1058
- ) ) ;
1059
- }
1060
- } ;
1061
-
1062
- if start_block < end_block {
1063
- Ok ( Some ( ( start_block, end_block) ) )
1064
- } else {
1065
- Ok ( None )
1066
- }
1067
- }
1068
-
1069
- pub async fn perform_hord_db_update (
1070
- start_block : u64 ,
1071
- end_block : u64 ,
1072
- hord_config : & HordConfig ,
1073
- config : & Config ,
1074
- ctx : & Context ,
1075
- ) -> Result < ( ) , String > {
1076
- info ! (
1077
- ctx. expect_logger( ) ,
1078
- "Syncing hord_db: {} blocks to download ({start_block}: {end_block})" ,
1079
- end_block - start_block + 1
1080
- ) ;
1081
-
1082
- let bitcoin_config = BitcoinConfig {
1083
- username : config. network . bitcoind_rpc_username . clone ( ) ,
1084
- password : config. network . bitcoind_rpc_password . clone ( ) ,
1085
- rpc_url : config. network . bitcoind_rpc_url . clone ( ) ,
1086
- network : config. network . bitcoin_network . clone ( ) ,
1087
- bitcoin_block_signaling : config. network . bitcoin_block_signaling . clone ( ) ,
1088
- } ;
1089
-
1090
- let blocks_db = open_readwrite_hord_db_conn_rocks_db ( & config. expected_cache_path ( ) , & ctx) ?;
1091
- let inscriptions_db_conn_rw = open_readwrite_hord_db_conn ( & config. expected_cache_path ( ) , & ctx) ?;
1092
-
1093
- let _ = fetch_and_cache_blocks_in_hord_db (
1094
- & bitcoin_config,
1095
- & blocks_db,
1096
- & inscriptions_db_conn_rw,
1097
- start_block,
1098
- end_block,
1099
- hord_config,
1100
- & ctx,
1101
- )
1102
- . await ?;
1103
-
1104
- Ok ( ( ) )
1105
- }
1106
-
1107
1002
#[ allow( dead_code) ]
1108
1003
pub fn install_ctrlc_handler ( terminate_tx : Sender < DigestingCommand > , ctx : Context ) {
1109
1004
ctrlc:: set_handler ( move || {
0 commit comments