diff --git a/swap/src/asb/command.rs b/swap/src/asb/command.rs index 377e45ea..c4b87fa0 100644 --- a/swap/src/asb/command.rs +++ b/swap/src/asb/command.rs @@ -1,6 +1,6 @@ use crate::bitcoin::Amount; use bitcoin::util::amount::ParseAmountError; -use bitcoin::Denomination; +use bitcoin::{Address, Denomination}; use std::path::PathBuf; #[derive(structopt::StructOpt, Debug)] @@ -29,6 +29,15 @@ pub enum Command { max_buy: Amount, }, History, + WithdrawBtc { + #[structopt( + long = "amount", + help = "Optionally specify the amount of Bitcoin to be withdrawn. If not specified the wallet will be drained." + )] + amount: Option, + #[structopt(long = "address", help = "The address to receive the Bitcoin.")] + address: Address, + }, } fn parse_btc(s: &str) -> Result { diff --git a/swap/src/bin/asb.rs b/swap/src/bin/asb.rs index 5aeaa10b..30c82a5b 100644 --- a/swap/src/bin/asb.rs +++ b/swap/src/bin/asb.rs @@ -127,6 +127,23 @@ async fn main() -> Result<()> { // Print the table to stdout table.printstd(); } + Command::WithdrawBtc { amount, address } => { + let bitcoin_wallet = init_bitcoin_wallet(&config, &seed, env_config).await?; + + let amount = match amount { + Some(amount) => amount, + None => { + bitcoin_wallet + .max_giveable(address.script_pubkey().len()) + .await? + } + }; + + let psbt = bitcoin_wallet.send_to_address(address, amount).await?; + let signed_tx = bitcoin_wallet.sign_and_finalize(psbt).await?; + + bitcoin_wallet.broadcast(signed_tx, "withdraw").await?; + } }; Ok(())