@@ -63,6 +63,10 @@ pub struct ConnectParams {
63
63
pub rpc_socket : SocketAddrV4 ,
64
64
/// p2p connection url, is some if the node started with p2p enabled
65
65
pub p2p_socket : Option < SocketAddrV4 > ,
66
+ /// zmq pub raw block connection url
67
+ pub zmq_pub_raw_block_socket : Option < SocketAddrV4 > ,
68
+ /// zmq pub raw tx connection Url
69
+ pub zmq_pub_raw_tx_socket : Option < SocketAddrV4 > ,
66
70
}
67
71
68
72
pub struct CookieValues {
@@ -217,6 +221,9 @@ pub struct Conf<'a> {
217
221
/// happen they are used at the time the process is spawn. When retrying other available ports
218
222
/// are returned reducing the probability of conflicts to negligible.
219
223
pub attempts : u8 ,
224
+
225
+ /// Enable the ZMQ interface to be accessible.
226
+ pub enable_zmq : bool ,
220
227
}
221
228
222
229
impl Default for Conf < ' _ > {
@@ -229,6 +236,7 @@ impl Default for Conf<'_> {
229
236
tmpdir : None ,
230
237
staticdir : None ,
231
238
attempts : 3 ,
239
+ enable_zmq : false ,
232
240
}
233
241
}
234
242
}
@@ -284,6 +292,25 @@ impl BitcoinD {
284
292
( args, Some ( p2p_socket) )
285
293
}
286
294
} ;
295
+
296
+ let ( zmq_args, zmq_pub_raw_tx_socket, zmq_pub_raw_block_socket) = match conf. enable_zmq {
297
+ true => {
298
+ let zmq_pub_raw_tx_port = get_available_port ( ) ?;
299
+ let zmq_pub_raw_tx_socket = SocketAddrV4 :: new ( LOCAL_IP , zmq_pub_raw_tx_port) ;
300
+ let zmq_pub_raw_block_port = get_available_port ( ) ?;
301
+ let zmq_pub_raw_block_socket = SocketAddrV4 :: new ( LOCAL_IP , zmq_pub_raw_block_port) ;
302
+ let zmqpubrawblock_arg =
303
+ format ! ( "-zmqpubrawblock=tcp://0.0.0.0:{}" , zmq_pub_raw_block_port) ;
304
+ let zmqpubrawtx_arg = format ! ( "-zmqpubrawtx=tcp://0.0.0.0:{}" , zmq_pub_raw_tx_port) ;
305
+ (
306
+ vec ! [ zmqpubrawtx_arg, zmqpubrawblock_arg] ,
307
+ Some ( zmq_pub_raw_tx_socket) ,
308
+ Some ( zmq_pub_raw_block_socket) ,
309
+ )
310
+ }
311
+ false => ( vec ! [ ] , None , None ) ,
312
+ } ;
313
+
287
314
let stdout = if conf. view_stdout {
288
315
Stdio :: inherit ( )
289
316
} else {
@@ -307,6 +334,7 @@ impl BitcoinD {
307
334
. args ( & default_args)
308
335
. args ( & p2p_args)
309
336
. args ( & conf_args)
337
+ . args ( & zmq_args)
310
338
. stdout ( stdout)
311
339
. spawn ( )
312
340
. with_context ( || format ! ( "Error while executing {:?}" , exe. as_ref( ) ) ) ?;
@@ -365,6 +393,8 @@ impl BitcoinD {
365
393
cookie_file,
366
394
rpc_socket,
367
395
p2p_socket,
396
+ zmq_pub_raw_block_socket,
397
+ zmq_pub_raw_tx_socket,
368
398
} ,
369
399
} )
370
400
}
@@ -767,6 +797,25 @@ mod test {
767
797
assert_eq ! ( password, result_values. password) ;
768
798
}
769
799
800
+ #[ test]
801
+ fn zmq_interface_enabled ( ) {
802
+ let mut conf = Conf :: default ( ) ;
803
+ conf. enable_zmq = true ;
804
+ let bitcoind = BitcoinD :: with_conf ( exe_path ( ) . unwrap ( ) , & conf) . unwrap ( ) ;
805
+
806
+ assert ! ( bitcoind. params. zmq_pub_raw_tx_socket. is_some( ) ) ;
807
+ assert ! ( bitcoind. params. zmq_pub_raw_block_socket. is_some( ) ) ;
808
+ }
809
+
810
+ #[ test]
811
+ fn zmq_interface_disabled ( ) {
812
+ let exe = init ( ) ;
813
+ let bitcoind = BitcoinD :: new ( exe) . unwrap ( ) ;
814
+
815
+ assert ! ( bitcoind. params. zmq_pub_raw_tx_socket. is_none( ) ) ;
816
+ assert ! ( bitcoind. params. zmq_pub_raw_block_socket. is_none( ) ) ;
817
+ }
818
+
770
819
fn peers_connected ( client : & Client ) -> usize {
771
820
let result: Vec < Value > = client. call ( "getpeerinfo" , & [ ] ) . unwrap ( ) ;
772
821
result. len ( )
0 commit comments