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
+1
View File
@@ -0,0 +1 @@
"$HOME/Developer/bitcoin"
+1 -2
View File
@@ -23,5 +23,4 @@ if [ "$(uname)" == "Darwin" ]; then
tmutil thinlocalsnapshots / &> /dev/null
fi
# Update path
cargo run -r -- "$HOME/Developer/bitcoin"
eval $(echo "cargo run -r -- $(cat node.args)")
+15 -9
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 })
},
+5 -4
View File
@@ -4,19 +4,20 @@ use itertools::Itertools;
use parser::{iter_blocks, log, BitcoinDB, BitcoinDaemon};
fn main() -> color_eyre::Result<()> {
let args = args().collect_vec();
let bitcoin_dir_path = args.get(1).unwrap();
let mut args = args().collect_vec();
let bitcoin_dir_path = args.get(1).unwrap().to_owned();
args.drain(0..2);
color_eyre::install()?;
let deamon = BitcoinDaemon::new(bitcoin_dir_path);
let deamon = BitcoinDaemon::new(bitcoin_dir_path.to_owned(), args);
loop {
deamon.stop();
// Scoped to free bitcoin's lock
let block_count = {
let bitcoin_db = BitcoinDB::new(Path::new(bitcoin_dir_path), true)?;
let bitcoin_db = BitcoinDB::new(Path::new(&bitcoin_dir_path), true)?;
// let block_count = 200_000;
let block_count = bitcoin_db.get_block_count();