From: Alekos Filini Date: Fri, 4 Sep 2020 13:45:11 +0000 (+0200) Subject: Write more docs, make `TxBuilder::with_recipients` take Scripts X-Git-Tag: 0.1.0-beta.1~3 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/struct.CommandStringError.html?a=commitdiff_plain;h=2e080fb31f9b745e4d4b77af82c70847c74cb4af;p=bdk-cli Write more docs, make `TxBuilder::with_recipients` take Scripts --- diff --git a/examples/repl.rs b/examples/repl.rs index 8e8b38e..2756d2d 100644 --- a/examples/repl.rs +++ b/examples/repl.rs @@ -37,10 +37,10 @@ use log::{debug, error, info, trace, LevelFilter}; use bitcoin::Network; use magical_bitcoin_wallet::bitcoin; -use magical_bitcoin_wallet::blockchain::ElectrumBlockchain; +use magical_bitcoin_wallet::blockchain::compact_filters::*; use magical_bitcoin_wallet::cli; use magical_bitcoin_wallet::sled; -use magical_bitcoin_wallet::{Client, Wallet}; +use magical_bitcoin_wallet::Wallet; fn prepare_home_dir() -> PathBuf { let mut dir = PathBuf::new(); @@ -88,19 +88,17 @@ fn main() { .unwrap(); debug!("database opened successfully"); - let client = Client::new( - matches.value_of("server").unwrap(), - matches.value_of("proxy"), - ) - .unwrap(); - let wallet = Wallet::new( - descriptor, - change_descriptor, - network, - tree, - ElectrumBlockchain::from(client), - ) - .unwrap(); + let num_threads = 1; + + let mempool = Arc::new(Mempool::default()); + let peers = (0..num_threads) + .map(|_| Peer::connect("192.168.1.136:8333", Arc::clone(&mempool), Network::Bitcoin)) + .collect::>() + .unwrap(); + let blockchain = + CompactFiltersBlockchain::new(peers, "./wallet-filters", Some(500_000)).unwrap(); + + let wallet = Wallet::new(descriptor, change_descriptor, network, tree, blockchain).unwrap(); let wallet = Arc::new(wallet); if let Some(_sub_matches) = matches.subcommand_matches("repl") { diff --git a/src/cli.rs b/src/cli.rs index 51c56ef..e09fedd 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -33,14 +33,14 @@ use log::{debug, error, info, trace, LevelFilter}; use bitcoin::consensus::encode::{deserialize, serialize, serialize_hex}; use bitcoin::hashes::hex::FromHex; use bitcoin::util::psbt::PartiallySignedTransaction; -use bitcoin::{Address, OutPoint, Txid}; +use bitcoin::{Address, OutPoint, Script, Txid}; use crate::blockchain::log_progress; use crate::error::Error; use crate::types::ScriptType; use crate::{FeeRate, TxBuilder, Wallet}; -fn parse_recipient(s: &str) -> Result<(Address, u64), String> { +fn parse_recipient(s: &str) -> Result<(Script, u64), String> { let parts: Vec<_> = s.split(":").collect(); if parts.len() != 2 { return Err("Invalid format".to_string()); @@ -55,7 +55,7 @@ fn parse_recipient(s: &str) -> Result<(Address, u64), String> { return Err(format!("{:?}", e)); } - Ok((addr.unwrap(), val.unwrap())) + Ok((addr.unwrap().script_pubkey(), val.unwrap())) } fn parse_outpoint(s: &str) -> Result {