Remove --send-btc in favor of swapping the available balance

If the current balance is 0, we wait until the user deposits money
to the given address. After that, we simply swap the full balance.

Not only does this simplify the interface by removing a parameter,
but it also integrates the `deposit` command into the `buy-xmr`
command.

Syncing a wallet that is backed by electrum includes transactions
that are part of the mempool when computing the balance.
As such, waiting for a deposit is a very quick action because it
allows us to build our lock transaction on top of the yet to be
confirmed deposit transactions.

This patch introduces another function to the `bitcoin::Wallet` that
relies on the currently statically encoded fee rate. To make sure
future developers don't forget to adjust both, we extract a function
that "selects" a fee rate and return the constant from there.

Fixes #196.
This commit is contained in:
Thomas Eizinger 2021-02-26 14:31:09 +11:00
parent 32cb0eb896
commit f472070546
No known key found for this signature in database
GPG key ID: 651AC83A6C6C8B96
3 changed files with 55 additions and 24 deletions

View file

@ -1,5 +1,3 @@
use crate::bitcoin;
use anyhow::Result;
use libp2p::{core::Multiaddr, PeerId};
use std::path::PathBuf;
use uuid::Uuid;
@ -26,9 +24,6 @@ pub enum Command {
#[structopt(long = "connect-addr")]
alice_addr: Multiaddr,
#[structopt(long = "send-btc", help = "Bitcoin amount as floating point nr without denomination (e.g. 1.25)", parse(try_from_str = parse_btc))]
send_bitcoin: bitcoin::Amount,
},
History,
Resume(Resume),
@ -85,8 +80,3 @@ pub enum Refund {
force: bool,
},
}
fn parse_btc(str: &str) -> Result<bitcoin::Amount> {
let amount = bitcoin::Amount::from_str_in(str, ::bitcoin::Denomination::Bitcoin)?;
Ok(amount)
}