@@ -31,31 +31,31 @@ pub use self::{
31
31
} ;
32
32
33
33
#[ derive( Debug ) ]
34
- /// Struct representing the bitcoind process with related information
34
+ /// Struct representing the bitcoind process with related information.
35
35
pub struct Node {
36
- /// Process child handle, used to terminate the process when this struct is dropped
36
+ /// Process child handle, used to terminate the process when this struct is dropped.
37
37
process : Child ,
38
- /// Rpc client linked to this bitcoind process
38
+ /// Rpc client linked to this bitcoind process.
39
39
pub client : Client ,
40
40
/// Work directory, where the node store blocks and other stuff.
41
41
work_dir : DataDir ,
42
42
43
- /// Contains information to connect to this node
43
+ /// Contains information to connect to this node.
44
44
pub params : ConnectParams ,
45
45
}
46
46
47
47
#[ derive( Debug ) ]
48
48
/// The DataDir struct defining the kind of data directory the node
49
49
/// will contain. Data directory can be either persistent, or temporary.
50
50
pub enum DataDir {
51
- /// Persistent Data Directory
51
+ /// Persistent Data Directory.
52
52
Persistent ( PathBuf ) ,
53
- /// Temporary Data Directory
53
+ /// Temporary Data Directory.
54
54
Temporary ( TempDir ) ,
55
55
}
56
56
57
57
impl DataDir {
58
- /// Return the data directory path
58
+ /// Return the data directory path.
59
59
fn path ( & self ) -> PathBuf {
60
60
match self {
61
61
Self :: Persistent ( path) => path. to_owned ( ) ,
@@ -65,17 +65,17 @@ impl DataDir {
65
65
}
66
66
67
67
#[ derive( Debug , Clone ) ]
68
- /// Contains all the information to connect to this node
68
+ /// Contains all the information to connect to this node.
69
69
pub struct ConnectParams {
70
- /// Path to the node cookie file, useful for other client to connect to the node
70
+ /// Path to the node cookie file, useful for other client to connect to the node.
71
71
pub cookie_file : PathBuf ,
72
- /// Url of the rpc of the node, useful for other client to connect to the node
72
+ /// Url of the rpc of the node, useful for other client to connect to the node.
73
73
pub rpc_socket : SocketAddrV4 ,
74
- /// p2p connection url, is some if the node started with p2p enabled
74
+ /// p2p connection url, is some if the node started with p2p enabled.
75
75
pub p2p_socket : Option < SocketAddrV4 > ,
76
- /// zmq pub raw block connection url
76
+ /// zmq pub raw block connection url.
77
77
pub zmq_pub_raw_block_socket : Option < SocketAddrV4 > ,
78
- /// zmq pub raw tx connection Url
78
+ /// zmq pub raw tx connection Url.
79
79
pub zmq_pub_raw_tx_socket : Option < SocketAddrV4 > ,
80
80
}
81
81
@@ -85,55 +85,55 @@ pub struct CookieValues {
85
85
}
86
86
87
87
impl ConnectParams {
88
- /// Parses the cookie file content
88
+ /// Parses the cookie file content.
89
89
fn parse_cookie ( content : String ) -> Option < CookieValues > {
90
90
let values: Vec < _ > = content. splitn ( 2 , ':' ) . collect ( ) ;
91
91
let user = values. first ( ) ?. to_string ( ) ;
92
92
let password = values. get ( 1 ) ?. to_string ( ) ;
93
93
Some ( CookieValues { user, password } )
94
94
}
95
95
96
- /// Return the user and password values from cookie file
96
+ /// Return the user and password values from cookie file.
97
97
pub fn get_cookie_values ( & self ) -> Result < Option < CookieValues > , std:: io:: Error > {
98
98
let cookie = std:: fs:: read_to_string ( & self . cookie_file ) ?;
99
99
Ok ( self :: ConnectParams :: parse_cookie ( cookie) )
100
100
}
101
101
}
102
102
103
- /// Enum to specify p2p settings
103
+ /// Enum to specify p2p settings.
104
104
#[ derive( Debug , PartialEq , Eq , Clone ) ]
105
105
pub enum P2P {
106
- /// the node doesn't open a p2p port and work in standalone mode
106
+ /// the node doesn't open a p2p port and work in standalone mode.
107
107
No ,
108
- /// the node open a p2p port
108
+ /// the node open a p2p port.
109
109
Yes ,
110
110
/// The node open a p2p port and also connects to the url given as parameter, it's handy to
111
111
/// initialize this with [Node::p2p_connect] of another node. The `bool` parameter indicates
112
112
/// if the node can accept connection too.
113
113
Connect ( SocketAddrV4 , bool ) ,
114
114
}
115
115
116
- /// All the possible error in this crate
116
+ /// All the possible error in this crate.
117
117
pub enum Error {
118
- /// Wrapper of io Error
118
+ /// Wrapper of io Error.
119
119
Io ( std:: io:: Error ) ,
120
- /// Wrapper of bitcoincore_rpc Error
120
+ /// Wrapper of bitcoincore_rpc Error.
121
121
Rpc ( client_sync:: Error ) ,
122
- /// Returned when calling methods requiring a feature to be activated, but it's not
122
+ /// Returned when calling methods requiring a feature to be activated, but it's not.
123
123
NoFeature ,
124
- /// Returned when calling methods requiring a env var to exist, but it's not
124
+ /// Returned when calling methods requiring a env var to exist, but it's not.
125
125
NoEnvVar ,
126
126
/// Returned when calling methods requiring the bitcoind executable but none is found
127
- /// (no feature, no `BITCOIND_EXE`, no `bitcoind` in `PATH` )
127
+ /// (no feature, no `BITCOIND_EXE`, no `bitcoind` in `PATH` ).
128
128
NoBitcoindExecutableFound ,
129
- /// Wrapper of early exit status
129
+ /// Wrapper of early exit status.
130
130
EarlyExit ( ExitStatus ) ,
131
- /// Returned when both tmpdir and staticdir is specified in `Conf` options
131
+ /// Returned when both tmpdir and staticdir is specified in `Conf` options.
132
132
BothDirsSpecified ,
133
- /// Returned when -rpcuser and/or -rpcpassword is used in `Conf` args
134
- /// It will soon be deprecated, please use -rpcauth instead
133
+ /// Returned when -rpcuser and/or -rpcpassword is used in `Conf` args.
134
+ /// It will soon be deprecated, please use -rpcauth instead.
135
135
RpcUserAndPasswordUsed ,
136
- /// Returned when expecting an auto-downloaded executable but `BITCOIND_SKIP_DOWNLOAD` env var is set
136
+ /// Returned when expecting an auto-downloaded executable but `BITCOIND_SKIP_DOWNLOAD` env var is set.
137
137
SkipDownload ,
138
138
/// Returned when bitcoind could not be reached after multiple attempts.
139
139
/// The attached string, if present, contains the error encountered when trying to connect.
@@ -214,14 +214,14 @@ pub struct Conf<'a> {
214
214
/// cannot be used because they are automatically initialized.
215
215
pub args : Vec < & ' a str > ,
216
216
217
- /// if `true` bitcoind log output will not be suppressed
217
+ /// if `true` bitcoind log output will not be suppressed.
218
218
pub view_stdout : bool ,
219
219
220
- /// Allows to specify options to open p2p port or connect to the another node
220
+ /// Allows to specify options to open p2p port or connect to the another node.
221
221
pub p2p : P2P ,
222
222
223
223
/// Must match what specified in args without dashes, needed to locate the cookie file
224
- /// directory with different/esoteric networks
224
+ /// directory with different/esoteric networks.
225
225
pub network : & ' a str ,
226
226
227
227
/// Temporary directory path.
@@ -239,10 +239,10 @@ pub struct Conf<'a> {
239
239
/// mode, as it cause memory overflows.
240
240
pub tmpdir : Option < PathBuf > ,
241
241
242
- /// Persistent directory path
242
+ /// Persistent directory path.
243
243
pub staticdir : Option < PathBuf > ,
244
244
245
- /// Try to spawn the process `attempt` time
245
+ /// Try to spawn the process `attempt` time.
246
246
///
247
247
/// The OS is giving available ports to use, however, they aren't booked, so it could rarely
248
248
/// happen they are used at the time the process is spawn. When retrying other available ports
@@ -275,7 +275,7 @@ impl Default for Conf<'_> {
275
275
impl Node {
276
276
/// Launch the bitcoind process from the given `exe` executable with default args.
277
277
///
278
- /// Waits for the node to be ready to accept connections before returning
278
+ /// Waits for the node to be ready to accept connections before returning.
279
279
pub fn new < S : AsRef < OsStr > > ( exe : S ) -> anyhow:: Result < Node > {
280
280
Node :: with_conf ( exe, & Conf :: default ( ) )
281
281
}
@@ -435,8 +435,8 @@ impl Node {
435
435
///
436
436
/// # Parameters
437
437
/// * `enable_zmq` - If `true`, creates two ZMQ sockets:
438
- /// - `zmq_pub_raw_tx_socket`: for raw transaction publishing
439
- /// - `zmq_pub_raw_block_socket`: for raw block publishing
438
+ /// - `zmq_pub_raw_tx_socket`: for raw transaction publishing.
439
+ /// - `zmq_pub_raw_block_socket`: for raw block publishing.
440
440
fn zmq_args (
441
441
enable_zmq : bool ,
442
442
) -> anyhow:: Result < ( Vec < String > , Option < SocketAddrV4 > , Option < SocketAddrV4 > ) > {
@@ -522,31 +522,31 @@ impl Node {
522
522
Err ( Error :: NoBitcoindInstance ( "Could not create or load wallet" . to_string ( ) ) . into ( ) )
523
523
}
524
524
525
- /// Returns the rpc URL including the schema eg. http://127.0.0.1:44842
525
+ /// Returns the rpc URL including the schema eg. http://127.0.0.1:44842.
526
526
pub fn rpc_url ( & self ) -> String { format ! ( "http://{}" , self . params. rpc_socket) }
527
527
528
- /// Returns the rpc URL including the schema and the given `wallet_name`
529
- /// eg. http://127.0.0.1:44842/wallet/my_wallet
528
+ /// Returns the rpc URL including the schema and the given `wallet_name`.
529
+ /// eg. http://127.0.0.1:44842/wallet/my_wallet.
530
530
pub fn rpc_url_with_wallet < T : AsRef < str > > ( & self , wallet_name : T ) -> String {
531
531
format ! ( "http://{}/wallet/{}" , self . params. rpc_socket, wallet_name. as_ref( ) )
532
532
}
533
533
534
- /// Return the current workdir path of the running node
534
+ /// Return the current workdir path of the running node.
535
535
pub fn workdir ( & self ) -> PathBuf { self . work_dir . path ( ) }
536
536
537
- /// Returns the [P2P] enum to connect to this node p2p port
537
+ /// Returns the [P2P] enum to connect to this node p2p port.
538
538
pub fn p2p_connect ( & self , listen : bool ) -> Option < P2P > {
539
539
self . params . p2p_socket . map ( |s| P2P :: Connect ( s, listen) )
540
540
}
541
541
542
- /// Stop the node, waiting correct process termination
542
+ /// Stop the node, waiting correct process termination.
543
543
pub fn stop ( & mut self ) -> anyhow:: Result < ExitStatus > {
544
544
self . client . stop ( ) ?;
545
545
Ok ( self . process . wait ( ) ?)
546
546
}
547
547
548
548
/// Create a new wallet in the running node, and return an RPC client connected to the just
549
- /// created wallet
549
+ /// created wallet.
550
550
pub fn create_wallet < T : AsRef < str > > ( & self , wallet : T ) -> anyhow:: Result < Client > {
551
551
let _ = self . client . create_wallet ( wallet. as_ref ( ) ) ?;
552
552
Ok ( Client :: new_with_auth (
@@ -578,7 +578,7 @@ impl Drop for Node {
578
578
579
579
/// Returns a non-used local port if available.
580
580
///
581
- /// Note there is a race condition during the time the method check availability and the caller
581
+ /// Note there is a race condition during the time the method check availability and the caller.
582
582
pub fn get_available_port ( ) -> anyhow:: Result < u16 > {
583
583
// using 0 as port let the system assign a port available
584
584
let t = TcpListener :: bind ( ( "127.0.0.1" , 0 ) ) ?; // 0 means the OS choose a free port
@@ -593,11 +593,11 @@ impl From<client_sync::Error> for Error {
593
593
fn from ( e : client_sync:: Error ) -> Self { Error :: Rpc ( e) }
594
594
}
595
595
596
- /// Provide the bitcoind executable path if a version feature has been specified
596
+ /// Provide the bitcoind executable path if a version feature has been specified.
597
597
#[ cfg( not( feature = "download" ) ) ]
598
598
pub fn downloaded_exe_path ( ) -> anyhow:: Result < String > { Err ( Error :: NoFeature . into ( ) ) }
599
599
600
- /// Provide the bitcoind executable path if a version feature has been specified
600
+ /// Provide the bitcoind executable path if a version feature has been specified.
601
601
#[ cfg( feature = "download" ) ]
602
602
pub fn downloaded_exe_path ( ) -> anyhow:: Result < String > {
603
603
if std:: env:: var_os ( "BITCOIND_SKIP_DOWNLOAD" ) . is_some ( ) {
@@ -621,10 +621,10 @@ pub fn downloaded_exe_path() -> anyhow::Result<String> {
621
621
622
622
/// Returns the daemon `bitcoind` executable with the following precedence:
623
623
///
624
- /// 1) If it's specified in the `BITCOIND_EXE` env var
624
+ /// 1) If it's specified in the `BITCOIND_EXE` env var.
625
625
/// 2) If there is no env var but the auto-download feature is enabled, returns the
626
- /// path of the downloaded executable
627
- /// 3) If neither of the precedent are available, the `bitcoind` executable is searched in the `PATH`
626
+ /// path of the downloaded executable.
627
+ /// 3) If neither of the precedent are available, the `bitcoind` executable is searched in the `PATH`.
628
628
pub fn exe_path ( ) -> anyhow:: Result < String > {
629
629
if let Ok ( path) = std:: env:: var ( "BITCOIND_EXE" ) {
630
630
return Ok ( path) ;
@@ -637,7 +637,7 @@ pub fn exe_path() -> anyhow::Result<String> {
637
637
. map ( |p| p. display ( ) . to_string ( ) )
638
638
}
639
639
640
- /// Validate the specified arg if there is any unavailable or deprecated one
640
+ /// Validate the specified arg if there is any unavailable or deprecated one.
641
641
pub fn validate_args ( args : Vec < & str > ) -> anyhow:: Result < Vec < & str > > {
642
642
args. iter ( ) . try_for_each ( |arg| {
643
643
// other kind of invalid arguments can be added into the list if needed
0 commit comments