parser: allow node args

This commit is contained in:
k
2024-07-10 20:51:03 +02:00
parent 4a82ee0b05
commit 2308fa173a
4 changed files with 22 additions and 15 deletions

View File

@@ -10,14 +10,16 @@ struct BlockchainInfo {
pub blocks: u64,
}
pub struct BitcoinDaemon<'a> {
path: &'a str,
pub struct BitcoinDaemon {
path: String,
other_args: Vec<String>,
}
impl<'a> BitcoinDaemon<'a> {
pub fn new(bitcoin_dir_path: &'a str) -> Self {
impl BitcoinDaemon {
pub fn new(bitcoin_dir_path: String, other_bitcoin_args: Vec<String>) -> Self {
Self {
path: bitcoin_dir_path,
other_args: other_bitcoin_args,
}
}
@@ -32,6 +34,10 @@ impl<'a> BitcoinDaemon<'a> {
.arg("-txindex=1")
.arg("-daemon");
self.other_args.iter().for_each(|arg| {
command.arg(arg);
});
// bitcoind -datadir=/Users/k/Developer/bitcoin -blocksonly -txindex=1 -daemon
let output = command
.output()
@@ -95,18 +101,18 @@ impl<'a> BitcoinDaemon<'a> {
let output = String::from_utf8_lossy(&output.stdout);
let json: Value = serde_json::from_str(&output)?;
let json = json.as_object().ok_or(eyre!(""))?;
let json = json.as_object().ok_or(eyre!("json as object failed"))?;
let blocks = json
.get("blocks")
.ok_or(eyre!(""))?
.ok_or(eyre!("get field 'blocks' from json failed"))?
.as_u64()
.ok_or(eyre!(""))?;
.ok_or(eyre!("blocks to u64 failed"))?;
let headers = json
.get("headers")
.ok_or(eyre!(""))?
.ok_or(eyre!("get field 'headers' from json failed"))?
.as_u64()
.ok_or(eyre!(""))?;
.ok_or(eyre!("blocks to u64 failed"))?;
Ok(BlockchainInfo { headers, blocks })
},