@@ -5,7 +5,9 @@ use crate::scan::stacks::scan_stacks_chainstate_via_csv_using_predicate;
5
5
use chainhook_event_observer:: chainhooks:: types:: { ChainhookConfig , ChainhookFullSpecification } ;
6
6
7
7
use chainhook_event_observer:: chainhooks:: types:: ChainhookSpecification ;
8
- use chainhook_event_observer:: observer:: { start_event_observer, ApiKey , ObserverEvent } ;
8
+ use chainhook_event_observer:: observer:: {
9
+ start_event_observer, ApiKey , ObserverCommand , ObserverEvent ,
10
+ } ;
9
11
use chainhook_event_observer:: utils:: Context ;
10
12
use chainhook_types:: { BitcoinBlockSignaling , StacksBlockData , StacksChainEvent } ;
11
13
use redis:: { Commands , Connection } ;
@@ -115,10 +117,11 @@ impl Service {
115
117
116
118
let context_cloned = self . ctx . clone ( ) ;
117
119
let event_observer_config_moved = event_observer_config. clone ( ) ;
120
+ let observer_command_tx_moved = observer_command_tx. clone ( ) ;
118
121
let _ = std:: thread:: spawn ( move || {
119
122
let future = start_event_observer (
120
123
event_observer_config_moved,
121
- observer_command_tx ,
124
+ observer_command_tx_moved ,
122
125
observer_command_rx,
123
126
Some ( observer_event_tx) ,
124
127
context_cloned,
@@ -131,14 +134,16 @@ impl Service {
131
134
let stacks_scan_pool = ThreadPool :: new ( STACKS_SCAN_THREAD_POOL_SIZE ) ;
132
135
let ctx = self . ctx . clone ( ) ;
133
136
let config = self . config . clone ( ) ;
137
+ let observer_command_tx_moved = observer_command_tx. clone ( ) ;
134
138
let _ = hiro_system_kit:: thread_named ( "Stacks scan runloop" )
135
139
. spawn ( move || {
136
- while let Ok ( predicate_spec) = stacks_scan_op_rx. recv ( ) {
140
+ while let Ok ( ( predicate_spec, api_key ) ) = stacks_scan_op_rx. recv ( ) {
137
141
let moved_ctx = ctx. clone ( ) ;
138
142
let mut moved_config = config. clone ( ) ;
143
+ let observer_command_tx = observer_command_tx_moved. clone ( ) ;
139
144
stacks_scan_pool. execute ( move || {
140
145
let op = scan_stacks_chainstate_via_csv_using_predicate (
141
- predicate_spec,
146
+ & predicate_spec,
142
147
& mut moved_config,
143
148
& moved_ctx,
144
149
) ;
@@ -156,6 +161,10 @@ impl Service {
156
161
moved_ctx. expect_logger( ) ,
157
162
"Stacks chainstate scan completed up to block: {}" , end_block. index
158
163
) ;
164
+ let _ = observer_command_tx. send ( ObserverCommand :: EnablePredicate (
165
+ ChainhookSpecification :: Stacks ( predicate_spec) ,
166
+ api_key,
167
+ ) ) ;
159
168
} ) ;
160
169
}
161
170
let res = stacks_scan_pool. join ( ) ;
@@ -168,14 +177,16 @@ impl Service {
168
177
let bitcoin_scan_pool = ThreadPool :: new ( BITCOIN_SCAN_THREAD_POOL_SIZE ) ;
169
178
let ctx = self . ctx . clone ( ) ;
170
179
let config = self . config . clone ( ) ;
180
+ let moved_observer_command_tx = observer_command_tx. clone ( ) ;
171
181
let _ = hiro_system_kit:: thread_named ( "Bitcoin scan runloop" )
172
182
. spawn ( move || {
173
- while let Ok ( predicate_spec) = bitcoin_scan_op_rx. recv ( ) {
183
+ while let Ok ( ( predicate_spec, api_key ) ) = bitcoin_scan_op_rx. recv ( ) {
174
184
let moved_ctx = ctx. clone ( ) ;
175
185
let moved_config = config. clone ( ) ;
186
+ let observer_command_tx = moved_observer_command_tx. clone ( ) ;
176
187
bitcoin_scan_pool. execute ( move || {
177
188
let op = scan_bitcoin_chainstate_via_http_using_predicate (
178
- predicate_spec,
189
+ & predicate_spec,
179
190
& moved_config,
180
191
& moved_ctx,
181
192
) ;
@@ -189,6 +200,10 @@ impl Service {
189
200
) ;
190
201
}
191
202
} ;
203
+ let _ = observer_command_tx. send ( ObserverCommand :: EnablePredicate (
204
+ ChainhookSpecification :: Bitcoin ( predicate_spec) ,
205
+ api_key,
206
+ ) ) ;
192
207
} ) ;
193
208
}
194
209
let res = bitcoin_scan_pool. join ( ) ;
@@ -219,7 +234,7 @@ impl Service {
219
234
}
220
235
} ;
221
236
match event {
222
- ObserverEvent :: HookRegistered ( chainhook) => {
237
+ ObserverEvent :: HookRegistered ( chainhook, api_key ) => {
223
238
// If start block specified, use it.
224
239
// I no start block specified, depending on the nature the hook, we'd like to retrieve:
225
240
// - contract-id
@@ -243,10 +258,10 @@ impl Service {
243
258
}
244
259
match chainhook {
245
260
ChainhookSpecification :: Stacks ( predicate_spec) => {
246
- let _ = stacks_scan_op_tx. send ( predicate_spec) ;
261
+ let _ = stacks_scan_op_tx. send ( ( predicate_spec, api_key ) ) ;
247
262
}
248
263
ChainhookSpecification :: Bitcoin ( predicate_spec) => {
249
- let _ = bitcoin_scan_op_tx. send ( predicate_spec) ;
264
+ let _ = bitcoin_scan_op_tx. send ( ( predicate_spec, api_key ) ) ;
250
265
}
251
266
}
252
267
}
0 commit comments