From f2df838a3ccd565f39ed5eded9b804824e43193f Mon Sep 17 00:00:00 2001 From: devbordecraft Date: Sun, 29 Aug 2021 18:31:41 +0200 Subject: [PATCH 1/2] Allow withdrawing and viewing of the bitcoin balance on swap-cli --- CHANGELOG.md | 2 ++ swap/src/cli/command.rs | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e31f45d..e864f9aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 We were not handling the error when TxCancel submission fails. We also configured the electrum client to retry 5 times in order to help with this problem. See issues: https://github.com/comit-network/xmr-btc-swap/issues/709 https://github.com/comit-network/xmr-btc-swap/issues/688, https://github.com/comit-network/xmr-btc-swap/issues/701. +- Add the ability to view the swap-cli bitcoin balance and withdraw + See issue https://github.com/comit-network/xmr-btc-swap/issues/694 ## [0.8.1] - 2021-08-16 diff --git a/swap/src/cli/command.rs b/swap/src/cli/command.rs index 0f0dc18b..72918b88 100644 --- a/swap/src/cli/command.rs +++ b/swap/src/cli/command.rs @@ -3,7 +3,7 @@ use crate::env::GetConfig; use crate::fs::system_data_dir; use crate::network::rendezvous::XmrBtcNamespace; use crate::{env, monero}; -use anyhow::{Context, Result}; +use anyhow::{bail, Context, Result}; use bitcoin::{Address, AddressType}; use libp2p::core::Multiaddr; use serde::Serialize; @@ -141,7 +141,7 @@ where bitcoin_electrum_rpc_url, bitcoin_target_block, amount, - address: validate_bitcoin_address(address, is_testnet)?, + address: bitcoin_address(address, is_testnet)?, }, } } @@ -529,6 +529,23 @@ fn env_config_from(testnet: bool) -> env::Config { } } +fn bitcoin_address(address: Address, is_testnet: bool) -> Result
{ + let network = if is_testnet { + bitcoin::Network::Testnet + } else { + bitcoin::Network::Bitcoin + }; + + if address.network != network { + bail!(BitcoinAddressNetworkMismatch { + expected: network, + actual: address.network + }); + } + + Ok(address) +} + fn validate_monero_address( address: monero::Address, testnet: bool, From 7a12a847a0904a54b33237b8570c945ac9985b47 Mon Sep 17 00:00:00 2001 From: devbordecraft Date: Sun, 29 Aug 2021 13:24:09 +0200 Subject: [PATCH 2/2] Fetch multiple UTXOs when we do max_giveable --- CHANGELOG.md | 2 ++ swap/src/bitcoin/wallet.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e864f9aa..3f2b5c51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 See issues: https://github.com/comit-network/xmr-btc-swap/issues/709 https://github.com/comit-network/xmr-btc-swap/issues/688, https://github.com/comit-network/xmr-btc-swap/issues/701. - Add the ability to view the swap-cli bitcoin balance and withdraw See issue https://github.com/comit-network/xmr-btc-swap/issues/694 +- An issue where the ASB withdraw one bitcoin UTXO at a time instead of the whole balance. + See issue https://github.com/comit-network/xmr-btc-swap/issues/662 ## [0.8.1] - 2021-08-16 diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index 4bdc6388..fb746b10 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -400,6 +400,7 @@ where let dummy_script = Script::from(vec![0u8; locking_script_size]); tx_builder.drain_to(dummy_script); tx_builder.fee_rate(fee_rate); + tx_builder.drain_wallet(); let response = tx_builder.finish(); match response {