Bit of cleanup after all the excitement
This commit is contained in:
@@ -1,25 +1,12 @@
|
|||||||
use crate::{keys, utils};
|
use crate::{keys, utils};
|
||||||
|
|
||||||
use bdk::bitcoin::base64;
|
use bdk::bitcoin::psbt::PartiallySignedTransaction;
|
||||||
use bdk::bitcoin::psbt::{PartiallySignedTransaction, Psbt};
|
use bdk::blockchain::Blockchain;
|
||||||
use bdk::blockchain::{Blockchain, Progress};
|
|
||||||
use bdk::database::MemoryDatabase;
|
use bdk::database::MemoryDatabase;
|
||||||
use bdk::wallet::AddressIndex::{self, New};
|
use bdk::wallet::AddressIndex::{self, New};
|
||||||
use bdk::wallet::AddressInfo;
|
use bdk::wallet::AddressInfo;
|
||||||
use bdk::{blockchain::ElectrumBlockchain, electrum_client, SyncOptions};
|
use bdk::{blockchain::ElectrumBlockchain, electrum_client, SyncOptions};
|
||||||
use bdk::{FeeRate, SignOptions, TransactionDetails, Wallet};
|
use bdk::{FeeRate, SignOptions, TransactionDetails, Wallet};
|
||||||
use toml::to_string;
|
|
||||||
use tracing::field::display;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct CustomProgress;
|
|
||||||
|
|
||||||
impl Progress for CustomProgress {
|
|
||||||
fn update(&self, progress: f32, message: Option<String>) -> Result<(), bdk::Error> {
|
|
||||||
println!("Progress: {} - {:?}", progress, message);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn run() -> Result<(), anyhow::Error> {
|
pub async fn run() -> Result<(), anyhow::Error> {
|
||||||
let dave = utils::home(&"dave".to_string());
|
let dave = utils::home(&"dave".to_string());
|
||||||
@@ -27,11 +14,6 @@ pub async fn run() -> Result<(), anyhow::Error> {
|
|||||||
let dave_wallet = keys::bitcoin::load_from_file(&dave).unwrap();
|
let dave_wallet = keys::bitcoin::load_from_file(&dave).unwrap();
|
||||||
let sammy_wallet = keys::bitcoin::load_from_file(&sammy).unwrap();
|
let sammy_wallet = keys::bitcoin::load_from_file(&sammy).unwrap();
|
||||||
|
|
||||||
// Verify explicitly that the address is derived as expected
|
|
||||||
let dave_expected_address = "tb1q88e45m4akrg2y00n4077vn90q8qw0svz7dss6k";
|
|
||||||
let derived_address = dave_wallet.get_address(AddressIndex::Peek(0))?.to_string();
|
|
||||||
assert_eq!(dave_expected_address, derived_address);
|
|
||||||
|
|
||||||
let dave_address = dave_wallet.get_address(AddressIndex::Peek(0))?.to_string();
|
let dave_address = dave_wallet.get_address(AddressIndex::Peek(0))?.to_string();
|
||||||
let sammy_address = sammy_wallet.get_address(AddressIndex::Peek(0))?.to_string();
|
let sammy_address = sammy_wallet.get_address(AddressIndex::Peek(0))?.to_string();
|
||||||
|
|
||||||
@@ -51,16 +33,14 @@ pub async fn run() -> Result<(), anyhow::Error> {
|
|||||||
let (mut psbt, details) =
|
let (mut psbt, details) =
|
||||||
build_sending_tx(&dave_wallet, sammy_wallet.get_address(New)?).expect("psbt build error");
|
build_sending_tx(&dave_wallet, sammy_wallet.get_address(New)?).expect("psbt build error");
|
||||||
|
|
||||||
println!("Transaction details: {:#?}", details);
|
println!("About to sign the transaction: {:?}", details);
|
||||||
println!("Unsigned PSBT: {}", base64::encode(psbt.serialize()));
|
|
||||||
|
|
||||||
let finalized = dave_wallet.sign(&mut psbt, SignOptions::default())?;
|
dave_wallet.sign(&mut psbt, SignOptions::default())?;
|
||||||
println!("Finalized: {}", finalized);
|
let signed_tx = psbt.extract_tx();
|
||||||
|
|
||||||
let tx_id = blockchain
|
println!("Broadcasting...");
|
||||||
.broadcast(&psbt.extract_tx())
|
blockchain.broadcast(&signed_tx).expect("broadcast error");
|
||||||
.expect("broadcast error");
|
println!("Transaction ID: {:?}", signed_tx.txid());
|
||||||
println!("Transaction ID: {:?}", tx_id);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -12,6 +12,7 @@ const SEND_AMOUNT: Amount = Amount::from_sat(5000);
|
|||||||
const STOP_GAP: usize = 50;
|
const STOP_GAP: usize = 50;
|
||||||
const PARALLEL_REQUESTS: usize = 5;
|
const PARALLEL_REQUESTS: usize = 5;
|
||||||
|
|
||||||
|
/// Demonstrates the use of bdk with the Esplora client.
|
||||||
pub async fn run() -> Result<(), anyhow::Error> {
|
pub async fn run() -> Result<(), anyhow::Error> {
|
||||||
let db_path = "/tmp/bdk-esplora-async-example.sqlite";
|
let db_path = "/tmp/bdk-esplora-async-example.sqlite";
|
||||||
let conn = Connection::open(db_path)?;
|
let conn = Connection::open(db_path)?;
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
pub mod btc_other_rpc;
|
pub mod btc_electrum_client;
|
||||||
pub mod btc_rpc;
|
pub mod btc_esplora_client;
|
||||||
pub mod test;
|
|
||||||
pub mod websocket;
|
pub mod websocket;
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
use anyhow::Result;
|
|
||||||
use reqwest::blocking::Client;
|
|
||||||
|
|
||||||
pub async fn run() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
// Set up the Esplora client
|
|
||||||
let esplora_url = "https://blockstream.info/signet/api";
|
|
||||||
let client = Client::new();
|
|
||||||
|
|
||||||
// Address to check
|
|
||||||
let address = "tb1q88e45m4akrg2y00n4077vn90q8qw0svz7dss6k";
|
|
||||||
|
|
||||||
// Query balance
|
|
||||||
let url = format!("{}/address/{}/utxo", esplora_url, address);
|
|
||||||
let response = client.get(&url).send()?.text()?;
|
|
||||||
|
|
||||||
println!("UTXO for address: {}", response);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -31,7 +31,7 @@ pub async fn run() {
|
|||||||
node.start().await;
|
node.start().await;
|
||||||
}
|
}
|
||||||
Some(Commands::Btc {}) => {
|
Some(Commands::Btc {}) => {
|
||||||
let _ = clients::btc_other_rpc::run().await;
|
let _ = clients::btc_electrum_client::run().await;
|
||||||
}
|
}
|
||||||
None => println!("No command provided. Exiting. See --help for more information."),
|
None => println!("No command provided. Exiting. See --help for more information."),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user