Going to try out the bdk
This commit is contained in:
@@ -1,74 +1,3 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use bitcoin::{address::NetworkUnchecked, key::Secp256k1, Address, Amount};
|
||||
use bitcoincore_rpc::{Auth, Client, RpcApi};
|
||||
|
||||
use crate::{keys, utils};
|
||||
|
||||
pub fn run(wallet_name: &str) {
|
||||
let rpc = client_for(wallet_name);
|
||||
let name = rpc.get_wallet_info().unwrap().wallet_name;
|
||||
println!("Wallet name: {name}");
|
||||
let balance = rpc.get_balance(None, None).unwrap();
|
||||
let address = get_default_address(rpc);
|
||||
let account = rpc.generate_to_address(block_num, address);
|
||||
println!("account {account:?} has balance {balance:?}");
|
||||
|
||||
// let sammy = Address::from_str("tb1qtd5e44gf6eqqdknymaydqyvw6869fda32w3l06").unwrap();
|
||||
// let amount = Amount::from_sat(1000);
|
||||
// let sammy = parse_and_validate_address(sammy).unwrap();
|
||||
// transfer_funds(rpc, amount, sammy);
|
||||
}
|
||||
|
||||
// fn login(rpc: Client, wallet_name: &str) {
|
||||
// let passphrase = serde_json::Value::from_str("password").unwrap();
|
||||
// rpc.call("walletpassphrase", &[passphrase]).unwrap();
|
||||
// }
|
||||
|
||||
fn get_default_address(rpc: Client) -> Address {
|
||||
let address = rpc.generate_to_address(None, None).unwrap();
|
||||
println!("Default address: {address:?}");
|
||||
parse_and_validate_address(address).unwrap()
|
||||
}
|
||||
|
||||
fn get_info(rpc: Client) {
|
||||
let info = rpc.get_wallet_info().unwrap();
|
||||
println!("Wallet info: {info:?}");
|
||||
}
|
||||
|
||||
fn parse_and_validate_address(
|
||||
address: bitcoin::Address<NetworkUnchecked>,
|
||||
) -> Result<bitcoin::Address, bitcoin::address::ParseError> {
|
||||
let require_network = address.require_network(bitcoin::Network::Signet);
|
||||
let address = require_network?;
|
||||
Ok(address)
|
||||
}
|
||||
|
||||
fn transfer_funds(rpc: Client, amount: Amount, to: Address) {
|
||||
rpc.send_to_address(&to, amount, None, None, None, None, None, None)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn client_for(wallet_name: &str) -> Client {
|
||||
let rpc = Client::new(
|
||||
"http://127.0.0.1:38332",
|
||||
Auth::UserPass("dave".to_string(), "password".to_string()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
if !rpc
|
||||
.list_wallets()
|
||||
.unwrap()
|
||||
.contains(&wallet_name.to_string())
|
||||
{
|
||||
rpc.load_wallet(wallet_name).unwrap();
|
||||
}
|
||||
|
||||
rpc.list_wallets().unwrap().iter().for_each(|wallet| {
|
||||
if wallet != wallet_name {
|
||||
rpc.unload_wallet(Some(wallet)).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
rpc
|
||||
pub fn run(name: &str) {
|
||||
println!("running btc_rpc...");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user