Added a working btc-rpc client, works with a running local signet node

This commit is contained in:
Dave Hrycyszyn
2024-06-20 19:46:56 +01:00
parent 13e144f19e
commit c5a6aeb067
4 changed files with 29 additions and 16 deletions

View File

@@ -0,0 +1,27 @@
use std::str::FromStr;
use bitcoincore_rpc::{Auth, Client, RpcApi};
fn parse_and_validate_address(
address: &str,
network: bitcoin::Network,
) -> Result<bitcoin::Address, bitcoin::address::ParseError> {
let address = address
.parse::<bitcoin::Address<_>>()?
.require_network(network)?;
Ok(address)
}
pub fn client() {
let rpc = Client::new(
"http://127.0.0.1:38332",
Auth::UserPass("dave".to_string(), "password".to_string()),
)
.unwrap();
let a = "tb1p4dvr6dzszagw34scnr6kde0dr2yrmu6gew9faza788rmqy3d645sdm9e50";
let address = parse_and_validate_address(a, bitcoin::Network::Signet).unwrap();
let info = rpc.get_address_info(&address).unwrap();
println!("info {info:?} ");
}