allow --change-address to be omitted and default to internal wallet address (#1709)

allow --change-address to be omitted and default to internal wallet address (#1709)

Co-authored-by: binarybaron <86064887+binarybaron@users.noreply.github.com>
Co-authored-by: Byron Hambly <byron@hambly.dev>
This commit is contained in:
Einliterflasche 2024-07-11 09:19:41 +02:00 committed by GitHub
parent c385059138
commit 4115a452e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 14 deletions

View File

@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
- CLI: `--change-address` can now be omitted. In that case, any change is refunded to the internal bitcoin wallet.
## [0.13.2] - 2024-07-02
- CLI: Buffer received transfer proofs for later processing if we're currently running a different swap

View File

@ -75,7 +75,7 @@ OPTIONS:
This command has three core options:
- `--change-address`: A Bitcoin address you control. Will be used for refunds of any kind.
- `--change-address`: A Bitcoin address you control. Will be used for refunds of any kind. You can also omit this flag which will refund any change to the internal wallet.
- `--receive-address`: A Monero address you control. This is where you will receive the Monero after the swap.
- `--seller`: The multiaddress of the seller you want to swap with.

View File

@ -267,6 +267,10 @@ impl Context {
tasks: Arc::new(PendingTaskList::default()),
}
}
pub fn bitcoin_wallet(&self) -> Option<Arc<bitcoin::Wallet>> {
self.bitcoin_wallet.clone()
}
}
impl fmt::Debug for Context {

View File

@ -69,6 +69,37 @@ where
monero_receive_address,
tor,
} => {
let context = Context::build(
Some(bitcoin),
Some(monero),
Some(tor),
data,
is_testnet,
debug,
json,
None,
)
.await?;
// when no refund address was provided we default to the internal wallet
let bitcoin_change_address = match bitcoin_change_address {
Some(addr) => addr,
None => {
let internal_wallet_address = context
.bitcoin_wallet()
.expect("bitcoin wallet should exist")
.new_address()
.await?;
tracing::info!(
internal_wallet_address=%internal_wallet_address,
"No --change-address supplied. Any change will be received to the internal wallet."
);
internal_wallet_address
}
};
let monero_receive_address =
monero_address::validate_is_testnet(monero_receive_address, is_testnet)?;
let bitcoin_change_address =
@ -81,17 +112,6 @@ where
swap_id: Uuid::new_v4(),
});
let context = Context::build(
Some(bitcoin),
Some(monero),
Some(tor),
data,
is_testnet,
debug,
json,
None,
)
.await?;
(context, request)
}
CliCommand::History => {
@ -300,10 +320,10 @@ enum CliCommand {
#[structopt(
long = "change-address",
help = "The bitcoin address where any form of change or excess funds should be sent to",
help = "The bitcoin address where any form of change or excess funds should be sent to. If omitted they will be sent to the internal wallet.",
parse(try_from_str = bitcoin_address::parse)
)]
bitcoin_change_address: bitcoin::Address,
bitcoin_change_address: Option<bitcoin::Address>,
#[structopt(flatten)]
monero: Monero,