refactor: use byref in udl instead of arc when possible

This commit is contained in:
thunderbiscuit 2023-12-14 13:37:00 -05:00
parent a1a45996fc
commit bcb77c45f4
No known key found for this signature in database
GPG Key ID: 88253696EB836462
5 changed files with 62 additions and 72 deletions

View File

@ -100,7 +100,7 @@ interface Wallet {
Balance get_balance(); Balance get_balance();
boolean is_mine(Script script); boolean is_mine([ByRef] Script script);
[Throws=BdkError] [Throws=BdkError]
void apply_update(Update update); void apply_update(Update update);
@ -118,7 +118,7 @@ interface Update {};
interface TxBuilder { interface TxBuilder {
constructor(); constructor();
TxBuilder add_recipient(Script script, u64 amount); TxBuilder add_recipient([ByRef] Script script, u64 amount);
TxBuilder set_recipients(sequence<ScriptAmount> recipients); TxBuilder set_recipients(sequence<ScriptAmount> recipients);
@ -142,7 +142,7 @@ interface TxBuilder {
TxBuilder drain_wallet(); TxBuilder drain_wallet();
TxBuilder drain_to(Script script); TxBuilder drain_to([ByRef] Script script);
TxBuilder enable_rbf(); TxBuilder enable_rbf();
@ -187,16 +187,16 @@ interface DerivationPath {
}; };
interface DescriptorSecretKey { interface DescriptorSecretKey {
constructor(Network network, Mnemonic mnemonic, string? password); constructor(Network network, [ByRef] Mnemonic mnemonic, string? password);
[Name=from_string, Throws=BdkError] [Name=from_string, Throws=BdkError]
constructor(string secret_key); constructor(string secret_key);
[Throws=BdkError] [Throws=BdkError]
DescriptorSecretKey derive(DerivationPath path); DescriptorSecretKey derive([ByRef] DerivationPath path);
[Throws=BdkError] [Throws=BdkError]
DescriptorSecretKey extend(DerivationPath path); DescriptorSecretKey extend([ByRef] DerivationPath path);
DescriptorPublicKey as_public(); DescriptorPublicKey as_public();
@ -210,10 +210,10 @@ interface DescriptorPublicKey {
constructor(string public_key); constructor(string public_key);
[Throws=BdkError] [Throws=BdkError]
DescriptorPublicKey derive(DerivationPath path); DescriptorPublicKey derive([ByRef] DerivationPath path);
[Throws=BdkError] [Throws=BdkError]
DescriptorPublicKey extend(DerivationPath path); DescriptorPublicKey extend([ByRef] DerivationPath path);
string as_string(); string as_string();
}; };
@ -223,28 +223,28 @@ interface Descriptor {
constructor(string descriptor, Network network); constructor(string descriptor, Network network);
[Name=new_bip44] [Name=new_bip44]
constructor(DescriptorSecretKey secret_key, KeychainKind keychain, Network network); constructor([ByRef] DescriptorSecretKey secret_key, KeychainKind keychain, Network network);
[Name=new_bip44_public] [Name=new_bip44_public]
constructor(DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network); constructor([ByRef] DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);
[Name=new_bip49] [Name=new_bip49]
constructor(DescriptorSecretKey secret_key, KeychainKind keychain, Network network); constructor([ByRef] DescriptorSecretKey secret_key, KeychainKind keychain, Network network);
[Name=new_bip49_public] [Name=new_bip49_public]
constructor(DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network); constructor([ByRef] DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);
[Name=new_bip84] [Name=new_bip84]
constructor(DescriptorSecretKey secret_key, KeychainKind keychain, Network network); constructor([ByRef] DescriptorSecretKey secret_key, KeychainKind keychain, Network network);
[Name=new_bip84_public] [Name=new_bip84_public]
constructor(DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network); constructor([ByRef] DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);
[Name=new_bip86] [Name=new_bip86]
constructor(DescriptorSecretKey secret_key, KeychainKind keychain, Network network); constructor([ByRef] DescriptorSecretKey secret_key, KeychainKind keychain, Network network);
[Name=new_bip86_public] [Name=new_bip86_public]
constructor(DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network); constructor([ByRef] DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);
string as_string(); string as_string();
@ -262,7 +262,7 @@ interface EsploraClient {
Update scan(Wallet wallet, u64 stop_gap, u64 parallel_requests); Update scan(Wallet wallet, u64 stop_gap, u64 parallel_requests);
[Throws=BdkError] [Throws=BdkError]
void broadcast(Transaction transaction); void broadcast([ByRef] Transaction transaction);
}; };
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------

View File

@ -15,7 +15,6 @@ use bdk::Error as BdkError;
use bdk::KeychainKind; use bdk::KeychainKind;
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc;
#[derive(Debug)] #[derive(Debug)]
pub struct Descriptor { pub struct Descriptor {
@ -35,7 +34,7 @@ impl Descriptor {
} }
pub(crate) fn new_bip44( pub(crate) fn new_bip44(
secret_key: Arc<DescriptorSecretKey>, secret_key: &DescriptorSecretKey,
keychain_kind: KeychainKind, keychain_kind: KeychainKind,
network: Network, network: Network,
) -> Self { ) -> Self {
@ -62,7 +61,7 @@ impl Descriptor {
} }
pub(crate) fn new_bip44_public( pub(crate) fn new_bip44_public(
public_key: Arc<DescriptorPublicKey>, public_key: &DescriptorPublicKey,
fingerprint: String, fingerprint: String,
keychain_kind: KeychainKind, keychain_kind: KeychainKind,
network: Network, network: Network,
@ -93,7 +92,7 @@ impl Descriptor {
} }
pub(crate) fn new_bip49( pub(crate) fn new_bip49(
secret_key: Arc<DescriptorSecretKey>, secret_key: &DescriptorSecretKey,
keychain_kind: KeychainKind, keychain_kind: KeychainKind,
network: Network, network: Network,
) -> Self { ) -> Self {
@ -120,7 +119,7 @@ impl Descriptor {
} }
pub(crate) fn new_bip49_public( pub(crate) fn new_bip49_public(
public_key: Arc<DescriptorPublicKey>, public_key: &DescriptorPublicKey,
fingerprint: String, fingerprint: String,
keychain_kind: KeychainKind, keychain_kind: KeychainKind,
network: Network, network: Network,
@ -151,7 +150,7 @@ impl Descriptor {
} }
pub(crate) fn new_bip84( pub(crate) fn new_bip84(
secret_key: Arc<DescriptorSecretKey>, secret_key: &DescriptorSecretKey,
keychain_kind: KeychainKind, keychain_kind: KeychainKind,
network: Network, network: Network,
) -> Self { ) -> Self {
@ -178,7 +177,7 @@ impl Descriptor {
} }
pub(crate) fn new_bip84_public( pub(crate) fn new_bip84_public(
public_key: Arc<DescriptorPublicKey>, public_key: &DescriptorPublicKey,
fingerprint: String, fingerprint: String,
keychain_kind: KeychainKind, keychain_kind: KeychainKind,
network: Network, network: Network,
@ -209,7 +208,7 @@ impl Descriptor {
} }
pub(crate) fn new_bip86( pub(crate) fn new_bip86(
secret_key: Arc<DescriptorSecretKey>, secret_key: &DescriptorSecretKey,
keychain_kind: KeychainKind, keychain_kind: KeychainKind,
network: Network, network: Network,
) -> Self { ) -> Self {
@ -236,7 +235,7 @@ impl Descriptor {
} }
pub(crate) fn new_bip86_public( pub(crate) fn new_bip86_public(
public_key: Arc<DescriptorPublicKey>, public_key: &DescriptorPublicKey,
fingerprint: String, fingerprint: String,
keychain_kind: KeychainKind, keychain_kind: KeychainKind,
network: Network, network: Network,
@ -288,83 +287,73 @@ mod test {
use bdk::descriptor::DescriptorError::Key; use bdk::descriptor::DescriptorError::Key;
use bdk::keys::KeyError::InvalidNetwork; use bdk::keys::KeyError::InvalidNetwork;
use std::sync::Arc;
fn get_descriptor_secret_key() -> DescriptorSecretKey { fn get_descriptor_secret_key() -> DescriptorSecretKey {
let mnemonic = Mnemonic::from_string("chaos fabric time speed sponsor all flat solution wisdom trophy crack object robot pave observe combine where aware bench orient secret primary cable detect".to_string()).unwrap(); let mnemonic = Mnemonic::from_string("chaos fabric time speed sponsor all flat solution wisdom trophy crack object robot pave observe combine where aware bench orient secret primary cable detect".to_string()).unwrap();
DescriptorSecretKey::new(Network::Testnet, Arc::new(mnemonic), None) DescriptorSecretKey::new(Network::Testnet, &mnemonic, None)
} }
#[test] #[test]
fn test_descriptor_templates() { fn test_descriptor_templates() {
let master: Arc<DescriptorSecretKey> = Arc::new(get_descriptor_secret_key()); let master: DescriptorSecretKey = get_descriptor_secret_key();
println!("Master: {:?}", master.as_string()); println!("Master: {:?}", master.as_string());
// tprv8ZgxMBicQKsPdWuqM1t1CDRvQtQuBPyfL6GbhQwtxDKgUAVPbxmj71pRA8raTqLrec5LyTs5TqCxdABcZr77bt2KyWA5bizJHnC4g4ysm4h // tprv8ZgxMBicQKsPdWuqM1t1CDRvQtQuBPyfL6GbhQwtxDKgUAVPbxmj71pRA8raTqLrec5LyTs5TqCxdABcZr77bt2KyWA5bizJHnC4g4ysm4h
let handmade_public_44 = master let handmade_public_44 = master
.derive(Arc::new( .derive(&DerivationPath::new("m/44h/1h/0h".to_string()).unwrap())
DerivationPath::new("m/44h/1h/0h".to_string()).unwrap(),
))
.unwrap() .unwrap()
.as_public(); .as_public();
println!("Public 44: {}", handmade_public_44.as_string()); println!("Public 44: {}", handmade_public_44.as_string());
// Public 44: [d1d04177/44'/1'/0']tpubDCoPjomfTqh1e7o1WgGpQtARWtkueXQAepTeNpWiitS3Sdv8RKJ1yvTrGHcwjDXp2SKyMrTEca4LoN7gEUiGCWboyWe2rz99Kf4jK4m2Zmx/* // Public 44: [d1d04177/44'/1'/0']tpubDCoPjomfTqh1e7o1WgGpQtARWtkueXQAepTeNpWiitS3Sdv8RKJ1yvTrGHcwjDXp2SKyMrTEca4LoN7gEUiGCWboyWe2rz99Kf4jK4m2Zmx/*
let handmade_public_49 = master let handmade_public_49 = master
.derive(Arc::new( .derive(&DerivationPath::new("m/49h/1h/0h".to_string()).unwrap())
DerivationPath::new("m/49h/1h/0h".to_string()).unwrap(),
))
.unwrap() .unwrap()
.as_public(); .as_public();
println!("Public 49: {}", handmade_public_49.as_string()); println!("Public 49: {}", handmade_public_49.as_string());
// Public 49: [d1d04177/49'/1'/0']tpubDC65ZRvk1NDddHrVAUAZrUPJ772QXzooNYmPywYF9tMyNLYKf5wpKE7ZJvK9kvfG3FV7rCsHBNXy1LVKW95jrmC7c7z4hq7a27aD2sRrAhR/* // Public 49: [d1d04177/49'/1'/0']tpubDC65ZRvk1NDddHrVAUAZrUPJ772QXzooNYmPywYF9tMyNLYKf5wpKE7ZJvK9kvfG3FV7rCsHBNXy1LVKW95jrmC7c7z4hq7a27aD2sRrAhR/*
let handmade_public_84 = master let handmade_public_84 = master
.derive(Arc::new( .derive(&DerivationPath::new("m/84h/1h/0h".to_string()).unwrap())
DerivationPath::new("m/84h/1h/0h".to_string()).unwrap(),
))
.unwrap() .unwrap()
.as_public(); .as_public();
println!("Public 84: {}", handmade_public_84.as_string()); println!("Public 84: {}", handmade_public_84.as_string());
// Public 84: [d1d04177/84'/1'/0']tpubDDNxbq17egjFk2edjv8oLnzxk52zny9aAYNv9CMqTzA4mQDiQq818sEkNe9Gzmd4QU8558zftqbfoVBDQorG3E4Wq26tB2JeE4KUoahLkx6/* // Public 84: [d1d04177/84'/1'/0']tpubDDNxbq17egjFk2edjv8oLnzxk52zny9aAYNv9CMqTzA4mQDiQq818sEkNe9Gzmd4QU8558zftqbfoVBDQorG3E4Wq26tB2JeE4KUoahLkx6/*
let handmade_public_86 = master let handmade_public_86 = master
.derive(Arc::new( .derive(&DerivationPath::new("m/86h/1h/0h".to_string()).unwrap())
DerivationPath::new("m/86h/1h/0h".to_string()).unwrap(),
))
.unwrap() .unwrap()
.as_public(); .as_public();
println!("Public 86: {}", handmade_public_86.as_string()); println!("Public 86: {}", handmade_public_86.as_string());
// Public 86: [d1d04177/86'/1'/0']tpubDCJzjbcGbdEfXMWaL6QmgVmuSfXkrue7m2YNoacWwyc7a2XjXaKojRqNEbo41CFL3PyYmKdhwg2fkGpLX4SQCbQjCGxAkWHJTw9WEeenrJb/* // Public 86: [d1d04177/86'/1'/0']tpubDCJzjbcGbdEfXMWaL6QmgVmuSfXkrue7m2YNoacWwyc7a2XjXaKojRqNEbo41CFL3PyYmKdhwg2fkGpLX4SQCbQjCGxAkWHJTw9WEeenrJb/*
let template_private_44 = let template_private_44 =
Descriptor::new_bip44(master.clone(), KeychainKind::External, Network::Testnet); Descriptor::new_bip44(&master, KeychainKind::External, Network::Testnet);
let template_private_49 = let template_private_49 =
Descriptor::new_bip49(master.clone(), KeychainKind::External, Network::Testnet); Descriptor::new_bip49(&master, KeychainKind::External, Network::Testnet);
let template_private_84 = let template_private_84 =
Descriptor::new_bip84(master.clone(), KeychainKind::External, Network::Testnet); Descriptor::new_bip84(&master, KeychainKind::External, Network::Testnet);
let template_private_86 = let template_private_86 =
Descriptor::new_bip86(master, KeychainKind::External, Network::Testnet); Descriptor::new_bip86(&master, KeychainKind::External, Network::Testnet);
// the extended public keys are the same when creating them manually as they are with the templates // the extended public keys are the same when creating them manually as they are with the templates
println!("Template 49: {}", template_private_49.as_string()); println!("Template 49: {}", template_private_49.as_string());
println!("Template 44: {}", template_private_44.as_string()); println!("Template 44: {}", template_private_44.as_string());
println!("Template 84: {}", template_private_84.as_string()); println!("Template 84: {}", template_private_84.as_string());
println!("Template 86: {}", template_private_86.as_string()); println!("Template 86: {}", template_private_86.as_string());
let template_public_44 = Descriptor::new_bip44_public( let template_public_44 = Descriptor::new_bip44_public(
handmade_public_44, &handmade_public_44,
"d1d04177".to_string(), "d1d04177".to_string(),
KeychainKind::External, KeychainKind::External,
Network::Testnet, Network::Testnet,
); );
let template_public_49 = Descriptor::new_bip49_public( let template_public_49 = Descriptor::new_bip49_public(
handmade_public_49, &handmade_public_49,
"d1d04177".to_string(), "d1d04177".to_string(),
KeychainKind::External, KeychainKind::External,
Network::Testnet, Network::Testnet,
); );
let template_public_84 = Descriptor::new_bip84_public( let template_public_84 = Descriptor::new_bip84_public(
handmade_public_84, &handmade_public_84,
"d1d04177".to_string(), "d1d04177".to_string(),
KeychainKind::External, KeychainKind::External,
Network::Testnet, Network::Testnet,
); );
let template_public_86 = Descriptor::new_bip86_public( let template_public_86 = Descriptor::new_bip86_public(
handmade_public_86, &handmade_public_86,
"d1d04177".to_string(), "d1d04177".to_string(),
KeychainKind::External, KeychainKind::External,
Network::Testnet, Network::Testnet,

View File

@ -1,11 +1,12 @@
use crate::wallet::{Update, Wallet}; use crate::wallet::{Update, Wallet};
use std::ops::Deref;
use bdk::bitcoin::Transaction as BdkTransaction;
use bdk::wallet::Update as BdkUpdate; use bdk::wallet::Update as BdkUpdate;
use bdk::Error as BdkError; use bdk::Error as BdkError;
use bdk_esplora::esplora_client::{BlockingClient, Builder}; use bdk_esplora::esplora_client::{BlockingClient, Builder};
use bdk_esplora::EsploraExt; use bdk_esplora::EsploraExt;
use crate::bitcoin::Transaction;
use std::sync::Arc; use std::sync::Arc;
pub struct EsploraClient(BlockingClient); pub struct EsploraClient(BlockingClient);
@ -57,8 +58,8 @@ impl EsploraClient {
// pub fn sync(); // pub fn sync();
pub fn broadcast(&self, transaction: Arc<crate::bitcoin::Transaction>) -> Result<(), BdkError> { pub fn broadcast(&self, transaction: &Transaction) -> Result<(), BdkError> {
let bdk_transaction: bdk::bitcoin::Transaction = transaction.deref().clone().into(); let bdk_transaction: BdkTransaction = transaction.clone().into();
self.0 self.0
.broadcast(&bdk_transaction) .broadcast(&bdk_transaction)
.map_err(|e| BdkError::Generic(e.to_string())) .map_err(|e| BdkError::Generic(e.to_string()))

View File

@ -79,7 +79,7 @@ pub struct DescriptorSecretKey {
} }
impl DescriptorSecretKey { impl DescriptorSecretKey {
pub(crate) fn new(network: Network, mnemonic: Arc<Mnemonic>, password: Option<String>) -> Self { pub(crate) fn new(network: Network, mnemonic: &Mnemonic, password: Option<String>) -> Self {
let mnemonic = mnemonic.inner.clone(); let mnemonic = mnemonic.inner.clone();
let xkey: ExtendedKey = (mnemonic, password).into_extended_key().unwrap(); let xkey: ExtendedKey = (mnemonic, password).into_extended_key().unwrap();
let descriptor_secret_key = BdkDescriptorSecretKey::XPrv(DescriptorXKey { let descriptor_secret_key = BdkDescriptorSecretKey::XPrv(DescriptorXKey {
@ -101,7 +101,7 @@ impl DescriptorSecretKey {
}) })
} }
pub(crate) fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> { pub(crate) fn derive(&self, path: &DerivationPath) -> Result<Arc<Self>, BdkError> {
let secp = Secp256k1::new(); let secp = Secp256k1::new();
let descriptor_secret_key = &self.inner; let descriptor_secret_key = &self.inner;
let path = path.inner_mutex.lock().unwrap().deref().clone(); let path = path.inner_mutex.lock().unwrap().deref().clone();
@ -131,7 +131,7 @@ impl DescriptorSecretKey {
} }
} }
pub(crate) fn extend(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> { pub(crate) fn extend(&self, path: &DerivationPath) -> Result<Arc<Self>, BdkError> {
let descriptor_secret_key = &self.inner; let descriptor_secret_key = &self.inner;
let path = path.inner_mutex.lock().unwrap().deref().clone(); let path = path.inner_mutex.lock().unwrap().deref().clone();
match descriptor_secret_key { match descriptor_secret_key {
@ -201,7 +201,7 @@ impl DescriptorPublicKey {
}) })
} }
pub(crate) fn derive(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> { pub(crate) fn derive(&self, path: &DerivationPath) -> Result<Arc<Self>, BdkError> {
let secp = Secp256k1::new(); let secp = Secp256k1::new();
let descriptor_public_key = &self.inner; let descriptor_public_key = &self.inner;
let path = path.inner_mutex.lock().unwrap().deref().clone(); let path = path.inner_mutex.lock().unwrap().deref().clone();
@ -232,7 +232,7 @@ impl DescriptorPublicKey {
} }
} }
pub(crate) fn extend(&self, path: Arc<DerivationPath>) -> Result<Arc<Self>, BdkError> { pub(crate) fn extend(&self, path: &DerivationPath) -> Result<Arc<Self>, BdkError> {
let descriptor_public_key = &self.inner; let descriptor_public_key = &self.inner;
let path = path.inner_mutex.lock().unwrap().deref().clone(); let path = path.inner_mutex.lock().unwrap().deref().clone();
match descriptor_public_key { match descriptor_public_key {
@ -261,7 +261,7 @@ impl DescriptorPublicKey {
self.inner.to_string() self.inner.to_string()
} }
} }
//
// // The goal of these tests to to ensure `bdk-ffi` intermediate code correctly calls `bdk` APIs. // // The goal of these tests to to ensure `bdk-ffi` intermediate code correctly calls `bdk` APIs.
// // These tests should not be used to verify `bdk` behavior that is already tested in the `bdk` // // These tests should not be used to verify `bdk` behavior that is already tested in the `bdk`
// // crate. // // crate.
@ -275,39 +275,39 @@ mod test {
fn get_inner() -> DescriptorSecretKey { fn get_inner() -> DescriptorSecretKey {
let mnemonic = Mnemonic::from_string("chaos fabric time speed sponsor all flat solution wisdom trophy crack object robot pave observe combine where aware bench orient secret primary cable detect".to_string()).unwrap(); let mnemonic = Mnemonic::from_string("chaos fabric time speed sponsor all flat solution wisdom trophy crack object robot pave observe combine where aware bench orient secret primary cable detect".to_string()).unwrap();
DescriptorSecretKey::new(Network::Testnet.into(), Arc::new(mnemonic), None) DescriptorSecretKey::new(Network::Testnet.into(), &mnemonic, None)
} }
fn derive_dsk( fn derive_dsk(
key: &DescriptorSecretKey, key: &DescriptorSecretKey,
path: &str, path: &str,
) -> Result<Arc<DescriptorSecretKey>, BdkError> { ) -> Result<Arc<DescriptorSecretKey>, BdkError> {
let path = Arc::new(DerivationPath::new(path.to_string()).unwrap()); let path = DerivationPath::new(path.to_string()).unwrap();
key.derive(path) key.derive(&path)
} }
fn extend_dsk( fn extend_dsk(
key: &DescriptorSecretKey, key: &DescriptorSecretKey,
path: &str, path: &str,
) -> Result<Arc<DescriptorSecretKey>, BdkError> { ) -> Result<Arc<DescriptorSecretKey>, BdkError> {
let path = Arc::new(DerivationPath::new(path.to_string()).unwrap()); let path = DerivationPath::new(path.to_string()).unwrap();
key.extend(path) key.extend(&path)
} }
fn derive_dpk( fn derive_dpk(
key: &DescriptorPublicKey, key: &DescriptorPublicKey,
path: &str, path: &str,
) -> Result<Arc<DescriptorPublicKey>, BdkError> { ) -> Result<Arc<DescriptorPublicKey>, BdkError> {
let path = Arc::new(DerivationPath::new(path.to_string()).unwrap()); let path = DerivationPath::new(path.to_string()).unwrap();
key.derive(path) key.derive(&path)
} }
fn extend_dpk( fn extend_dpk(
key: &DescriptorPublicKey, key: &DescriptorPublicKey,
path: &str, path: &str,
) -> Result<Arc<DescriptorPublicKey>, BdkError> { ) -> Result<Arc<DescriptorPublicKey>, BdkError> {
let path = Arc::new(DerivationPath::new(path.to_string()).unwrap()); let path = DerivationPath::new(path.to_string()).unwrap();
key.extend(path) key.extend(&path)
} }
#[test] #[test]
@ -347,7 +347,7 @@ mod test {
assert_eq!(extended_dpk.as_string(), "tpubD6NzVbkrYhZ4WywdEfYbbd62yuvqLjAZuPsNyvzCNV85JekAEMbKHWSHLF9h3j45SxewXDcLv328B1SEZrxg4iwGfmdt1pDFjZiTkGiFqGa/0/*"); assert_eq!(extended_dpk.as_string(), "tpubD6NzVbkrYhZ4WywdEfYbbd62yuvqLjAZuPsNyvzCNV85JekAEMbKHWSHLF9h3j45SxewXDcLv328B1SEZrxg4iwGfmdt1pDFjZiTkGiFqGa/0/*");
let wif = "L2wTu6hQrnDMiFNWA5na6jB12ErGQqtXwqpSL7aWquJaZG8Ai3ch"; let wif = "L2wTu6hQrnDMiFNWA5na6jB12ErGQqtXwqpSL7aWquJaZG8Ai3ch";
let extended_key = DescriptorSecretKey::from_string(wif.to_string()).unwrap(); let extended_key = DescriptorSecretKey::from_string(wif.to_string()).unwrap();
let result = extended_key.derive(Arc::new(DerivationPath::new("m/0".to_string()).unwrap())); let result = extended_key.derive(&DerivationPath::new("m/0".to_string()).unwrap());
dbg!(&result); dbg!(&result);
assert!(result.is_err()); assert!(result.is_err());
} }

View File

@ -70,7 +70,7 @@ impl Wallet {
.map_err(|e| BdkError::Generic(e.to_string())) .map_err(|e| BdkError::Generic(e.to_string()))
} }
pub fn is_mine(&self, script: Arc<Script>) -> bool { pub fn is_mine(&self, script: &Script) -> bool {
// TODO: Both of the following lines work. Which is better? // TODO: Both of the following lines work. Which is better?
self.get_wallet().is_mine(&script.0) self.get_wallet().is_mine(&script.0)
// self.get_wallet().is_mine(script.0.clone().as_script()) // self.get_wallet().is_mine(script.0.clone().as_script())
@ -332,7 +332,7 @@ impl TxBuilder {
} }
/// Add a recipient to the internal list. /// Add a recipient to the internal list.
pub(crate) fn add_recipient(&self, script: Arc<Script>, amount: u64) -> Arc<Self> { pub(crate) fn add_recipient(&self, script: &Script, amount: u64) -> Arc<Self> {
let mut recipients: Vec<(BdkScriptBuf, u64)> = self.recipients.clone(); let mut recipients: Vec<(BdkScriptBuf, u64)> = self.recipients.clone();
recipients.append(&mut vec![(script.0.clone(), amount)]); recipients.append(&mut vec![(script.0.clone(), amount)]);
@ -455,7 +455,7 @@ impl TxBuilder {
/// either provide the utxos that the transaction should spend via add_utxos, or set drain_wallet to spend all of them. /// either provide the utxos that the transaction should spend via add_utxos, or set drain_wallet to spend all of them.
/// When bumping the fees of a transaction made with this option, you probably want to use BumpFeeTxBuilder.allow_shrinking /// When bumping the fees of a transaction made with this option, you probably want to use BumpFeeTxBuilder.allow_shrinking
/// to allow this output to be reduced to pay for the extra fees. /// to allow this output to be reduced to pay for the extra fees.
pub(crate) fn drain_to(&self, script: Arc<Script>) -> Arc<Self> { pub(crate) fn drain_to(&self, script: &Script) -> Arc<Self> {
Arc::new(TxBuilder { Arc::new(TxBuilder {
drain_to: Some(script.0.clone()), drain_to: Some(script.0.clone()),
..self.clone() ..self.clone()