Skip to content

Commit e6e602c

Browse files
Add generic bitcoin-cli commands
This commit adds a special `external_subcommand` that can call any valid bitcoin-cli rpc call on the node. Even if we don't have it covered in our node command lists.
1 parent c1921a7 commit e6e602c

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/commands.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ pub enum NodeSubCommand {
156156
GetBalance,
157157
/// Send to an external wallet address
158158
SendToAddress { address: String, amount: u64 },
159+
/// Execute any bitcoin-cli commands
160+
#[structopt(external_subcommand)]
161+
BitcoinCli(Vec<String>)
159162
}
160163

161164
#[derive(Debug, StructOpt, Clone, PartialEq)]

src/handlers.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,10 @@ pub(crate) fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
617617
#[cfg(feature = "regtest-node")]
618618
ReplSubCommand::Node { subcommand } => {
619619
let backend = new_backend(&home_dir)?;
620-
backend.exec_cmd(subcommand)
620+
match backend.exec_cmd(subcommand) {
621+
Ok(result) => Ok(result),
622+
Err(e) => Ok(serde_json::Value::String(e.to_string()))
623+
}
621624
}
622625
#[cfg(any(
623626
feature = "electrum",

src/nodes.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use {
2323
},
2424
electrsd::bitcoind::bitcoincore_rpc::{Client, RpcApi},
2525
std::str::FromStr,
26+
serde_json::Value,
2627
};
2728

2829
#[allow(dead_code)]
@@ -94,6 +95,13 @@ impl Nodes {
9495
.send_to_address(&address, amount, None, None, None, None, None, None)
9596
.map_err(|e| Error::Generic(e.to_string()))?;
9697
Ok(serde_json::to_value(&txid)?)
98+
},
99+
100+
NodeSubCommand::BitcoinCli(args) => {
101+
let cmd = &args[0];
102+
let args = args[1..].iter().map(|arg| serde_json::Value::from_str(arg)).collect::<Result<Vec<Value>, _>>()?;
103+
let result: Value = client.call(cmd, &args)?;
104+
Ok(result)
97105
}
98106
}
99107
}

0 commit comments

Comments
 (0)