@@ -18,9 +18,7 @@ use crate::hord::{
18
18
revert_hord_db_with_augmented_bitcoin_block, update_hord_db_and_augment_bitcoin_block,
19
19
HordConfig ,
20
20
} ;
21
- use crate :: indexer:: bitcoin:: {
22
- standardize_bitcoin_block, BitcoinBlockFullBreakdown ,
23
- } ;
21
+ use crate :: indexer:: bitcoin:: { standardize_bitcoin_block, BitcoinBlockFullBreakdown } ;
24
22
use crate :: indexer:: { Indexer , IndexerConfig } ;
25
23
use crate :: utils:: { send_request, Context } ;
26
24
@@ -68,7 +66,7 @@ pub enum Event {
68
66
}
69
67
70
68
// TODO(lgalabru): Support for GRPC?
71
- #[ derive( Clone , Debug ) ]
69
+ #[ derive( Deserialize , Debug , Clone ) ]
72
70
pub enum EventHandler {
73
71
WebHook ( String ) ,
74
72
}
@@ -120,7 +118,7 @@ impl EventHandler {
120
118
async fn notify_bitcoin_transaction_proxied ( & self ) { }
121
119
}
122
120
123
- #[ derive( Clone , Debug ) ]
121
+ #[ derive( Debug , Clone ) ]
124
122
pub struct EventObserverConfig {
125
123
pub chainhook_config : Option < ChainhookConfig > ,
126
124
pub bitcoin_rpc_proxy_enabled : bool ,
@@ -139,6 +137,20 @@ pub struct EventObserverConfig {
139
137
pub hord_config : Option < HordConfig > ,
140
138
}
141
139
140
+ #[ derive( Deserialize , Debug , Clone ) ]
141
+ pub struct EventObserverConfigOverrides {
142
+ pub ingestion_port : Option < u16 > ,
143
+ pub bitcoind_rpc_username : Option < String > ,
144
+ pub bitcoind_rpc_password : Option < String > ,
145
+ pub bitcoind_rpc_url : Option < String > ,
146
+ pub bitcoind_zmq_url : Option < String > ,
147
+ pub stacks_node_rpc_url : Option < String > ,
148
+ pub display_logs : Option < bool > ,
149
+ pub cache_path : Option < String > ,
150
+ pub bitcoin_network : Option < String > ,
151
+ pub stacks_network : Option < String > ,
152
+ }
153
+
142
154
impl EventObserverConfig {
143
155
pub fn get_cache_path_buf ( & self ) -> PathBuf {
144
156
let mut path_buf = PathBuf :: new ( ) ;
@@ -156,6 +168,61 @@ impl EventObserverConfig {
156
168
} ;
157
169
bitcoin_config
158
170
}
171
+
172
+ pub fn new_using_overrides (
173
+ overrides : Option < & EventObserverConfigOverrides > ,
174
+ ) -> Result < EventObserverConfig , String > {
175
+ let stacks_node_rpc_url = overrides
176
+ . and_then ( |c| c. stacks_node_rpc_url . clone ( ) )
177
+ . unwrap_or ( "http://localhost:20443" . to_string ( ) ) ;
178
+
179
+ let bitcoin_network =
180
+ if let Some ( network) = overrides. and_then ( |c| c. bitcoin_network . as_ref ( ) ) {
181
+ BitcoinNetwork :: from_str ( network) ?
182
+ } else {
183
+ BitcoinNetwork :: Regtest
184
+ } ;
185
+
186
+ let stacks_network =
187
+ if let Some ( network) = overrides. and_then ( |c| c. stacks_network . as_ref ( ) ) {
188
+ StacksNetwork :: from_str ( network) ?
189
+ } else {
190
+ StacksNetwork :: Devnet
191
+ } ;
192
+
193
+ let config = EventObserverConfig {
194
+ bitcoin_rpc_proxy_enabled : false ,
195
+ event_handlers : vec ! [ ] ,
196
+ chainhook_config : None ,
197
+ ingestion_port : overrides
198
+ . and_then ( |c| c. ingestion_port )
199
+ . unwrap_or ( DEFAULT_INGESTION_PORT ) ,
200
+ bitcoind_rpc_username : overrides
201
+ . and_then ( |c| c. bitcoind_rpc_username . clone ( ) )
202
+ . unwrap_or ( "devnet" . to_string ( ) ) ,
203
+ bitcoind_rpc_password : overrides
204
+ . and_then ( |c| c. bitcoind_rpc_password . clone ( ) )
205
+ . unwrap_or ( "devnet" . to_string ( ) ) ,
206
+ bitcoind_rpc_url : overrides
207
+ . and_then ( |c| c. bitcoind_rpc_url . clone ( ) )
208
+ . unwrap_or ( "http://localhost:18443" . to_string ( ) ) ,
209
+ bitcoin_block_signaling : overrides
210
+ . and_then ( |c| match c. bitcoind_zmq_url . as_ref ( ) {
211
+ Some ( url) => Some ( BitcoinBlockSignaling :: ZeroMQ ( url. clone ( ) ) ) ,
212
+ None => Some ( BitcoinBlockSignaling :: Stacks ( stacks_node_rpc_url. clone ( ) ) ) ,
213
+ } )
214
+ . unwrap_or ( BitcoinBlockSignaling :: Stacks ( stacks_node_rpc_url. clone ( ) ) ) ,
215
+ stacks_node_rpc_url,
216
+ display_logs : overrides. and_then ( |c| c. display_logs ) . unwrap_or ( false ) ,
217
+ cache_path : overrides
218
+ . and_then ( |c| c. cache_path . clone ( ) )
219
+ . unwrap_or ( "cache" . to_string ( ) ) ,
220
+ bitcoin_network,
221
+ stacks_network,
222
+ hord_config : None ,
223
+ } ;
224
+ Ok ( config)
225
+ }
159
226
}
160
227
161
228
#[ derive( Deserialize , Debug ) ]
0 commit comments