mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
global: snapshot
This commit is contained in:
@@ -1,19 +1,14 @@
|
||||
use std::path::Path;
|
||||
|
||||
use bitcoincore_rpc::RpcApi;
|
||||
use brk_rpc::{Auth, Client};
|
||||
|
||||
fn main() {
|
||||
brk_logger::init(None).unwrap();
|
||||
|
||||
let bitcoin_dir = Path::new(&std::env::var("HOME").unwrap())
|
||||
.join("Library")
|
||||
.join("Application Support")
|
||||
.join("Bitcoin");
|
||||
let bitcoin_dir = Client::default_bitcoin_path();
|
||||
|
||||
let auth = Auth::CookieFile(bitcoin_dir.join(".cookie"));
|
||||
|
||||
let client = Client::new("http://localhost:8332", auth).unwrap();
|
||||
let client = Client::new(Client::default_url(), auth).unwrap();
|
||||
|
||||
loop {
|
||||
println!("{:?}", client.call(|c| c.get_block_count()).unwrap());
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::thread::sleep;
|
||||
use std::{mem, sync::Arc, time::Duration};
|
||||
|
||||
@@ -270,4 +272,27 @@ impl Client {
|
||||
{
|
||||
self.0.call_once(f)
|
||||
}
|
||||
|
||||
pub fn default_url() -> &'static str {
|
||||
"http://localhost:8332"
|
||||
}
|
||||
|
||||
pub fn default_bitcoin_path() -> PathBuf {
|
||||
if env::consts::OS == "macos" {
|
||||
Self::default_mac_bitcoin_path()
|
||||
} else {
|
||||
Self::default_linux_bitcoin_path()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_linux_bitcoin_path() -> PathBuf {
|
||||
Path::new(&env::var("HOME").unwrap()).join(".bitcoin")
|
||||
}
|
||||
|
||||
pub fn default_mac_bitcoin_path() -> PathBuf {
|
||||
Path::new(&env::var("HOME").unwrap())
|
||||
.join("Library")
|
||||
.join("Application Support")
|
||||
.join("Bitcoin")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user