Add subcommand to print internal bitcoin wallet descriptor

Example:

 cargo run --package swap --bin swap -- export-bitcoin-wallet

{"descriptor":"wpkh(xprv9s21ZrQH143K2q85eUf2ppCtti2Zar6aDCW5dCC5DG9VvutJ3cpe3Qf9wZpQeraNf9JEuGem1RyJZQMEWCN2DpWyL5WbsvmSW6wbL7Jq53H/84'/0'/0'/0/*)","blockheight":0,"label":"cli-bitcoin"}
This commit is contained in:
rishflab 2021-10-01 10:36:08 +10:00
parent 9ea73a8e66
commit e42812ba37
6 changed files with 74 additions and 0 deletions

View file

@ -9,6 +9,7 @@ use bdk::database::BatchDatabase;
use bdk::descriptor::Segwitv0;
use bdk::electrum_client::{ElectrumApi, GetHistoryRes};
use bdk::keys::DerivableKey;
use bdk::wallet::export::WalletExport;
use bdk::wallet::AddressIndex;
use bdk::{FeeRate, KeychainKind, SignOptions};
use bitcoin::{Network, Script};
@ -174,6 +175,18 @@ impl Wallet {
sub
}
pub async fn wallet_export(&self, role: &str) -> Result<WalletExport> {
let wallet = self.wallet.lock().await;
match bdk::wallet::export::WalletExport::export_wallet(
&wallet,
&format!("{}-{}", role, self.network),
true,
) {
Ok(wallet_export) => Ok(wallet_export),
Err(err_msg) => Err(anyhow::Error::msg(err_msg)),
}
}
}
fn print_status_change(txid: Txid, old: Option<ScriptStatus>, new: ScriptStatus) -> ScriptStatus {