mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Merge #798
798: Add subcommand to print internal bitcoin wallet descriptor r=rishflab a=rishflab Example: ``` cargo run --package swap --bin swap -- export-bitcoin-wallet {"descriptor":"wpkh(xprv9s21ZrQH143K2q85eUf2ppCtti2Zar6aDCW5dCC5DG9VvutJ3cpe3Qf9wZpQeraNf9JEuGem1RyJZQMEWCN2DpWyL5WbsvmSW6wbL7Jq53H/84'/0'/0'/0/*)","blockheight":0,"label":"cli-bitcoin"} ``` closes #700 Co-authored-by: rishflab <rishflab@hotmail.com>
This commit is contained in:
commit
58fd9c135a
@ -50,6 +50,8 @@ It is possible to migrate critical data from the old db to the sqlite but there
|
|||||||
- Added a `disable-timestamp` flag to the ASB that disables timestamps from logs.
|
- Added a `disable-timestamp` flag to the ASB that disables timestamps from logs.
|
||||||
- A `config` subcommand that prints the current configuration including the data directory location.
|
- A `config` subcommand that prints the current configuration including the data directory location.
|
||||||
This feature should alleviate difficulties users were having when finding where xmr-btc-swap was storing data.
|
This feature should alleviate difficulties users were having when finding where xmr-btc-swap was storing data.
|
||||||
|
- Added `export-bitcoin-wallet` subcommand to the CLI and ASB, to print the internal bitcoin wallet descriptor.
|
||||||
|
This will allow users to transact and monitor using external wallets.
|
||||||
|
|
||||||
## [0.8.3] - 2021-09-03
|
## [0.8.3] - 2021-09-03
|
||||||
|
|
||||||
|
@ -74,6 +74,15 @@ where
|
|||||||
env_config: env_config(testnet),
|
env_config: env_config(testnet),
|
||||||
cmd: Command::Config,
|
cmd: Command::Config,
|
||||||
},
|
},
|
||||||
|
RawCommand::ExportBitcoinWallet => Arguments {
|
||||||
|
testnet,
|
||||||
|
json,
|
||||||
|
sled,
|
||||||
|
disable_timestamp,
|
||||||
|
config_path: config_path(config, testnet)?,
|
||||||
|
env_config: env_config(testnet),
|
||||||
|
cmd: Command::ExportBitcoinWallet,
|
||||||
|
},
|
||||||
RawCommand::ManualRecovery(ManualRecovery::Redeem {
|
RawCommand::ManualRecovery(ManualRecovery::Redeem {
|
||||||
redeem_params: RecoverCommandParams { swap_id },
|
redeem_params: RecoverCommandParams { swap_id },
|
||||||
do_not_await_finality,
|
do_not_await_finality,
|
||||||
@ -222,6 +231,7 @@ pub enum Command {
|
|||||||
SafelyAbort {
|
SafelyAbort {
|
||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
},
|
},
|
||||||
|
ExportBitcoinWallet,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(structopt::StructOpt, Debug)]
|
#[derive(structopt::StructOpt, Debug)]
|
||||||
@ -296,6 +306,8 @@ pub enum RawCommand {
|
|||||||
about = "Prints the Bitcoin and Monero balance. Requires the monero-wallet-rpc to be running."
|
about = "Prints the Bitcoin and Monero balance. Requires the monero-wallet-rpc to be running."
|
||||||
)]
|
)]
|
||||||
Balance,
|
Balance,
|
||||||
|
#[structopt(about = "Print the internal bitcoin wallet descriptor.")]
|
||||||
|
ExportBitcoinWallet,
|
||||||
#[structopt(about = "Contains sub-commands for recovering a swap manually.")]
|
#[structopt(about = "Contains sub-commands for recovering a swap manually.")]
|
||||||
ManualRecovery(ManualRecovery),
|
ManualRecovery(ManualRecovery),
|
||||||
}
|
}
|
||||||
|
@ -301,6 +301,11 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
tracing::info!("Redeem transaction successfully published with id {}", txid);
|
tracing::info!("Redeem transaction successfully published with id {}", txid);
|
||||||
}
|
}
|
||||||
|
Command::ExportBitcoinWallet => {
|
||||||
|
let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?;
|
||||||
|
let wallet_export = bitcoin_wallet.wallet_export("asb").await?;
|
||||||
|
println!("{}", wallet_export.to_string())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -409,6 +409,23 @@ async fn main() -> Result<()> {
|
|||||||
println!("{}", table);
|
println!("{}", table);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Command::ExportBitcoinWallet {
|
||||||
|
bitcoin_electrum_rpc_url,
|
||||||
|
bitcoin_target_block,
|
||||||
|
} => {
|
||||||
|
let seed = Seed::from_file_or_generate(data_dir.as_path())
|
||||||
|
.context("Failed to read in seed file")?;
|
||||||
|
let bitcoin_wallet = init_bitcoin_wallet(
|
||||||
|
bitcoin_electrum_rpc_url,
|
||||||
|
&seed,
|
||||||
|
data_dir.clone(),
|
||||||
|
env_config,
|
||||||
|
bitcoin_target_block,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
let wallet_export = bitcoin_wallet.wallet_export("cli").await?;
|
||||||
|
println!("{}", wallet_export.to_string())
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ use bdk::database::BatchDatabase;
|
|||||||
use bdk::descriptor::Segwitv0;
|
use bdk::descriptor::Segwitv0;
|
||||||
use bdk::electrum_client::{ElectrumApi, GetHistoryRes};
|
use bdk::electrum_client::{ElectrumApi, GetHistoryRes};
|
||||||
use bdk::keys::DerivableKey;
|
use bdk::keys::DerivableKey;
|
||||||
|
use bdk::wallet::export::WalletExport;
|
||||||
use bdk::wallet::AddressIndex;
|
use bdk::wallet::AddressIndex;
|
||||||
use bdk::{FeeRate, KeychainKind, SignOptions};
|
use bdk::{FeeRate, KeychainKind, SignOptions};
|
||||||
use bitcoin::{Network, Script};
|
use bitcoin::{Network, Script};
|
||||||
@ -174,6 +175,18 @@ impl Wallet {
|
|||||||
|
|
||||||
sub
|
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 {
|
fn print_status_change(txid: Txid, old: Option<ScriptStatus>, new: ScriptStatus) -> ScriptStatus {
|
||||||
|
@ -239,6 +239,22 @@ where
|
|||||||
tor_socks5_port,
|
tor_socks5_port,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
RawCommand::ExportBitcoinWallet { bitcoin } => {
|
||||||
|
let (bitcoin_electrum_rpc_url, bitcoin_target_block) =
|
||||||
|
bitcoin.apply_defaults(is_testnet)?;
|
||||||
|
|
||||||
|
Arguments {
|
||||||
|
env_config: env_config_from(is_testnet),
|
||||||
|
debug,
|
||||||
|
json,
|
||||||
|
sled,
|
||||||
|
data_dir: data::data_dir_from(data, is_testnet)?,
|
||||||
|
cmd: Command::ExportBitcoinWallet {
|
||||||
|
bitcoin_electrum_rpc_url,
|
||||||
|
bitcoin_target_block,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(ParseResult::Arguments(arguments))
|
Ok(ParseResult::Arguments(arguments))
|
||||||
@ -289,6 +305,10 @@ pub enum Command {
|
|||||||
namespace: XmrBtcNamespace,
|
namespace: XmrBtcNamespace,
|
||||||
tor_socks5_port: u16,
|
tor_socks5_port: u16,
|
||||||
},
|
},
|
||||||
|
ExportBitcoinWallet {
|
||||||
|
bitcoin_electrum_rpc_url: Url,
|
||||||
|
bitcoin_target_block: usize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(structopt::StructOpt, Debug)]
|
#[derive(structopt::StructOpt, Debug)]
|
||||||
@ -427,6 +447,11 @@ enum RawCommand {
|
|||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
tor: Tor,
|
tor: Tor,
|
||||||
},
|
},
|
||||||
|
/// Print the internal bitcoin wallet descriptor
|
||||||
|
ExportBitcoinWallet {
|
||||||
|
#[structopt(flatten)]
|
||||||
|
bitcoin: Bitcoin,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(structopt::StructOpt, Debug)]
|
#[derive(structopt::StructOpt, Debug)]
|
||||||
|
Loading…
Reference in New Issue
Block a user