mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Add command to withdraw BTC
If no amount is given the wallet will be drained.
This commit is contained in:
parent
f5e81bb0ee
commit
96008ec130
@ -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<Amount>,
|
||||
#[structopt(long = "address", help = "The address to receive the Bitcoin.")]
|
||||
address: Address,
|
||||
},
|
||||
}
|
||||
|
||||
fn parse_btc(s: &str) -> Result<Amount, ParseAmountError> {
|
||||
|
@ -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(())
|
||||
|
Loading…
Reference in New Issue
Block a user