Skip to content

Commit 4478bfd

Browse files
committed
update BDK to 3.0.0
1 parent 7c34fa1 commit 4478bfd

9 files changed

Lines changed: 36 additions & 37 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ members = [".", "migration"]
2020
base64 = { version = "0.22.1", default-features = false, features = [
2121
"std",
2222
] }
23-
bdk_wallet = { version = "=2.0.0", default-features = false, features = [
23+
bdk_wallet = { version = "=3.0.0", default-features = false, features = [
2424
"file_store",
2525
"keys-bip39",
2626
"std",
2727
] }
28-
bdk_electrum = { version = "0.23.0", optional = true, default-features = false, features = [
28+
bdk_electrum = { version = "0.23.2", optional = true, default-features = false, features = [
2929
"use-rustls",
3030
] }
31-
bdk_esplora = { version = "0.22.0", optional = true, default-features = false, features = [
31+
bdk_esplora = { version = "0.22.2", optional = true, default-features = false, features = [
3232
"blocking-https-rustls",
3333
] }
3434
chacha20poly1305 = { version = "0.10.1", default-features = false, features = [

bindings/c-ffi/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/uniffi/Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/keys.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,13 @@ pub struct Keys {
7373

7474
/// Generate a set of [`Keys`] for the given Bitcoin network and witness version.
7575
pub fn generate_keys(bitcoin_network: BitcoinNetwork, witness_version: WitnessVersion) -> Keys {
76-
let bdk_network = BdkNetwork::from(bitcoin_network);
7776
let mnemonic = Mnemonic::generate((WordCount::Words12, Language::English))
7877
.expect("to be able to generate a new mnemonic");
7978
let xkey: ExtendedKey = mnemonic
8079
.clone()
8180
.into_extended_key()
8281
.expect("a valid key should have been provided");
83-
let xpub = &xkey.into_xpub(bdk_network, &Secp256k1::new());
82+
let xpub = &xkey.into_xpub(bitcoin_network.network_kind(), &Secp256k1::new());
8483
let mnemonic_str = mnemonic.to_string();
8584
let (account_xpub_vanilla, account_xpub_colored) =
8685
get_account_xpubs(&bitcoin_network, &mnemonic_str, witness_version).unwrap();
@@ -101,15 +100,14 @@ pub fn restore_keys(
101100
mnemonic: String,
102101
witness_version: WitnessVersion,
103102
) -> Result<Keys, Error> {
104-
let bdk_network = BdkNetwork::from(bitcoin_network);
105103
let (account_xpub_vanilla, account_xpub_colored) =
106104
get_account_xpubs(&bitcoin_network, &mnemonic, witness_version)?;
107105
let mnemonic_parsed = Mnemonic::parse_in(Language::English, &mnemonic)?;
108106
let xkey: ExtendedKey = mnemonic_parsed
109107
.clone()
110108
.into_extended_key()
111109
.expect("a valid key should have been provided");
112-
let xpub = &xkey.into_xpub(bdk_network, &Secp256k1::new());
110+
let xpub = &xkey.into_xpub(bitcoin_network.network_kind(), &Secp256k1::new());
113111
let master_fingerprint = xpub.fingerprint().to_string();
114112
Ok(Keys {
115113
mnemonic,

src/utils.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ pub enum BitcoinNetwork {
7878
SignetCustom,
7979
}
8080

81+
impl BitcoinNetwork {
82+
pub(crate) fn network_kind(&self) -> NetworkKind {
83+
match self {
84+
BitcoinNetwork::Mainnet => NetworkKind::Main,
85+
_ => NetworkKind::Test,
86+
}
87+
}
88+
}
89+
8190
impl fmt::Display for BitcoinNetwork {
8291
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8392
write!(f, "{self:?}")
@@ -258,10 +267,10 @@ where
258267
deserialize_str_or_number(deserializer)
259268
}
260269

261-
pub(crate) fn str_to_xpub(xpub: &str, bdk_network: &BdkNetwork) -> Result<Xpub, Error> {
270+
pub(crate) fn str_to_xpub(xpub: &str, network_kind: &NetworkKind) -> Result<Xpub, Error> {
262271
let pubkey_btc = Xpub::from_str(xpub)?;
263272
let extended_key_btc: ExtendedKey = ExtendedKey::from(pubkey_btc);
264-
Ok(extended_key_btc.into_xpub(*bdk_network, &Secp256k1::new()))
273+
Ok(extended_key_btc.into_xpub(*network_kind, &Secp256k1::new()))
265274
}
266275

267276
pub(crate) fn get_coin_type(bitcoin_network: &BitcoinNetwork, rgb: bool) -> u32 {

src/wallet/multisig.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,6 @@ impl MultisigWallet {
875875
/// [`MultisigKeys`].
876876
pub fn new(wallet_data: WalletData, keys: MultisigKeys) -> Result<Self, Error> {
877877
let wdata = wallet_data.clone();
878-
let bdk_network = BdkNetwork::from(wdata.bitcoin_network);
879878

880879
// wallet keys
881880
let descs = keys.build_descriptors(wdata.bitcoin_network)?;
@@ -894,7 +893,7 @@ impl MultisigWallet {
894893
descs.colored,
895894
descs.vanilla,
896895
true,
897-
bdk_network,
896+
BdkNetwork::from(wdata.bitcoin_network),
898897
)?;
899898

900899
// setup RGB

src/wallet/singlesig.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ impl SinglesigKeys {
2828
pub(crate) fn build_descriptors(
2929
&self,
3030
bitcoin_network: &BitcoinNetwork,
31-
bdk_network: &BdkNetwork,
3231
) -> Result<(WalletDescriptors, bool), Error> {
33-
let xpub_rgb = str_to_xpub(&self.account_xpub_colored, bdk_network)?;
34-
let xpub_btc = str_to_xpub(&self.account_xpub_vanilla, bdk_network)?;
32+
let network_kind = bitcoin_network.network_kind();
33+
let xpub_rgb = str_to_xpub(&self.account_xpub_colored, &network_kind)?;
34+
let xpub_btc = str_to_xpub(&self.account_xpub_vanilla, &network_kind)?;
3535
Ok(if let Some(mnemonic) = &self.mnemonic {
3636
let descs = get_descriptors(
3737
bitcoin_network,
@@ -154,10 +154,9 @@ impl Wallet {
154154
/// [`SinglesigKeys`].
155155
pub fn new(wallet_data: WalletData, keys: SinglesigKeys) -> Result<Self, Error> {
156156
let wdata = wallet_data.clone();
157-
let bdk_network = BdkNetwork::from(wdata.bitcoin_network);
158157

159158
// wallet keys
160-
let (descs, watch_only) = keys.build_descriptors(&wdata.bitcoin_network, &bdk_network)?;
159+
let (descs, watch_only) = keys.build_descriptors(&wdata.bitcoin_network)?;
161160

162161
// wallet directory and file logging setup
163162
let (wallet_dir, logger, _logger_guard) =
@@ -170,7 +169,7 @@ impl Wallet {
170169
descs.colored,
171170
descs.vanilla,
172171
watch_only,
173-
bdk_network,
172+
BdkNetwork::from(wdata.bitcoin_network),
174173
)?;
175174

176175
// setup RGB
@@ -204,10 +203,7 @@ impl Wallet {
204203
/// Return the descriptors of the wallet.
205204
pub fn get_descriptors(&self) -> WalletDescriptors {
206205
self.keys
207-
.build_descriptors(
208-
&self.internals.wallet_data.bitcoin_network,
209-
&BdkNetwork::from(self.internals.wallet_data.bitcoin_network),
210-
)
206+
.build_descriptors(&self.internals.wallet_data.bitcoin_network)
211207
.expect("already succeeded at wallet creation")
212208
.0
213209
}

src/wallet/test/new.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,7 @@ fn get_descriptors_success() {
455455
// get descriptors from keys
456456
let keys = wallet.get_keys();
457457
let bitcoin_network = wallet.bitcoin_network();
458-
let descriptors = keys
459-
.build_descriptors(&bitcoin_network, &BdkNetwork::from(bitcoin_network))
460-
.unwrap()
461-
.0;
458+
let descriptors = keys.build_descriptors(&bitcoin_network).unwrap().0;
462459

463460
// get descriptors from wallet
464461
let wlt_descriptors = wallet.get_descriptors();

0 commit comments

Comments
 (0)