@@ -15,42 +15,37 @@ const NBLOCKS: usize = 101;
15
15
#[ allow( dead_code) ] // Not all tests use this function.
16
16
pub fn init_logger ( ) { let _ = env_logger:: try_init ( ) ; }
17
17
18
+ /// Controls the loaded wallet.
19
+ pub enum Wallet {
20
+ /// Load the default wallet.
21
+ Default ,
22
+ /// Load a wallet with custom name.
23
+ Load ( String ) ,
24
+ /// Do not load a wallet.
25
+ None ,
26
+ }
27
+
18
28
pub trait NodeExt {
19
29
/// Returns a handle to a `bitcoind` instance after leading wallet if present.
20
- fn new ( conf : node :: Conf , wallet : Option < String > ) -> Node ;
30
+ fn _new ( wallet : Wallet , txindex : bool ) -> Node ;
21
31
22
32
/// Returns a handle to a `bitcoind` instance with "default" wallet loaded.
23
- fn new_with_default_wallet ( ) -> Node {
24
- let conf = node:: Conf :: default ( ) ;
25
- Self :: new ( conf, None )
26
- }
33
+ fn new_with_default_wallet ( ) -> Node { Self :: _new ( Wallet :: Default , false ) }
27
34
28
35
/// Returns a handle to a `bitcoind` instance with "default" wallet loaded and `-txindex` enabled.
29
- fn new_with_default_wallet_txindex ( ) -> Node {
30
- let mut conf = node:: Conf :: default ( ) ;
31
- conf. args . push ( "-txindex" ) ;
32
- Self :: new ( conf, None )
33
- }
36
+ fn new_with_default_wallet_txindex ( ) -> Node { Self :: _new ( Wallet :: Default , true ) }
34
37
35
38
/// Returns a handle to a `bitcoind` instance with `wallet` loaded.
36
- fn new_with_wallet ( wallet : String ) -> Node {
37
- let conf = node :: Conf :: default ( ) ;
38
- Self :: new ( conf , Some ( wallet) )
39
- }
39
+ fn new_with_wallet ( wallet : String ) -> Node { Self :: _new ( Wallet :: Load ( wallet ) , false ) }
40
+
41
+ /// Returns a handle to a `bitcoind` instance with ` wallet` loaded and `-txindex` enabled.
42
+ fn new_with_wallet_txindex ( wallet : String ) -> Node { Self :: _new ( Wallet :: Load ( wallet ) , true ) }
40
43
41
44
/// Returns a handle to a `bitcoind` instance without any wallet loaded.
42
- fn new_no_wallet ( ) -> Node {
43
- let mut conf = node:: Conf :: default ( ) ;
44
- conf. wallet = None ;
45
- Self :: new ( conf, None )
46
- }
45
+ fn new_no_wallet ( ) -> Node { Self :: _new ( Wallet :: None , false ) }
47
46
48
47
/// Returns a handle to a `bitcoind` instance without any wallet loaded and `-txindex` enabled.
49
- fn new_no_wallet_txindex ( ) -> Node {
50
- let mut conf = node:: Conf :: default ( ) ;
51
- conf. args . push ( "-txindex" ) ;
52
- Self :: new ( conf, None )
53
- }
48
+ fn new_no_wallet_txindex ( ) -> Node { Self :: _new ( Wallet :: None , true ) }
54
49
55
50
/// Generates [`NBLOCKS`] to an address controlled by the loaded wallet.
56
51
fn fund_wallet ( & self ) ;
@@ -76,11 +71,18 @@ pub trait NodeExt {
76
71
}
77
72
78
73
impl NodeExt for Node {
79
- fn new ( mut conf : node :: Conf , wallet : Option < String > ) -> Node {
74
+ fn _new ( wallet : Wallet , txindex : bool ) -> Node {
80
75
let exe = node:: exe_path ( ) . expect ( "failed to get bitcoind executable" ) ;
81
76
82
- if let Some ( wallet) = wallet {
83
- conf. wallet = Some ( wallet) ;
77
+ let mut conf = node:: Conf :: default ( ) ;
78
+ match wallet {
79
+ Wallet :: Default => { } , // conf.wallet = Some("default")
80
+ Wallet :: Load ( w) => conf. wallet = Some ( w) ,
81
+ Wallet :: None => conf. wallet = None ,
82
+ }
83
+
84
+ if txindex {
85
+ conf. args . push ( "-txindex" ) ;
84
86
}
85
87
86
88
Node :: with_conf ( exe, & conf) . expect ( "failed to create node" )
0 commit comments