@@ -23,6 +23,7 @@ use crate::db::{
23
23
find_last_block_inserted, find_missing_blocks, run_compaction,
24
24
update_sequence_metadata_with_block,
25
25
} ;
26
+ use crate :: ord:: chain;
26
27
use crate :: scan:: bitcoin:: process_block_with_predicates;
27
28
use crate :: service:: http_api:: start_predicate_api_server;
28
29
use crate :: service:: observers:: {
@@ -33,7 +34,7 @@ use crate::service::observers::{
33
34
use crate :: service:: runloops:: start_bitcoin_scan_runloop;
34
35
use chainhook_sdk:: chainhooks:: bitcoin:: BitcoinChainhookOccurrencePayload ;
35
36
use chainhook_sdk:: chainhooks:: types:: {
36
- BitcoinChainhookSpecification , ChainhookFullSpecification , ChainhookSpecification ,
37
+ BitcoinChainhookSpecification , ChainhookConfig , ChainhookFullSpecification , ChainhookSpecification
37
38
} ;
38
39
use chainhook_sdk:: observer:: {
39
40
start_event_observer, BitcoinBlockDataCached , DataHandlerEvent , EventObserverConfig ,
@@ -63,17 +64,33 @@ impl Service {
63
64
64
65
pub async fn run (
65
66
& mut self ,
66
- predicates : Vec < BitcoinChainhookSpecification > ,
67
+ observer_specs : Vec < BitcoinChainhookSpecification > ,
67
68
predicate_activity_relayer : Option <
68
69
crossbeam_channel:: Sender < BitcoinChainhookOccurrencePayload > ,
69
70
> ,
70
71
check_blocks_integrity : bool ,
72
+ stream_indexing_to_observers : bool ,
71
73
) -> Result < ( ) , String > {
72
74
let mut event_observer_config = self . config . get_event_observer_config ( ) ;
73
75
76
+ let block_post_processor = if stream_indexing_to_observers && !observer_specs. is_empty ( ) {
77
+ let mut chainhook_config: ChainhookConfig = ChainhookConfig :: new ( ) ;
78
+ let specs = observer_specs. clone ( ) ;
79
+ for mut observer_spec in specs. into_iter ( ) {
80
+ observer_spec. enabled = true ;
81
+ let spec = ChainhookSpecification :: Bitcoin ( observer_spec) ;
82
+ chainhook_config. register_specification ( spec) ?;
83
+ }
84
+ event_observer_config. chainhook_config = Some ( chainhook_config) ;
85
+ let block_tx = start_observer_forwarding ( & event_observer_config, & self . ctx ) ;
86
+ Some ( block_tx)
87
+ } else {
88
+ None
89
+ } ;
90
+
74
91
// Catch-up with chain tip
75
92
let chain_tip_height = self
76
- . catch_up_with_chain_tip ( false , check_blocks_integrity)
93
+ . catch_up_with_chain_tip ( false , check_blocks_integrity, block_post_processor )
77
94
. await ?;
78
95
info ! (
79
96
self . ctx. expect_logger( ) ,
@@ -98,7 +115,7 @@ impl Service {
98
115
// 2) catch-up outdated observers by dispatching replays
99
116
let ( chainhook_config, outdated_observers) =
100
117
create_and_consolidate_chainhook_config_with_predicates (
101
- predicates ,
118
+ observer_specs ,
102
119
chain_tip_height,
103
120
predicate_activity_relayer. is_some ( ) ,
104
121
& self . config ,
@@ -446,6 +463,7 @@ impl Service {
446
463
& mut self ,
447
464
rebuild_from_scratch : bool ,
448
465
compact_and_check_rocksdb_integrity : bool ,
466
+ block_post_processor : Option < crossbeam_channel:: Sender < BitcoinBlockData > > ,
449
467
) -> Result < u64 , String > {
450
468
{
451
469
if compact_and_check_rocksdb_integrity {
@@ -515,7 +533,7 @@ impl Service {
515
533
) ?;
516
534
}
517
535
}
518
- self . update_state ( None ) . await
536
+ self . update_state ( block_post_processor ) . await
519
537
}
520
538
521
539
pub async fn update_state (
0 commit comments