Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ workspace = true
bitcoin = { version = "0.32.0", default-features = false }
bdk_core = { path = "../core", version = "0.6.2", default-features = false }
serde = { version = "1", optional = true, features = ["derive", "rc"] }
miniscript = { version = "12.3.1", optional = true, default-features = false }
miniscript = { git = "https://github.com/rust-bitcoin/rust-miniscript.git", branch = "release-12.x", optional = true, default-features = false }

# Feature dependencies
rusqlite = { version = "0.31.0", features = ["bundled"], optional = true }
Expand Down
1 change: 1 addition & 0 deletions crates/esplora/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bdk_core = { path = "../core", version = "0.6.1", default-features = false }
esplora-client = { version = "0.12.1", default-features = false }
async-trait = { version = "0.1.66", optional = true }
futures = { version = "0.3.26", optional = true }
serde_json = { version = "1.0", features = ["alloc"] }

[dev-dependencies]
esplora-client = { version = "0.12.0" }
Expand Down
2 changes: 1 addition & 1 deletion examples/example_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ anyhow = "1"
clap = { version = "4.5.17", features = ["derive", "env"] }
rand = "0.8"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"
serde_json = { version = "1.0", features = ["alloc"] }
29 changes: 8 additions & 21 deletions examples/example_cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bdk_chain::keychain_txout::DEFAULT_LOOKAHEAD;
use bdk_chain::miniscript::descriptor::KeyMapWrapper;
use serde_json::json;
use std::cmp;
use std::collections::HashMap;
use std::env;
use std::fmt;
use std::str::FromStr;
Expand All @@ -11,11 +11,10 @@ use anyhow::bail;
use anyhow::Context;
use bdk_chain::bitcoin::{
absolute, address::NetworkUnchecked, bip32, consensus, constants, hex::DisplayHex, relative,
secp256k1::Secp256k1, transaction, Address, Amount, Network, NetworkKind, PrivateKey, Psbt,
PublicKey, Sequence, Transaction, TxIn, TxOut,
secp256k1::Secp256k1, transaction, Address, Amount, Network, NetworkKind, Psbt, Sequence,
Transaction, TxIn, TxOut,
};
use bdk_chain::miniscript::{
descriptor::{DescriptorSecretKey, SinglePubKey},
plan::{Assets, Plan},
psbt::PsbtExt,
Descriptor, DescriptorPublicKey, ForEachKey,
Expand Down Expand Up @@ -696,27 +695,15 @@ pub fn handle_commands<CS: clap::Subcommand, S: clap::Args>(

let secp = Secp256k1::new();
let (_, keymap) = Descriptor::parse_descriptor(&secp, &desc_str)?;

if keymap.is_empty() {
bail!("unable to sign")
}

// note: we're only looking at the first entry in the keymap
// the idea is to find something that impls `GetKey`
let sign_res = match keymap.iter().next().expect("not empty") {
(DescriptorPublicKey::Single(single_pub), DescriptorSecretKey::Single(prv)) => {
let pk = match single_pub.key {
SinglePubKey::FullKey(pk) => pk,
SinglePubKey::XOnly(_) => unimplemented!("single xonly pubkey"),
};
let keys: HashMap<PublicKey, PrivateKey> = [(pk, prv.key)].into();
psbt.sign(&keys, &secp)
}
(_, DescriptorSecretKey::XPrv(k)) => psbt.sign(&k.xkey, &secp),
_ => unimplemented!("multi xkey signer"),
};

let _ =
sign_res.map_err(|errors| anyhow::anyhow!("failed to sign PSBT {errors:?}"))?;
let keymap_wrapper: KeyMapWrapper = keymap.into();
let _sign_res = psbt
.sign(&keymap_wrapper, &secp)
.map_err(|errors| anyhow::anyhow!("failed to sign PSBT {errors:?}"))?;

let mut obj = serde_json::Map::new();
obj.insert("psbt".to_string(), json!(psbt.to_string()));
Expand Down
Loading