Added a working btc-rpc client, works with a running local signet node
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
use bitcoincore_rpc::{Auth, Client, RpcApi};
|
||||
|
||||
pub fn client() {
|
||||
let rpc = Client::new(
|
||||
"http://localhost:8332",
|
||||
Auth::UserPass(
|
||||
"<FILL RPC USERNAME>".to_string(),
|
||||
"<FILL RPC PASSWORD>".to_string(),
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let best_block_hash = rpc.get_best_block_hash().unwrap();
|
||||
println!("best block hash: {}", best_block_hash);
|
||||
}
|
||||
27
side-node/src/clients/btc_rpc.rs
Normal file
27
side-node/src/clients/btc_rpc.rs
Normal 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:?} ");
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
pub mod btc;
|
||||
pub mod btc_rpc;
|
||||
pub mod websocket;
|
||||
|
||||
@@ -31,7 +31,7 @@ pub async fn run() {
|
||||
node.start().await;
|
||||
}
|
||||
Some(Commands::Btc {}) => {
|
||||
println!("BTC command not yet implemented.");
|
||||
clients::btc_rpc::client();
|
||||
}
|
||||
None => println!("No command provided. Exiting. See --help for more information."),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user