Upgrade bitcoin wallet to use BIP84 derivation scheme

Explicitly specify the change descriptor because the behaviour when it
is not specified is unclear.
This commit is contained in:
rishflab 2021-03-02 17:10:29 +11:00
parent 17278d1278
commit a41b255dab
4 changed files with 12 additions and 11 deletions

View File

@ -13,6 +13,7 @@
#![allow(non_snake_case)]
use anyhow::{Context, Result};
use bdk::{descriptor::Segwitv0, keys::DerivableKey};
use prettytable::{row, Table};
use std::{path::Path, sync::Arc};
use structopt::StructOpt;
@ -88,7 +89,7 @@ async fn main() -> Result<()> {
let (bitcoin_wallet, monero_wallet) = init_wallets(
config.clone(),
&wallet_data_dir,
seed.extended_private_key(BITCOIN_NETWORK)?.private_key,
seed.extended_private_key(BITCOIN_NETWORK)?,
)
.await?;
@ -135,14 +136,14 @@ async fn main() -> Result<()> {
async fn init_wallets(
config: Config,
bitcoin_wallet_data_dir: &Path,
private_key: ::bitcoin::PrivateKey,
key: impl DerivableKey<Segwitv0> + Clone,
) -> Result<(bitcoin::Wallet, monero::Wallet)> {
let bitcoin_wallet = bitcoin::Wallet::new(
config.bitcoin.electrum_rpc_url,
config.bitcoin.electrum_http_url,
BITCOIN_NETWORK,
bitcoin_wallet_data_dir,
private_key,
key,
)
.await?;

View File

@ -337,7 +337,7 @@ async fn init_wallets(
config.bitcoin.electrum_http_url,
bitcoin_network,
bitcoin_wallet_data_dir,
seed.extended_private_key(bitcoin_network)?.private_key,
seed.extended_private_key(bitcoin_network)?,
)
.await?;

View File

@ -7,9 +7,10 @@ use anyhow::{anyhow, bail, Context, Result};
use backoff::{backoff::Constant as ConstantBackoff, future::retry};
use bdk::{
blockchain::{noop_progress, Blockchain, ElectrumBlockchain},
descriptor::Segwitv0,
electrum_client::{self, Client, ElectrumApi},
miniscript::bitcoin::PrivateKey,
FeeRate,
keys::DerivableKey,
FeeRate, KeychainKind,
};
use bitcoin::Script;
use reqwest::{Method, Url};
@ -45,7 +46,7 @@ impl Wallet {
electrum_http_url: Url,
network: bitcoin::Network,
wallet_dir: &Path,
private_key: PrivateKey,
key: impl DerivableKey<Segwitv0> + Clone,
) -> Result<Self> {
// Workaround for https://github.com/bitcoindevkit/rust-electrum-client/issues/47.
let config = electrum_client::ConfigBuilder::default().retry(2).build();
@ -56,8 +57,8 @@ impl Wallet {
let db = bdk::sled::open(wallet_dir)?.open_tree(SLED_TREE_NAME)?;
let bdk_wallet = bdk::Wallet::new(
bdk::template::P2WPKH(private_key),
None,
bdk::template::BIP84(key.clone(), KeychainKind::External),
Some(bdk::template::BIP84(key, KeychainKind::Internal)),
network,
db,
ElectrumBlockchain::from(client),

View File

@ -607,8 +607,7 @@ async fn init_test_wallets(
bitcoin::Network::Regtest,
datadir,
seed.extended_private_key(bitcoin::Network::Regtest)
.expect("Could not create extended private key from seed")
.private_key,
.expect("Could not create extended private key from seed"),
)
.await
.expect("could not init btc wallet");