Merge branch 'cooperative-release-of-funds' of https://github.com/patrini32/xmr-btc-swap into pr/1676

This commit is contained in:
binarybaron 2024-07-11 09:30:49 +02:00
commit f8c3276642
6 changed files with 63 additions and 38 deletions

View File

@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
- Introduced a cooperative Monero redeem feature for Bob to request from Alice if Bob is punished for not refunding in time. Alice can choose to cooperate but is not obligated to do so. This change is backwards compatible. To attempt recovery, resume a swap in the "Bitcoin punished" state. Success depends on Alice being active and still having a record of the swap. Note that Alice's cooperation is voluntary and recovery is not guaranteed - Introduced a cooperative Monero redeem feature for Bob to request from Alice if Bob is punished for not refunding in time. Alice can choose to cooperate but is not obligated to do so. This change is backwards compatible. To attempt recovery, resume a swap in the "Bitcoin punished" state. Success depends on Alice being active and still having a record of the swap. Note that Alice's cooperation is voluntary and recovery is not guaranteed
- 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 ## [0.13.2] - 2024-07-02

44
Cargo.lock generated
View File

@ -154,9 +154,9 @@ dependencies = [
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.80" version = "0.1.81"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1483,9 +1483,9 @@ checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
[[package]] [[package]]
name = "git2" name = "git2"
version = "0.18.1" version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbf97ba92db08df386e10c8ede66a2a0369bd277090afd8710e19e38de9ec0cd" checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724"
dependencies = [ dependencies = [
"bitflags 2.4.0", "bitflags 2.4.0",
"libc", "libc",
@ -1763,9 +1763,9 @@ dependencies = [
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "1.3.1" version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-channel", "futures-channel",
@ -1789,7 +1789,7 @@ checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155"
dependencies = [ dependencies = [
"futures-util", "futures-util",
"http 1.0.0", "http 1.0.0",
"hyper 1.3.1", "hyper 1.4.1",
"hyper-util", "hyper-util",
"rustls 0.23.10", "rustls 0.23.10",
"rustls-pki-types", "rustls-pki-types",
@ -1810,7 +1810,7 @@ dependencies = [
"futures-util", "futures-util",
"http 1.0.0", "http 1.0.0",
"http-body 1.0.0", "http-body 1.0.0",
"hyper 1.3.1", "hyper 1.4.1",
"pin-project-lite 0.2.13", "pin-project-lite 0.2.13",
"socket2 0.5.5", "socket2 0.5.5",
"tokio", "tokio",
@ -2128,9 +2128,9 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]] [[package]]
name = "libgit2-sys" name = "libgit2-sys"
version = "0.16.1+1.7.1" version = "0.17.0+1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2a2bb3680b094add03bb3732ec520ece34da31a8cd2d633d1389d0f0fb60d0c" checksum = "10472326a8a6477c3c20a64547b0059e4b0d086869eee31e6d7da728a8eb7224"
dependencies = [ dependencies = [
"cc", "cc",
"libc", "libc",
@ -3243,9 +3243,9 @@ dependencies = [
[[package]] [[package]]
name = "qrcode" name = "qrcode"
version = "0.14.0" version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23e719ca51966ff9f5a8436edb00d6115b3c606a0bb27c8f8ca74a38ff2b036d" checksum = "d68782463e408eb1e668cf6152704bd856c78c5b6417adaee3203d8f4c1fc9ec"
dependencies = [ dependencies = [
"image", "image",
] ]
@ -3497,7 +3497,7 @@ dependencies = [
"http 1.0.0", "http 1.0.0",
"http-body 1.0.0", "http-body 1.0.0",
"http-body-util", "http-body-util",
"hyper 1.3.1", "hyper 1.4.1",
"hyper-rustls", "hyper-rustls",
"hyper-util", "hyper-util",
"ipnet", "ipnet",
@ -3995,9 +3995,9 @@ dependencies = [
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.203" version = "1.0.204"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
@ -4024,9 +4024,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.203" version = "1.0.204"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -4541,7 +4541,7 @@ dependencies = [
"futures", "futures",
"get-port", "get-port",
"hex", "hex",
"hyper 1.3.1", "hyper 1.4.1",
"itertools 0.13.0", "itertools 0.13.0",
"jsonrpsee", "jsonrpsee",
"jsonrpsee-core", "jsonrpsee-core",
@ -5327,9 +5327,9 @@ checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7"
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "1.9.1" version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5de17fd2f7da591098415cff336e12965a28061ddace43b59cb3c430179c9439" checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314"
dependencies = [ dependencies = [
"getrandom 0.2.11", "getrandom 0.2.11",
"serde", "serde",
@ -5355,9 +5355,9 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]] [[package]]
name = "vergen" name = "vergen"
version = "8.3.1" version = "8.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e27d6bdd219887a9eadd19e1c34f32e47fa332301184935c6d9bca26f3cca525" checksum = "2990d9ea5967266ea0ccf413a4aa5c42a93dbcfda9cb49a97de6931726b12566"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"cfg-if 1.0.0", "cfg-if 1.0.0",

View File

@ -75,7 +75,7 @@ OPTIONS:
This command has three core 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. - `--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. - `--seller`: The multiaddress of the seller you want to swap with.

View File

@ -67,7 +67,7 @@ tracing-appender = "0.2"
tracing-futures = { version = "0.2", features = [ "std-future", "futures-03" ] } tracing-futures = { version = "0.2", features = [ "std-future", "futures-03" ] }
tracing-subscriber = { version = "0.3", default-features = false, features = [ "fmt", "ansi", "env-filter", "time", "tracing-log", "json" ] } tracing-subscriber = { version = "0.3", default-features = false, features = [ "fmt", "ansi", "env-filter", "time", "tracing-log", "json" ] }
url = { version = "2", features = [ "serde" ] } url = { version = "2", features = [ "serde" ] }
uuid = { version = "1.9", features = [ "serde", "v4" ] } uuid = { version = "1.10", features = [ "serde", "v4" ] }
void = "1" void = "1"
[target.'cfg(not(windows))'.dependencies] [target.'cfg(not(windows))'.dependencies]
@ -79,7 +79,7 @@ zip = "0.5"
[dev-dependencies] [dev-dependencies]
bitcoin-harness = { git = "https://github.com/delta1/bitcoin-harness-rs.git", rev = "80cc8d05db2610d8531011be505b7bee2b5cdf9f" } bitcoin-harness = { git = "https://github.com/delta1/bitcoin-harness-rs.git", rev = "80cc8d05db2610d8531011be505b7bee2b5cdf9f" }
get-port = "3" get-port = "3"
hyper = "1.3" hyper = "1.4"
jsonrpsee = { version = "0.16.2", features = [ "ws-client" ] } jsonrpsee = { version = "0.16.2", features = [ "ws-client" ] }
mockito = "1.4" mockito = "1.4"
monero-harness = { path = "../monero-harness" } monero-harness = { path = "../monero-harness" }

View File

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

View File

@ -69,6 +69,37 @@ where
monero_receive_address, monero_receive_address,
tor, 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 = let monero_receive_address =
monero_address::validate_is_testnet(monero_receive_address, is_testnet)?; monero_address::validate_is_testnet(monero_receive_address, is_testnet)?;
let bitcoin_change_address = let bitcoin_change_address =
@ -81,17 +112,6 @@ where
swap_id: Uuid::new_v4(), swap_id: Uuid::new_v4(),
}); });
let context = Context::build(
Some(bitcoin),
Some(monero),
Some(tor),
data,
is_testnet,
debug,
json,
None,
)
.await?;
(context, request) (context, request)
} }
CliCommand::History => { CliCommand::History => {
@ -300,10 +320,10 @@ enum CliCommand {
#[structopt( #[structopt(
long = "change-address", 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) parse(try_from_str = bitcoin_address::parse)
)] )]
bitcoin_change_address: bitcoin::Address, bitcoin_change_address: Option<bitcoin::Address>,
#[structopt(flatten)] #[structopt(flatten)]
monero: Monero, monero: Monero,