mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
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:
parent
17278d1278
commit
a41b255dab
@ -13,6 +13,7 @@
|
|||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
use bdk::{descriptor::Segwitv0, keys::DerivableKey};
|
||||||
use prettytable::{row, Table};
|
use prettytable::{row, Table};
|
||||||
use std::{path::Path, sync::Arc};
|
use std::{path::Path, sync::Arc};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
@ -88,7 +89,7 @@ async fn main() -> Result<()> {
|
|||||||
let (bitcoin_wallet, monero_wallet) = init_wallets(
|
let (bitcoin_wallet, monero_wallet) = init_wallets(
|
||||||
config.clone(),
|
config.clone(),
|
||||||
&wallet_data_dir,
|
&wallet_data_dir,
|
||||||
seed.extended_private_key(BITCOIN_NETWORK)?.private_key,
|
seed.extended_private_key(BITCOIN_NETWORK)?,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@ -135,14 +136,14 @@ async fn main() -> Result<()> {
|
|||||||
async fn init_wallets(
|
async fn init_wallets(
|
||||||
config: Config,
|
config: Config,
|
||||||
bitcoin_wallet_data_dir: &Path,
|
bitcoin_wallet_data_dir: &Path,
|
||||||
private_key: ::bitcoin::PrivateKey,
|
key: impl DerivableKey<Segwitv0> + Clone,
|
||||||
) -> Result<(bitcoin::Wallet, monero::Wallet)> {
|
) -> Result<(bitcoin::Wallet, monero::Wallet)> {
|
||||||
let bitcoin_wallet = bitcoin::Wallet::new(
|
let bitcoin_wallet = bitcoin::Wallet::new(
|
||||||
config.bitcoin.electrum_rpc_url,
|
config.bitcoin.electrum_rpc_url,
|
||||||
config.bitcoin.electrum_http_url,
|
config.bitcoin.electrum_http_url,
|
||||||
BITCOIN_NETWORK,
|
BITCOIN_NETWORK,
|
||||||
bitcoin_wallet_data_dir,
|
bitcoin_wallet_data_dir,
|
||||||
private_key,
|
key,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ async fn init_wallets(
|
|||||||
config.bitcoin.electrum_http_url,
|
config.bitcoin.electrum_http_url,
|
||||||
bitcoin_network,
|
bitcoin_network,
|
||||||
bitcoin_wallet_data_dir,
|
bitcoin_wallet_data_dir,
|
||||||
seed.extended_private_key(bitcoin_network)?.private_key,
|
seed.extended_private_key(bitcoin_network)?,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -7,9 +7,10 @@ use anyhow::{anyhow, bail, Context, Result};
|
|||||||
use backoff::{backoff::Constant as ConstantBackoff, future::retry};
|
use backoff::{backoff::Constant as ConstantBackoff, future::retry};
|
||||||
use bdk::{
|
use bdk::{
|
||||||
blockchain::{noop_progress, Blockchain, ElectrumBlockchain},
|
blockchain::{noop_progress, Blockchain, ElectrumBlockchain},
|
||||||
|
descriptor::Segwitv0,
|
||||||
electrum_client::{self, Client, ElectrumApi},
|
electrum_client::{self, Client, ElectrumApi},
|
||||||
miniscript::bitcoin::PrivateKey,
|
keys::DerivableKey,
|
||||||
FeeRate,
|
FeeRate, KeychainKind,
|
||||||
};
|
};
|
||||||
use bitcoin::Script;
|
use bitcoin::Script;
|
||||||
use reqwest::{Method, Url};
|
use reqwest::{Method, Url};
|
||||||
@ -45,7 +46,7 @@ impl Wallet {
|
|||||||
electrum_http_url: Url,
|
electrum_http_url: Url,
|
||||||
network: bitcoin::Network,
|
network: bitcoin::Network,
|
||||||
wallet_dir: &Path,
|
wallet_dir: &Path,
|
||||||
private_key: PrivateKey,
|
key: impl DerivableKey<Segwitv0> + Clone,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
// Workaround for https://github.com/bitcoindevkit/rust-electrum-client/issues/47.
|
// Workaround for https://github.com/bitcoindevkit/rust-electrum-client/issues/47.
|
||||||
let config = electrum_client::ConfigBuilder::default().retry(2).build();
|
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 db = bdk::sled::open(wallet_dir)?.open_tree(SLED_TREE_NAME)?;
|
||||||
|
|
||||||
let bdk_wallet = bdk::Wallet::new(
|
let bdk_wallet = bdk::Wallet::new(
|
||||||
bdk::template::P2WPKH(private_key),
|
bdk::template::BIP84(key.clone(), KeychainKind::External),
|
||||||
None,
|
Some(bdk::template::BIP84(key, KeychainKind::Internal)),
|
||||||
network,
|
network,
|
||||||
db,
|
db,
|
||||||
ElectrumBlockchain::from(client),
|
ElectrumBlockchain::from(client),
|
||||||
|
@ -607,8 +607,7 @@ async fn init_test_wallets(
|
|||||||
bitcoin::Network::Regtest,
|
bitcoin::Network::Regtest,
|
||||||
datadir,
|
datadir,
|
||||||
seed.extended_private_key(bitcoin::Network::Regtest)
|
seed.extended_private_key(bitcoin::Network::Regtest)
|
||||||
.expect("Could not create extended private key from seed")
|
.expect("Could not create extended private key from seed"),
|
||||||
.private_key,
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("could not init btc wallet");
|
.expect("could not init btc wallet");
|
||||||
|
Loading…
Reference in New Issue
Block a user