Skip to content

Commit 7bc0b8b

Browse files
committed
refactor: Move some shared code out into separate function
1 parent 175009b commit 7bc0b8b

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

testnet/stacks-node/src/tests/bitcoin_regtest.rs

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ impl BitcoinCoreController {
4444
}
4545
}
4646

47+
fn add_rpc_cli_args(&self, command: &mut Command) {
48+
command.arg(format!("-rpcport={}", self.config.burnchain.rpc_port));
49+
50+
match (
51+
&self.config.burnchain.username,
52+
&self.config.burnchain.password,
53+
) {
54+
(Some(username), Some(password)) => {
55+
command
56+
.arg(format!("-rpcuser={username}"))
57+
.arg(format!("-rpcpassword={password}"));
58+
}
59+
_ => {}
60+
}
61+
}
62+
4763
pub fn start_bitcoind(&mut self) -> BitcoinResult<()> {
4864
std::fs::create_dir_all(&self.config.get_burnchain_path_str()).unwrap();
4965

@@ -59,22 +75,11 @@ impl BitcoinCoreController {
5975
.arg("-listenonion=0")
6076
.arg("-rpcbind=127.0.0.1")
6177
.arg(format!("-port={}", self.config.burnchain.peer_port))
62-
.arg(format!("-datadir={}", self.config.get_burnchain_path_str()))
63-
.arg(format!("-rpcport={}", self.config.burnchain.rpc_port));
78+
.arg(format!("-datadir={}", self.config.get_burnchain_path_str()));
6479

65-
match (
66-
&self.config.burnchain.username,
67-
&self.config.burnchain.password,
68-
) {
69-
(Some(username), Some(password)) => {
70-
command
71-
.arg(format!("-rpcuser={username}"))
72-
.arg(format!("-rpcpassword={password}"));
73-
}
74-
_ => {}
75-
}
80+
self.add_rpc_cli_args(&mut command);
7681

77-
eprintln!("bitcoind spawn: {:?}", command);
82+
eprintln!("bitcoind spawn: {command:?}");
7883

7984
let mut process = match command.spawn() {
8085
Ok(child) => child,
@@ -105,22 +110,9 @@ impl BitcoinCoreController {
105110
pub fn stop_bitcoind(&mut self) -> Result<(), BitcoinCoreError> {
106111
if let Some(_) = self.bitcoind_process.take() {
107112
let mut command = Command::new("bitcoin-cli");
108-
command
109-
.stdout(Stdio::piped())
110-
.arg("-rpcconnect=127.0.0.1")
111-
.arg(format!("-rpcport={}", self.config.burnchain.rpc_port));
112-
113-
match (
114-
&self.config.burnchain.username,
115-
&self.config.burnchain.password,
116-
) {
117-
(Some(username), Some(password)) => {
118-
command
119-
.arg(format!("-rpcuser={username}"))
120-
.arg(format!("-rpcpassword={password}"));
121-
}
122-
_ => {}
123-
}
113+
command.stdout(Stdio::piped()).arg("-rpcconnect=127.0.0.1");
114+
115+
self.add_rpc_cli_args(&mut command);
124116

125117
command.arg("stop");
126118

0 commit comments

Comments
 (0)