Skip to content

Commit

Permalink
Merge #10: Support cookie-based RPC authentication (Bitcoin Core)
Browse files Browse the repository at this point in the history
d86f29f Support cookie-based RPC authentication (Bitcoin Core) (Sebastian Falbesoner)

Tree-SHA512: 7bb23f09e1f0ebbc737b937000f0bac6950f541924f67e823548c4be98311fa21e48f97e1a0e1a0117802f48d4dbb3f59e236e1da3460c0582934d6874cc0dfe
  • Loading branch information
chris-belcher committed Jan 21, 2021
2 parents 3b06de2 + d86f29f commit ebcba6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ futures = "0.3"
rand = "0.7.3"
itertools = "0.9.0"
structopt = "0.3.21"
dirs = "3.0.1"
21 changes: 15 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use dirs::home_dir;
use std::io;
use std::sync::{Arc, RwLock};
use std::path::PathBuf;
Expand Down Expand Up @@ -83,12 +84,20 @@ fn recover_wallet(wallet_file_name: &PathBuf) -> std::io::Result<()> {

fn get_bitcoin_rpc() -> Result<Client, Error> {
//TODO put all this in a config file
let auth = Auth::UserPass(
"regtestrpcuser".to_string(),
"regtestrpcpass".to_string(),
//"btcrpcuser".to_string(),
//"btcrpcpass".to_string()
);
const RPC_CREDENTIALS: Option<(&str, &str)> =
Some(("regtestrpcuser", "regtestrpcpass"));
//Some(("btcrpcuser", "btcrpcpass"));
//None; // use Bitcoin Core cookie-based authentication

let auth = match RPC_CREDENTIALS {
Some((user, pass)) => Auth::UserPass(user.to_string(), pass.to_string()),
None => {
//TODO this currently only works for Linux and regtest,
// also support other OSes (Windows, MacOS...) and networks
let data_dir = home_dir().unwrap().join(".bitcoin");
Auth::CookieFile(data_dir.join("regtest").join(".cookie"))
},
};
let rpc = Client::new(
"http://localhost:18443/wallet/teleport"
//"http://localhost:18332/wallet/teleport"
Expand Down

0 comments on commit ebcba6c

Please sign in to comment.