Commit Graph

1228 Commits

Author SHA1 Message Date
Daniel Karzel
ff10edd8a4
Add the list-sellers command to the CLI
This command uses a rendezvous node to find sellers (i.e. ASBs) and query them for quotes.
Sellers, that can be dialed and queried for a quote will be listed.
2021-07-06 20:03:18 +10:00
Daniel Karzel
f45cde84ab
comfy-table instead of prettytable-rs 2021-07-06 20:01:48 +10:00
Thomas Eizinger
b4fafeba6b
Allow large enum variant lint
The docs say one needs to measure the impact of this before taking
action. We didn't measure anything. Let's not take any action.
2021-07-06 19:58:41 +10:00
Thomas Eizinger
e163942850
Merge transport and behaviour module into network 2021-07-06 19:58:40 +10:00
Daniel Karzel
ff8cca2e27
Pass in CLI behaviour when creating swarm
This allows us to reuse the swarm setup with a different behaviour for discovering ASBs with a rendezvous node.
2021-07-06 19:58:36 +10:00
bors[bot]
4cd27e372c
Merge #604
604: Bump torut from 0.1.9 to 0.1.10 r=thomaseizinger a=dependabot[bot]

Bumps [torut](https://github.com/teawithsand/torut) from 0.1.9 to 0.1.10.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/teawithsand/torut/releases">torut's releases</a>.</em></p>
<blockquote>
<h2>Release 0.1.10</h2>
<p>Deprecated onion services V2 and all stuff associated with it.
Updated tokio version.
Implemented std::error::Error for error types in this crate, support for these errors is very basic and all that was done was implementing Error trait for existing error types. No error structure refactoring was done.</p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="8a26ddde79"><code>8a26ddd</code></a> Implemented std::error::Error for error types</li>
<li><a href="c5cee8a369"><code>c5cee8a</code></a> Implemented std::error::Error for error types</li>
<li><a href="caed51d697"><code>caed51d</code></a> Deprecated v2 onion service stuff</li>
<li><a href="87bcde20bb"><code>87bcde2</code></a> Updated tokio version</li>
<li>See full diff in <a href="https://github.com/teawithsand/torut/compare/v0.1.9...v0.1.10">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=torut&package-manager=cargo&previous-version=0.1.9&new-version=0.1.10)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-07-06 06:49:06 +00:00
bors[bot]
72673fa166
Merge #605
605: Merge `--seller-addr` and `--seller-peer-id` into `--seller` parameter r=thomaseizinger a=thomaseizinger

This simplifies the CLI's interface.

It wills also play nicely with https://github.com/comit-network/xmr-btc-swap/pull/593.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-07-06 05:55:25 +00:00
Thomas Eizinger
d49f4ea60d
Test saving and loading of addresses in isolation 2021-07-06 15:53:14 +10:00
Thomas Eizinger
ec4234fbb9
Merge --seller-addr and --seller-peer-id into --seller parameter
This simplifies the CLI's interface.
2021-07-06 14:51:08 +10:00
Thomas Eizinger
c2daf7a11e
Make use of torut's errors implementing std::error::Error
Anyhow all the things!
2021-07-06 14:46:00 +10:00
Thomas Eizinger
8057b45e17
Test new reachability function in tests 2021-06-30 18:28:51 +10:00
Thomas Eizinger
92ed8d9c04
Refuse to dial addresses via Tor that are almost certainly not reachable
For now, this just concerns loopback addresses.
2021-06-30 18:28:47 +10:00
Thomas Eizinger
ec59184e85
Refactor fmt_as_address_string to return a structured value
Instead of formatting to a string right away, we parse the multiaddress
into a stricter data structure that only allows the kind of addresses
we can dial through Tor.

This will allow us to perform further checks on the parsed address.
2021-06-30 18:15:26 +10:00
bors[bot]
b708d5a4dd
Merge #585
585: Configurable kraken websocket url via the ASB config r=thomaseizinger a=cimble-code

- Allows the ASB operator to configure a custom kraken websocket url via the ASB config. 
- Addresses the issue of price control first brought up [here](https://github.com/comit-network/xmr-btc-swap/discussions/571)

>  Gotya. 
There is a relatively easy to implement (but temporary) solution for that. We could let the user configure the kraken websocket url via the ASB config. That way you can plug in your own service. The only requirement is that your service publishes prices updates in the same format as [kraken](https://docs.kraken.com/websockets/), e.g. : 

_Originally posted by @bonomat in https://github.com/comit-network/xmr-btc-swap/discussions/571#discussioncomment-885535_

Co-authored-by: Your Name <you@example.com>
2021-06-28 12:05:00 +00:00
Your Name
665ea503d2 Make price ticker ws url configurable 2021-06-28 03:19:49 -07:00
Daniel Karzel
dc89a837e7
Do not actively set KeepAlice::No for swap_setup
Closing the connection upon completing the `swap_setup` protocol caused problems on the ASB side, because the CLI would close the connection before the last message was properly processed. This would result in swaps going into execution on the CLI side, but not on the ASB side.
The CLI ensures an open connection to the ASB over the complete course of a swap. So it does not make much sense to allow a protocol to close the connection (the CLI would immediately redial).
For the Alice we set the initial `KeepAlive` to `10` seconds because Bob is expected to request a spot price in reasonable time after opening a connection on the protocol. Since Tor connections can take some time we set 10 seconds fow now for resilience.
2021-06-28 12:08:51 +10:00
Daniel Karzel
cd14e22cdf
Longer timeout (120 secs) for swap_setup protocol
Given that we combined the `spot_price` and the `execution_setup` messaging into one protocol we should allow the protocol to take longer than 60 seconds to complete.
This is especially important for connections over Tor, where messaging can take significantly longer than over clearnet.
I ran some tests with Tor and did not run into issues with the 60 seconds, but we get very close to the timeout, so we better make it more resilient by adding more time.
2021-06-28 12:08:51 +10:00
Daniel Karzel
fd18a07426
Flush and close swap_setup substreams
When swapping on testnet we ran into a problem where the CLI started the swap after sending all messages successfully, but the ASB ran into a `connection closed` error at the end of the `swap_setup` and the swap state machine was never actually triggered.

Flushing and closing the stream on both sides should ensure that we don't run into this problem and both parties gracefully exit the protocol.
2021-06-28 12:08:50 +10:00
Daniel Karzel
c2c9e975ef
Quote protocol asb/cli instead of alice/bob
The quote protocol has no relation to the protocol roles but to the application hence the rename.
2021-06-28 10:04:08 +10:00
Daniel Karzel
c0070f8fa7
Move files from protocol to appropriate module
Some network and application specific code does not belong in the protocol module and was moved.
Eventloop, recovery and the outside behaviour were moved to the respective application module because they are application specific.

The `swap_setup` was moved into the network module because upon change both sides will have to be changed and should thus stay close together.
2021-06-28 10:04:08 +10:00
Daniel Karzel
818147a629
swap_setup instead of spot_price and execution_setup
Having `spot_price` and `execution_setup` as separate protocols did not bring any advantages, but was problematic because we had to ensure that `execution_setup` would be triggered after `spot_price`. Because of this dependency it is better to combine the protocols into one.

Combining the protocols also allows a refactoring to get rid of the `libp2p-async-await` dependency.

Alice always listens for the `swap_setup` protocol. When Bob opens a substream on that protocol the spot price is communicated, and then all execution setup messages (swap-id and signature exchange).
2021-06-28 10:04:07 +10:00
Daniel Karzel
529de8d5fd
ASB aborts if CLI does not lock BTC
Includes a new state that is used to await BTC lock tx finality. Upon starting the swap we initially only wait for the BTC lock tx to be seen in the mempool.
This is guarded by a short timeout (3 mins), because it is assumed that in the current setup (sport_price + execution_setup only triggered upon funds being available already) the lock transaction should be picked up almost instanly after the execution setup succeeded.
2021-06-23 17:54:42 +10:00
Daniel Karzel
c4c798ea20
Timeout on execution_setup for ASB
Similar to the CLI the ASB has to ensure that the execution_setup is executed within a certain time.
Without a timeout the price (returned by `spot_price` would be guaranteed with the CLI indefinitely.
2021-06-23 17:54:42 +10:00
Daniel Karzel
1ae377ef24
Request timeout when swapping over Tor
It seems the current chosen channel timeouts are still not optimal.
I ran into issues with swapping over Tor and traced them down to the CLI timeout of the bmrng channel.
It appears that the ASB was not running as quick as the CLI, which caused a timeout on the CLI side (in addition to the delay when sending messages over Tor).
Only `execution_setup` caused the problem so far, but I would recommend changing all the channel timeouts to one minute to avoid this problem.
2021-06-23 17:53:50 +10:00
bors[bot]
c6b0013b92
Merge #581 #583
581: Remove dead code r=thomaseizinger a=da-kami



583: Bump reqwest from 0.11.3 to 0.11.4 r=thomaseizinger a=dependabot[bot]

Bumps [reqwest](https://github.com/seanmonstar/reqwest) from 0.11.3 to 0.11.4.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/seanmonstar/reqwest/releases">reqwest's releases</a>.</em></p>
<blockquote>
<h2>v0.11.4</h2>
<ul>
<li>Add <code>ClientBuilder::resolve()</code> option to override DNS resolution for specific domains.</li>
<li>Add <code>native-tls-alpn</code> Cargo feature to use ALPN with the native-tls backend.</li>
<li>Add <code>ClientBuilder::deflate()</code> option and <code>deflate</code> Cargo feature to support decoding response bodies using deflate.</li>
<li>Add <code>RequestBuilder::version()</code> to allow setting the HTTP version of a request.</li>
<li>Fix allowing &quot;invalid&quot; certificates with the <code>rustls-tls</code> backend, when the server uses TLS v1.2 or v1.3.</li>
<li>(wasm) Add <code>try_clone</code> to <code>Request</code> and <code>RequestBuilder</code></li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md">reqwest's changelog</a>.</em></p>
<blockquote>
<h2>v0.11.4</h2>
<ul>
<li>Add <code>ClientBuilder::resolve()</code> option to override DNS resolution for specific domains.</li>
<li>Add <code>native-tls-alpn</code> Cargo feature to use ALPN with the native-tls backend.</li>
<li>Add <code>ClientBuilder::deflate()</code> option and <code>deflate</code> Cargo feature to support decoding response bodies using deflate.</li>
<li>Add <code>RequestBuilder::version()</code> to allow setting the HTTP version of a request.</li>
<li>Fix allowing &quot;invalid&quot; certificates with the <code>rustls-tls</code> backend, when the server uses TLS v1.2 or v1.3.</li>
<li>(wasm) Add <code>try_clone</code> to <code>Request</code> and <code>RequestBuilder</code></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="f5fe17876a"><code>f5fe178</code></a> v0.11.4</li>
<li><a href="8e5af459e5"><code>8e5af45</code></a> Allow overriding of DNS resolution to specified IP addresses(<a href="https://github-redirect.dependabot.com/seanmonstar/reqwest/issues/561">#561</a>) (<a href="https://github-redirect.dependabot.com/seanmonstar/reqwest/issues/1277">#1277</a>)</li>
<li><a href="c4388fcff9"><code>c4388fc</code></a> WASM: Add <code>try_clone</code> implementations to <code>Request</code> and <code>RequestBuilder</code> (<a href="https://github-redirect.dependabot.com/seanmonstar/reqwest/issues/1286">#1286</a>)</li>
<li><a href="b48cb4a5aa"><code>b48cb4a</code></a> Add native-tls-alpn feature (<a href="https://github-redirect.dependabot.com/seanmonstar/reqwest/issues/1283">#1283</a>)</li>
<li><a href="bbeb1ede4e"><code>bbeb1ed</code></a> Bump ssri from 6.0.1 to 6.0.2 in /examples/wasm_github_fetch (<a href="https://github-redirect.dependabot.com/seanmonstar/reqwest/issues/1262">#1262</a>)</li>
<li><a href="841d47c6a2"><code>841d47c</code></a> Bump url-parse from 1.4.7 to 1.5.1 in /examples/wasm_github_fetch (<a href="https://github-redirect.dependabot.com/seanmonstar/reqwest/issues/1267">#1267</a>)</li>
<li><a href="33bc7939b4"><code>33bc793</code></a> Bump lodash from 4.17.19 to 4.17.21 in /examples/wasm_github_fetch (<a href="https://github-redirect.dependabot.com/seanmonstar/reqwest/issues/1269">#1269</a>)</li>
<li><a href="b0af278f78"><code>b0af278</code></a> Implement &quot;default&quot; functions of the trait to fix &quot;insecure&quot; mode (<a href="https://github-redirect.dependabot.com/seanmonstar/reqwest/issues/1259">#1259</a>)</li>
<li><a href="8d3e27966c"><code>8d3e279</code></a> use ZlibDecoder for deflate responses (<a href="https://github-redirect.dependabot.com/seanmonstar/reqwest/issues/1257">#1257</a>)</li>
<li><a href="b88f309339"><code>b88f309</code></a> Fix small typos in <code>Client</code> docs (<a href="https://github-redirect.dependabot.com/seanmonstar/reqwest/issues/1253">#1253</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/seanmonstar/reqwest/compare/v0.11.3...v0.11.4">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=reqwest&package-manager=cargo&previous-version=0.11.3&new-version=0.11.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Co-authored-by: Daniel Karzel <daniel@comit.network>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-23 03:41:02 +00:00
bors[bot]
858c6d85ce
Merge #576
576: Bump to Rust 1.53 r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-06-23 03:17:17 +00:00
Daniel Karzel
ca6b889632
Remove dead code 2021-06-22 17:06:21 +10:00
bors[bot]
3e88e13fbb
Merge #566 #568
566: Bump rand_chacha from 0.3.0 to 0.3.1 r=thomaseizinger a=dependabot[bot]

Bumps [rand_chacha](https://github.com/rust-random/rand) from 0.3.0 to 0.3.1.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/rust-random/rand/blob/master/CHANGELOG.md">rand_chacha's changelog</a>.</em></p>
<blockquote>
<h2>[0.3.19] - 2017-12-27</h2>
<h3>Changed</h3>
<ul>
<li>Require <code>log &lt;= 0.3.8</code> for dev builds</li>
<li>Update <code>fuchsia-zircon</code> dependency to 0.3</li>
<li>Fix broken links in docs (to unblock compiler docs testing CI)</li>
</ul>
<h2>[0.3.18] - 2017-11-06</h2>
<h3>Changed</h3>
<ul>
<li><code>thread_rng</code> is seeded from the system time if <code>OsRng</code> fails</li>
<li><code>weak_rng</code> now uses <code>thread_rng</code> internally</li>
</ul>
<h2>[0.3.17] - 2017-10-07</h2>
<h3>Changed</h3>
<ul>
<li>Fuchsia: Magenta was renamed Zircon</li>
</ul>
<h2>[0.3.16] - 2017-07-27</h2>
<h3>Added</h3>
<ul>
<li>Implement Debug for mote non-public types</li>
<li>implement <code>Rand</code> for (i|u)i128</li>
<li>Support for Fuchsia</li>
</ul>
<h3>Changed</h3>
<ul>
<li>Add inline attribute to SampleRange::construct_range.
This improves the benchmark for sample in 11% and for shuffle in 16%.</li>
<li>Use <code>RtlGenRandom</code> instead of <code>CryptGenRandom</code></li>
</ul>
<h2>[0.3.15] - 2016-11-26</h2>
<h3>Added</h3>
<ul>
<li>Add <code>Rng</code> trait method <code>choose_mut</code></li>
<li>Redox support</li>
</ul>
<h3>Changed</h3>
<ul>
<li>Use <code>arc4rand</code> for <code>OsRng</code> on FreeBSD.</li>
<li>Use <code>arc4random(3)</code> for <code>OsRng</code> on OpenBSD.</li>
</ul>
<h3>Fixed</h3>
<ul>
<li>Fix filling buffers 4 GiB or larger with <code>OsRng::fill_bytes</code> on Windows</li>
</ul>
<h2>[0.3.14] - 2016-02-13</h2>
<h3>Fixed</h3>
<ul>
<li>Inline definitions from winapi/advapi32, which decreases build times</li>
</ul>
<h2>[0.3.13] - 2016-01-09</h2>
<h3>Fixed</h3>
<ul>
<li>Compatible with Rust 1.7.0-nightly (needed some extra type annotations)</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="98a0339f99"><code>98a0339</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/rust-random/rand/issues/1135">#1135</a> from dhardy/work</li>
<li><a href="a7f8fb72d7"><code>a7f8fb7</code></a> Prepare rand_chacha v0.3.1 release</li>
<li><a href="09d3df3119"><code>09d3df3</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/rust-random/rand/issues/1130">#1130</a> from dhardy/work</li>
<li><a href="d167dd25d2"><code>d167dd2</code></a> Deprecate ReadRng</li>
<li><a href="e3bc4a1357"><code>e3bc4a1</code></a> Do not impl serde for ReadRng or ReseedingRng</li>
<li><a href="66b163632e"><code>66b1636</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/rust-random/rand/issues/1132">#1132</a> from rust-random/readme-wasm-note</li>
<li><a href="d9c6a76048"><code>d9c6a76</code></a> README: add note regarding wasm32-unknown-unknown</li>
<li><a href="4726d328d6"><code>4726d32</code></a> Update minimum version of packed_simd_2</li>
<li><a href="f6bbfcfa89"><code>f6bbfcf</code></a> serde for BlockRng, ReseedingRng and ReadRng</li>
<li><a href="2732f2d6a8"><code>2732f2d</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/rust-random/rand/issues/1116">#1116</a> from vks/criterion</li>
<li>Additional commits viewable in <a href="https://github.com/rust-random/rand/compare/rand_chacha-0.3.0...rand_chacha-0.3.1">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=rand_chacha&package-manager=cargo&previous-version=0.3.0&new-version=0.3.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

568: Bump bdk from 0.7.0 to 0.8.0 r=thomaseizinger a=dependabot[bot]

Bumps [bdk](https://github.com/bitcoindevkit/bdk) from 0.7.0 to 0.8.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/bitcoindevkit/bdk/blob/master/CHANGELOG.md">bdk's changelog</a>.</em></p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="33b45ebe82"><code>33b45eb</code></a> Bump version to 0.8.0</li>
<li><a href="2faed425ed"><code>2faed42</code></a> Update CHANGELOG</li>
<li><a href="2cc05c07a5"><code>2cc05c0</code></a> Bump version in <code>src/lib.rs</code></li>
<li><a href="9205295332"><code>9205295</code></a> Merge commit 'refs/pull/365/head' of github.com:bitcoindevkit/bdk into releas...</li>
<li><a href="3b446c9e14"><code>3b446c9</code></a> Use no_run instead of ignore</li>
<li><a href="378167efca"><code>378167e</code></a> Remove explicit <code>feature(external_doc)</code></li>
<li><a href="224be27aa8"><code>224be27</code></a> Fix example/doctests format</li>
<li><a href="4a23070cc8"><code>4a23070</code></a> [ci] Check fmt for examples/doctests</li>
<li><a href="f8117c0f9f"><code>f8117c0</code></a> Bump version to 0.8.0-rc.1</li>
<li><a href="0ec064ef13"><code>0ec064e</code></a> Use AddressInfo in private methods</li>
<li>Additional commits viewable in <a href="https://github.com/bitcoindevkit/bdk/compare/v0.7.0...v0.8.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=bdk&package-manager=cargo&previous-version=0.7.0&new-version=0.8.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-21 03:12:03 +00:00
Thomas Eizinger
7120a1f70a
Don't depend on core::fmt through bitcoin_hashes re-export 2021-06-21 12:14:02 +10:00
Thomas Eizinger
3aa028e3bf
Use or-pattern stabilized in Rust 1.53 where possible 2021-06-21 11:57:21 +10:00
Thomas Eizinger
ac0b0150e6
Upgrade to Rust 1.53
Also fix all clippy lints that came up.
2021-06-21 11:56:04 +10:00
Thomas Eizinger
b7064578ca
Reduce level of indentation of match statements 2021-06-21 11:46:24 +10:00
Thomas Eizinger
f1182f97c0
Simplify match statement
This code is unnecessarily complicated.
2021-06-21 11:31:24 +10:00
Thomas Eizinger
707bae9ff0
Merge patterns of nested match 2021-06-21 11:22:45 +10:00
dependabot[bot]
9577875834
Bump bdk from 0.7.0 to 0.8.0
Bumps [bdk](https://github.com/bitcoindevkit/bdk) from 0.7.0 to 0.8.0.
- [Release notes](https://github.com/bitcoindevkit/bdk/releases)
- [Changelog](https://github.com/bitcoindevkit/bdk/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bitcoindevkit/bdk/compare/v0.7.0...v0.8.0)

---
updated-dependencies:
- dependency-name: bdk
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-21 11:16:45 +10:00
Thomas Eizinger
1ba186aa63
Make log message a proper statement
"Listening on" is only half a sentence.
2021-06-21 09:01:21 +10:00
Thomas Eizinger
ff8cd0ab93
Harmonise log statements between applications
The refactoring of the transport initialization removed the log statement
for the asb. We re-introduce this log statement in main for consistency.
2021-06-21 09:01:20 +10:00
Thomas Eizinger
8a30ef725c
Refactor transports to construct them specific for each application
Instead of splitting up the transports into capabilities, we compose
them directly for each application. This allows us to remove the
websocket transport for the CLI which is really only needed for the
ASB to allow retrieval of quotes via the browser.
2021-06-21 09:01:19 +10:00
Thomas Eizinger
90deb6451c
Rename swarm constructors to be per tool instead of per role 2021-06-21 09:00:10 +10:00
Thomas Eizinger
d19231d811
Refactor Tor transport to be dial-only
Libp2p's transports are meant to be composed. Hence, any form of
fallback should be implemented by emitting `MultiaddrNotSupported`
from the `listen` and `dial` functions.

This allows us to completely remove the tcp transport from the tor
transport.
2021-06-21 09:00:10 +10:00
Thomas Eizinger
8bd6c9dcfc
Simplify construction of Socks5Stream 2021-06-21 09:00:09 +10:00
Thomas Eizinger
ea0fd1eb53
Inline functions to reduce complexity induced by indirection 2021-06-21 09:00:09 +10:00
Thomas Eizinger
97a09807dd
Use BoxFuture type alias to avoid clippy's complexity nag 2021-06-21 09:00:09 +10:00
Thomas Eizinger
d01e444c90
Import anyhow::Result instead of fully-qualifying it 2021-06-21 09:00:06 +10:00
bors[bot]
7f2aa59880
Merge #504 #547 #556 #563 #564
504: Bump bdk from 0.6.0 to 0.7.0 r=thomaseizinger a=dependabot[bot]

Bumps [bdk](https://github.com/bitcoindevkit/bdk) from 0.6.0 to 0.7.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/bitcoindevkit/bdk/blob/v0.7.0/CHANGELOG.md">bdk's changelog</a>.</em></p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="766570abfd"><code>766570a</code></a> Bump version to 0.7.0</li>
<li><a href="934ec366d9"><code>934ec36</code></a> Use the released <code>testutils-macros</code></li>
<li><a href="d0733e9496"><code>d0733e9</code></a> Bump version in <code>src/lib.rs</code></li>
<li><a href="3c7a1f5918"><code>3c7a1f5</code></a> Bump <code>testutils-macros</code> to <code>v0.6.0</code></li>
<li><a href="85aadaccd2"><code>85aadac</code></a> Update changelog in preparation of <code>v0.7.0</code></li>
<li><a href="fad0fe9f30"><code>fad0fe9</code></a> Update create transaction example code</li>
<li><a href="47f26447da"><code>47f2644</code></a> continue signing when finding already finalized inputs</li>
<li><a href="3608ff9f14"><code>3608ff9</code></a> Merge commit 'refs/pull/341/head' of github.com:bitcoindevkit/bdk into releas...</li>
<li><a href="898dfe6cf1"><code>898dfe6</code></a> get psbt inputs with bounds check</li>
<li><a href="7961ae7f8e"><code>7961ae7</code></a> Check index out of bound also for tx inputs not only for psbt inputs</li>
<li>Additional commits viewable in <a href="https://github.com/bitcoindevkit/bdk/compare/v0.6.0...v0.7.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=bdk&package-manager=cargo&previous-version=0.6.0&new-version=0.7.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

547: Print the Bitcoin address to the terminal as a QR code r=thomaseizinger a=xscd

It helps to fund the Bitcoin address with your mobile device without a need to copy-paste the receive address. 

Here is how it looks like under different terminals:
1) Gnome Terminal:
![1](https://user-images.githubusercontent.com/46658470/120103390-0e87dd80-c158-11eb-9e0f-da5af89ea8d7.png)
2) Alacritty:
![2](https://user-images.githubusercontent.com/46658470/120103398-1ba4cc80-c158-11eb-89c0-8a54e8902658.png)
3) Kitty:
![3](https://user-images.githubusercontent.com/46658470/120103411-265f6180-c158-11eb-95e1-b37c2d16c2b6.png)
4) Konsole:
![4](https://user-images.githubusercontent.com/46658470/120103421-2f503300-c158-11eb-83bf-82d55b6e2dd8.png)



556: Bump rust_decimal from 1.14.1 to 1.14.2 r=thomaseizinger a=dependabot[bot]

Bumps [rust_decimal](https://github.com/paupino/rust-decimal) from 1.14.1 to 1.14.2.
<details>
<summary>Commits</summary>
<ul>
<li><a href="16b41cc58c"><code>16b41cc</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/paupino/rust-decimal/issues/394">#394</a> from paupino/version/1.14.2</li>
<li><a href="c7bd3bf987"><code>c7bd3bf</code></a> Version 1.14.2</li>
<li><a href="c0117ddc36"><code>c0117dd</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/paupino/rust-decimal/issues/393">#393</a> from paupino/issue/392</li>
<li><a href="a231fbf12c"><code>a231fbf</code></a> Fixes issue with remainder overflow</li>
<li>See full diff in <a href="https://github.com/paupino/rust-decimal/compare/1.14.1...1.14.2">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=rust_decimal&package-manager=cargo&previous-version=1.14.1&new-version=1.14.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

563: Bump tokio from 1.6.0 to 1.7.0 r=thomaseizinger a=dependabot[bot]

Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.6.0 to 1.7.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/tokio-rs/tokio/releases">tokio's releases</a>.</em></p>
<blockquote>
<h2>Tokio v1.7.0</h2>
<h1>1.7.0 (June 15, 2021)</h1>
<h3>Added</h3>
<ul>
<li>net: add named pipes on windows (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3760">#3760</a>)</li>
<li>net: add <code>TcpSocket</code> from <code>std::net::TcpStream</code> conversion (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3838">#3838</a>)</li>
<li>sync: add <code>receiver_count</code> to <code>watch::Sender</code> (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3729">#3729</a>)</li>
<li>sync: export <code>sync::notify::Notified</code> future publicly (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3840">#3840</a>)</li>
<li>tracing: instrument task wakers (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3836">#3836</a>)</li>
</ul>
<h3>Fixed</h3>
<ul>
<li>macros: suppress <code>clippy::default_numeric_fallback</code> lint in generated code (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3831">#3831</a>)</li>
<li>runtime: immediately drop new tasks when runtime is shut down (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3752">#3752</a>)</li>
<li>sync: deprecate unused <code>mpsc::RecvError</code> type (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3833">#3833</a>)</li>
</ul>
<h3>Documented</h3>
<ul>
<li>io: clarify EOF condition for <code>AsyncReadExt::read_buf</code> (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3850">#3850</a>)</li>
<li>io: clarify limits on return values of <code>AsyncWrite::poll_write</code> (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3820">#3820</a>)</li>
<li>sync: add examples to Semaphore (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3808">#3808</a>)</li>
</ul>
<h2>Tokio v1.6.2</h2>
<h3>Fixes</h3>
<ul>
<li>test: sub-ms <code>time:advance</code> regression introduced in 1.6 (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3852">#3852</a>)</li>
</ul>
<p><a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3852">#3852</a>: <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/pull/3852">tokio-rs/tokio#3852</a></p>
<h2>Tokio v1.6.1</h2>
<p>This release reverts <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3518">#3518</a> because it doesn't work on some kernels due to
a kernel bug. (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3803">#3803</a>)</p>
<p><a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3518">#3518</a>: <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3518">tokio-rs/tokio#3518</a>
<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3803">#3803</a>: <a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3803">tokio-rs/tokio#3803</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="34c6a26c01"><code>34c6a26</code></a> chore: prepare Tokio v1.7.0 (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3863">#3863</a>)</li>
<li><a href="97e7830364"><code>97e7830</code></a> net: provide NamedPipe{Client, Server} types and builders (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3760">#3760</a>)</li>
<li><a href="606206ecad"><code>606206e</code></a> Merge branch 'tokio-1.6.x' into merge-1.6.x</li>
<li><a href="dfe4013ff2"><code>dfe4013</code></a> chore: prepare Tokio 1.6.2 release (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3859">#3859</a>)</li>
<li><a href="18779aa2e2"><code>18779aa</code></a> time: fix time::advance() with sub-ms durations (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3852">#3852</a>)</li>
<li><a href="2c24a028f6"><code>2c24a02</code></a> chore: re-enable test_socket_pair on FreeBSD (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3844">#3844</a>)</li>
<li><a href="f55b77aadd"><code>f55b77a</code></a> tracing: emit waker op as str instead as Debug (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3853">#3853</a>)</li>
<li><a href="21de476ae7"><code>21de476</code></a> sync: export sync::notify::Notified future publicly (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3840">#3840</a>)</li>
<li><a href="cb147a2b3f"><code>cb147a2</code></a> sync: deprecate mpsc::RecvError (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3833">#3833</a>)</li>
<li><a href="f759240254"><code>f759240</code></a> chore: update version in README.md (<a href="https://github-redirect.dependabot.com/tokio-rs/tokio/issues/3851">#3851</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/tokio-rs/tokio/compare/tokio-1.6.0...tokio-1.7.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=tokio&package-manager=cargo&previous-version=1.6.0&new-version=1.7.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

564: Bump thomaseizinger/create-pull-request from 1.0.0 to 1.1.0 r=thomaseizinger a=dependabot[bot]

Bumps [thomaseizinger/create-pull-request](https://github.com/thomaseizinger/create-pull-request) from 1.0.0 to 1.1.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/thomaseizinger/create-pull-request/blob/master/CHANGELOG.md">thomaseizinger/create-pull-request's changelog</a>.</em></p>
<blockquote>
<h2>[1.1.0] - 2021-06-16</h2>
<h3>Added</h3>
<ul>
<li>Git hook to make sure we always run <code>yarn build</code> before committing any Typescript changes. This should prevent dist/index.js from getting out of date.</li>
<li>Support for setting a proxy using the <code>HTTPS_PROXY</code> environment variable</li>
<li>Support for GitHub Enterprise by reading <code>process.env.GITHUB_REPOSITORY</code></li>
</ul>
<h3>Fixed</h3>
<ul>
<li>action.yml suggested to use <code>github-token</code> as the input where as in reality, we are looking for an input <code>github_token</code> (note the underscore!)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="285345fb83"><code>285345f</code></a> Add support for creating PR's in ghes and behind proxy (<a href="https://github-redirect.dependabot.com/thomaseizinger/create-pull-request/issues/41">#41</a>)</li>
<li><a href="13c98abb44"><code>13c98ab</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/thomaseizinger/create-pull-request/issues/37">#37</a> from orestesgaolin/patch-1</li>
<li><a href="5c8c2b6c09"><code>5c8c2b6</code></a> Fix parameters in the example</li>
<li><a href="1dde00b9ad"><code>1dde00b</code></a> Adapt LICENSE</li>
<li><a href="655db51f4a"><code>655db51</code></a> Automatically set the hookspath to our git hooks</li>
<li><a href="cedbbbb2ba"><code>cedbbbb</code></a> Update README.md</li>
<li><a href="2cd3e70bc6"><code>2cd3e70</code></a> Add readme note about inputs</li>
<li><a href="faf5ed2aa5"><code>faf5ed2</code></a> Define Inputs type through type magic on payloads types</li>
<li><a href="3fb1c8b1be"><code>3fb1c8b</code></a> Fixing git url in package.json</li>
<li><a href="e46f94e6ae"><code>e46f94e</code></a> Add git hook for making sure we update index.js</li>
<li>Additional commits viewable in <a href="https://github.com/thomaseizinger/create-pull-request/compare/1.0.0...1.1.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=thomaseizinger/create-pull-request&package-manager=github_actions&previous-version=1.0.0&new-version=1.1.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: xscd <xscd@pm.me>
2021-06-17 01:06:54 +00:00
xscd
03857ca835 Print the Bitcoin address to the terminal as a QR code 2021-06-16 15:18:16 +03:00
dependabot[bot]
e9595487f6
Bump strum from 0.20.0 to 0.21.0
Bumps [strum](https://github.com/Peternator7/strum) from 0.20.0 to 0.21.0.
- [Release notes](https://github.com/Peternator7/strum/releases)
- [Changelog](https://github.com/Peternator7/strum/blob/master/CHANGELOG.md)
- [Commits](https://github.com/Peternator7/strum/commits)

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-01 06:45:25 +00:00
bors[bot]
eb705d3e9c
Merge #515
515: Make it easier to create a bitcoin::Wallet for testing r=thomaseizinger a=thomaseizinger

Forcing the user to create an implementation of `EstimateFeeRate`
every time they want to create a wallet for testing is tedious and
leads to duplicated code.

The implementation for tests is rarely dynamic and thus can be
simplified to static arguments.

This also allows us to provide convenience constructors to make tests
that don't care about fees less distracting by reducing the number of
constants that are floating around.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-05-28 08:57:22 +00:00
dependabot[bot]
6badf09394
Bump bdk from 0.6.0 to 0.7.0
Bumps [bdk](https://github.com/bitcoindevkit/bdk) from 0.6.0 to 0.7.0.
- [Release notes](https://github.com/bitcoindevkit/bdk/releases)
- [Changelog](https://github.com/bitcoindevkit/bdk/blob/v0.7.0/CHANGELOG.md)
- [Commits](https://github.com/bitcoindevkit/bdk/compare/v0.6.0...v0.7.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-28 18:42:25 +10:00
COMIT Botty McBotface
7e6ff81efb Prepare release 0.7.0 2021-05-28 07:17:26 +00:00
bors[bot]
5385fc1aa0
Merge #531 #535
531: Bump thiserror from 1.0.24 to 1.0.25 r=thomaseizinger a=dependabot[bot]

Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.24 to 1.0.25.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/dtolnay/thiserror/releases">thiserror's releases</a>.</em></p>
<blockquote>
<h2>1.0.25</h2>
<ul>
<li>Support <code>error(transparent)</code> on errors containing a non-<code>'static</code> inner error (<a href="https://github-redirect.dependabot.com/dtolnay/thiserror/issues/113">#113</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="19cb5cee4b"><code>19cb5ce</code></a> Release 1.0.25</li>
<li><a href="e49c10f2ba"><code>e49c10f</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/dtolnay/thiserror/issues/134">#134</a> from dtolnay/nonstatic</li>
<li><a href="1ed8751081"><code>1ed8751</code></a> Support non-static AsDynError lifetimes</li>
<li><a href="51a1ff6593"><code>51a1ff6</code></a> Add regression test for issue 113</li>
<li><a href="ee2a47d3af"><code>ee2a47d</code></a> Adjust macro hygiene test formatting</li>
<li><a href="c610d97267"><code>c610d97</code></a> Update ui test suite to nightly-2021-05-14</li>
<li><a href="c10adbc25e"><code>c10adbc</code></a> Ignore manual_map clippy lint</li>
<li>See full diff in <a href="https://github.com/dtolnay/thiserror/compare/1.0.24...1.0.25">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=thiserror&package-manager=cargo&previous-version=1.0.24&new-version=1.0.25)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

535: Bitcoin network check when building PSBT r=da-kami a=da-kami

This ensures that funds are not sent to an address on the wrong network.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-05-28 06:16:59 +00:00
Thomas Eizinger
51316d8183
Make it easier to create a bitcoin::Wallet for testing
Forcing the user to create an implementation of `EstimateFeeRate`
every time they want to create a wallet for testing is tedious and
leads to duplicated code.

The implementation for tests is rarely dynamic and thus can be
simplified to static arguments.

This also allows us to provide convenience constructors to make tests
that don't care about fees less distracting by reducing the number of
constants that are floating around.
2021-05-28 15:26:19 +10:00
Thomas Eizinger
229d840990
Introduce dedicated ParseResult to simplify error handling in main 2021-05-28 15:22:55 +10:00
Thomas Eizinger
d43ba33e15
Lift out Ok wrapping from match expression 2021-05-28 15:22:52 +10:00
Daniel Karzel
766ac706de
Application arg tests
Includes validation for given Bitcoin address against network.
2021-05-28 14:50:43 +10:00
bors[bot]
baf5a0896e
Merge #536
536: Switch to using stable Rust instead of nightly r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-05-28 04:47:26 +00:00
Daniel Karzel
202f6d1fa0
Bitcoin network check when building PSBT
This ensures that funds are not sent to an address on the wrong network.
2021-05-28 09:54:35 +10:00
Daniel Karzel
c9064d5a37
Add ping protocol to ensure connection is alive
Adds the ping behaviour to both ASB and CLI behaviour that periodically pings a connected party to ensure that the underlying network connection is still alive.
This fixes problems with long-running connections that become dead without a connection closure being reported back to the swarm.
2021-05-27 11:19:27 +10:00
Thomas Eizinger
8f9d612af2
Change to stable Rust 1.52
Fix clippy warnings that are new in this version.
2021-05-25 16:11:49 +10:00
Thomas Eizinger
b8cb9e1b8b
Update secp256kfun and rand to latest version
This will allow us to compile on stable Rust.
The latest version of `secp256kfun` uses `curve25519-dalek-ng` instead
of the original curve25519-dalek crate. Instead of converting back and
forth, we simply switch to this crate as well. Judging from the README
it is just a fork because there was trouble between the maintainers of
the original crate.
2021-05-25 15:35:13 +10:00
Thomas Eizinger
e79ac4563b
Delete unused code 2021-05-25 15:32:03 +10:00
TDevD
5da075f533 fix typo 2021-05-24 10:24:06 +02:00
COMIT Botty McBotface
3f2d094f65
Prepare release 0.6.0 2021-05-24 16:00:43 +10:00
Daniel Karzel
1de907b176
Change default Monero mainnet node to xmr.to
It appears to be more stable.
Encountered issues with the previous setup, `monero-wallet-rpc` logs:

```
2021-05-24 04:23:54.852	E !r. THROW EXCEPTION: tools::error::no_connection_to_daemon
2021-05-24 04:23:54.857	E Exception at while refreshing, what=no connection to daemon
```
2021-05-24 14:44:44 +10:00
bors[bot]
ded9ea1b79
Merge #525
525: Bitcoin transaction published state r=da-kami a=da-kami

This improves the error handling on the ASB.
Once the Bitcoin redeem transaction is seen in mempool, the state machine cannot transition to a cancel scenario anymore because at that point the CLI will have redeemed the Monero.
The additional state then waits for transaction finality and prevents re-publishing the transaction.

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-05-24 02:55:31 +00:00
bors[bot]
284733d359
Merge #522
522: Add support for arm architecture to Swap CLI r=da-kami a=bonomat

Tested locally on my RPI4

Co-authored-by: Philipp Hoenisch <philipp@hoenisch.at>
2021-05-24 01:58:57 +00:00
Daniel Karzel
01af9a5676
Bitcoin transaction published state
This improves the error handling on the ASB.
Once the Bitcoin redeem transaction is seen in mempool, the state machine cannot transition to a cancel scenario anymore because at that point the CLI will have redeemed the Monero.
The additional state then waits for transaction finality.
2021-05-24 10:53:14 +10:00
bors[bot]
db319d0a90
Merge #520
520: Cli json logging r=da-kami a=da-kami

Combining `--json` with the debug file logger was a pita, so I stopped and went for a simpler approach:

If `--json` is given we just log to terminal - **no** logfiles will be created in `{data-dir}/logs`. 
The `--debug` flag applies to `--json` (i.e. if not given it will just print json on info level). We could change that to automatically fallback to debug - could add a `required_if` dependency via strucopt/clap but I did not want to invest more time into thinking about this.

Note on extending binary functionality:
As discussed with @thomaseizinger recently, we will have to think about multiple binaries soon, i.e. a binary that focuses to be used to building on top of it (that always logs json) and potientially keeping a simple CLI that is more user friendly. This also goes towards more clearly separating the application code from re-usable protocol / network code. 


Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-05-21 09:49:10 +00:00
Philipp Hoenisch
21babf9678
Support armv7 architecture for monero-wallet-rpc.
This allows us to run swap cli on a raspberry pi 4.
2021-05-21 17:55:04 +10:00
Philipp Hoenisch
a445ddd2bd
Print download URL while downloading. 2021-05-21 17:54:03 +10:00
Philipp Hoenisch
f6c7410457
Upgrade monero-wallet-rpc to version 2.0 2021-05-21 17:53:43 +10:00
bors[bot]
ba33e1acc1
Merge #519
519: Avoid application error upon `--help` r=da-kami a=da-kami

Our `preview` release is currently broken because of this issue.

The way we use clap's `get_matches_from_safe` caused parsing errors upon `--help` and `--version` to be bubbled up to the application - which causes the application to exit with an error when running `--help` and `--version`.
This is solved by using `get_matches_from` instead of `get_matches_from_safe` which handles these known clap commands internally and exits early. 

Added smoke tests to CI so we catch such kind of problems in the future. Smoke testing by calling `--help` is cheap and should be OK in CI.

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-05-21 05:43:24 +00:00
Daniel Karzel
fb9fb21c2b
CLI log statements to be more JSON friendly
Values to be logged as fields.
Upon starting a swap we print the swap-id as well.
2021-05-21 15:00:31 +10:00
Daniel Karzel
0187d9ef4f
Introduce --json flag for the CLI
When `--json` is used the CLI does not log to file, but only on the command line in json output.
2021-05-21 15:00:19 +10:00
bors[bot]
0032e820af
Merge #512
512: Bump libp2p from 0.37.1 to 0.38.0 r=thomaseizinger a=dependabot[bot]

Bumps [libp2p](https://github.com/libp2p/rust-libp2p) from 0.37.1 to 0.38.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/libp2p/rust-libp2p/releases">libp2p's releases</a>.</em></p>
<blockquote>
<h2>v0.38.0</h2>
<p>See individual <a href="https://github.com/libp2p/rust-libp2p/blob/HEAD/CHANGELOG.md">changelogs</a> for details.</p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/libp2p/rust-libp2p/blob/master/CHANGELOG.md">libp2p's changelog</a>.</em></p>
<blockquote>
<h2>Version 0.38.0 [2021-05-17]</h2>
<ul>
<li>Update individual crates.
<ul>
<li><code>libp2p-core</code></li>
<li><code>libp2p-gossipsub</code></li>
<li><code>libp2p-noise</code></li>
<li><code>libp2p-pnet</code></li>
<li><code>libp2p-wasm-ext</code></li>
</ul>
</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="0b7ee3fa92"><code>0b7ee3f</code></a> *: Prepare v0.38.0 (<a href="https://github-redirect.dependabot.com/libp2p/rust-libp2p/issues/2072">#2072</a>)</li>
<li><a href="c5bcada2c2"><code>c5bcada</code></a> protocols/gossipsub: Rework connection keep-alive (<a href="https://github-redirect.dependabot.com/libp2p/rust-libp2p/issues/2043">#2043</a>)</li>
<li><a href="9c5dd84099"><code>9c5dd84</code></a> build(deps): Update snow requirement from 0.7.1 to 0.8.0 (<a href="https://github-redirect.dependabot.com/libp2p/rust-libp2p/issues/2068">#2068</a>)</li>
<li><a href="1fdac073fc"><code>1fdac07</code></a> build(deps): Bump actions-rs/toolchain from 1 to 1.0.7 (<a href="https://github-redirect.dependabot.com/libp2p/rust-libp2p/issues/2069">#2069</a>)</li>
<li><a href="10fcc1c485"><code>10fcc1c</code></a> build(deps): Bump actions-rs/cargo from 1 to 1.0.3 (<a href="https://github-redirect.dependabot.com/libp2p/rust-libp2p/issues/2070">#2070</a>)</li>
<li><a href="82c8b1a4b3"><code>82c8b1a</code></a> build(deps): Bump actions/checkout from 2 to 2.3.4 (<a href="https://github-redirect.dependabot.com/libp2p/rust-libp2p/issues/2071">#2071</a>)</li>
<li><a href="43a8ad8fc2"><code>43a8ad8</code></a> protocols/relay/examples: Add client server instructions (<a href="https://github-redirect.dependabot.com/libp2p/rust-libp2p/issues/2060">#2060</a>)</li>
<li><a href="8988ac247e"><code>8988ac2</code></a> protocols/mdns: Fix discovered event emission. (<a href="https://github-redirect.dependabot.com/libp2p/rust-libp2p/issues/2065">#2065</a>)</li>
<li><a href="5c541a16f1"><code>5c541a1</code></a> build(deps): update salsa20 requirement from 0.7 to 0.8 (<a href="https://github-redirect.dependabot.com/libp2p/rust-libp2p/issues/2062">#2062</a>)</li>
<li><a href="d931f36428"><code>d931f36</code></a> transport/wasm-ext: Support dialing <code>Multiaddr</code> with <code>/p2p</code> protocol (<a href="https://github-redirect.dependabot.com/libp2p/rust-libp2p/issues/2058">#2058</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/libp2p/rust-libp2p/compare/v0.37.1...v0.38.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=libp2p&package-manager=cargo&previous-version=0.37.1&new-version=0.38.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-21 01:48:01 +00:00
Daniel Karzel
9ff29ae491
CLI --help and --version are handled correctly
Since we introduced our own parsing function for command line arguments, we have to make sure that clap's behaviour is handled correctly.
Clap's `get_matches_from_safe` returns an error of a certain kind, of which `ErrorKind::HelpDisplayed` and `ErrorKind::VersionDisplayed ` have to be handled to properly print the help/version and exit the program.
The clap error includes the message, so we print help/version in main now and ensure the program exits with `0` afterwards.
2021-05-21 11:46:11 +10:00
Daniel Karzel
22bf48c287
Fix bug that breaks swap ID for logging 2021-05-20 14:52:36 +10:00
bors[bot]
bdb88f89cb
Merge #490
490: Mainnet switch r=da-kami a=da-kami

Fixes  #446
Fixes #360 
Fixes #506 
Fixes #478 

To be precise: It is actually a testnet switch, because I think mainnet should be default.

I took several assumptions on the way (e.g. network support, ...).

At this stage any feedback welcome :)

TODO:

- [ ] successful mainnet swap with this code base before merging :)

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-05-20 04:16:55 +00:00
Daniel Karzel
2db470f099
Bitcoin=2 Monero=10 default finality confirmations
It is currently not expected that ASB and CLI are used for swaps > 10_000$ equivalent to XMR/BTC, thus the finality confirmations were reduced to an equivalent of 20 mins of work (2 blocks for Bitcoin, 10 for Monero).
Monero enforces 10 unlocking blocks until the balance is spendable, so the finality confirmations cannot be set lower than 10.
2021-05-20 13:05:52 +10:00
Daniel Karzel
6694e4f4e0
Ensure that output of lock script is at tx-output index 0
We subscribe to transactions upon broadcast, where we use output index `0` for the subscription.
In order to ensure that this subscription is guaranteed to be for the locking script (and not a change output) we now ensure that the locking script output is always at index `0` of the outputs of the transaction.

We chose this solution because otherwise we would have to add more information to broadcasting a transaction.
This solution is less intrusive, because the order of transaction outputs should not have any side effects and ensuring index `0` makes the whole behaviour more deterministic.
2021-05-20 13:05:52 +10:00
Daniel Karzel
bae38a712f
Sync on interval instead of ping
Since we don't rely on long running subscriptions anymore we can remove the ping that was used to ensure a connection refresh.
2021-05-20 13:05:51 +10:00
Daniel Karzel
efb51820b1
Poll block headers for latest block on each iteration
The Electrum block-header subscription did not provide us with block headers, because upon the connection being closed by a node the subscription would end.
Re-newing the the subscription upon re-connect is not easily achievable, that's why we opted for a polling mode for now, where we start a block header subscription on every update iteration, that is only used once (when the subscription is made).
2021-05-20 13:05:51 +10:00
Daniel Karzel
f2e43ea565
Let testnet setup reflect mainnet
Our test values should reflect what we test on mainnet more closely to avoid bugs that are only observed when using mainnet settings.
2021-05-20 13:05:51 +10:00
Daniel Karzel
4dd696ebe1
Fix monero-wallet-rpc startup for mainnet CLI
There is no `--mainnet` flag.
Since we cannot just pass an empty string to `.arg()` we use the `.args()` method to pass nothing for mainnet and the respective flags for stagenet and testnet.
2021-05-20 13:05:51 +10:00
Daniel Karzel
1aaffb09f9
Refactor ASB test-/mainnet default dir init 2021-05-20 13:05:51 +10:00
Daniel Karzel
cfa85e0bad
Simplify ASB initial setup signature 2021-05-20 13:05:51 +10:00
Daniel Karzel
7f8af7926d
ASB config may specify finality confirmations
By default the finality confirmations of the network's `env::Config` will be applied and no finality confirmations will be persisted on disk in the config file.
It is however possible to set finality confirmations in the config file for bitcoin and monero for power users at their own risk.
If set the defaults will be overwritten with the parameter from the config file upon startup.
2021-05-20 13:05:51 +10:00
Daniel Karzel
af60d3bb54
Network check upon spot price request 2021-05-20 13:03:29 +10:00
Daniel Karzel
02974811ad
Activate mainnet for the ASB
To run the ASB on testnet, one actively has to provide the `--testnet` flag.
Mainnet and testnet data and config are separated into sub-folders, i.e. `{data/config-dir}/asb/testnet` and `{data-dir}/asb/mainnet`.
The initial setup is also per network. If (default) config for the network cannot be found the initial setup is triggered.
Startup includes network check to ensure the bitcoin/monero network in config file is the same as the one in the `env::Config`.

Note: Wallet initialization is done with the network set in the `env::Config`, the network saved in the config file is just to indicate what network the config file is for.
2021-05-20 12:58:39 +10:00
Daniel Karzel
9ac5b635d7
Introduce own de-/serializable monero::Network 2021-05-20 12:58:30 +10:00
Daniel Karzel
69cf12620d
Activate mainnet for the CLI
This includes testing CLI commandline args
Clap's `default_value_with` actually did not work on `Subcommand`s because the parent's flags were not picked up.
This was fixed by changing parameters dependent on testnet/mainnet to options.
This problem should have been detected by tests, that's why the command line parameter tests were finally (re-)added.

Thanks to @rishflab for some pre-work for this.
2021-05-20 12:57:58 +10:00
dependabot[bot]
6c206c7067
Bump libp2p from 0.37.1 to 0.38.0
Bumps [libp2p](https://github.com/libp2p/rust-libp2p) from 0.37.1 to 0.38.0.
- [Release notes](https://github.com/libp2p/rust-libp2p/releases)
- [Changelog](https://github.com/libp2p/rust-libp2p/blob/master/CHANGELOG.md)
- [Commits](https://github.com/libp2p/rust-libp2p/compare/v0.37.1...v0.38.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-05-18 06:33:38 +00:00
Thomas Eizinger
a3f436104f
Use tokio-tar from crates.io 2021-05-18 12:52:17 +10:00
Thomas Eizinger
75c5db53b2
Remove tokio-tar from workspace in favor of git dependency
Fixes #315.
Fixes #227.
2021-05-17 11:04:20 +10:00
Daniel Karzel
1cdc23de32
Explicitly specify monero-wallet-rpc deamon port
In order to allow people to plug into public nodes / be more flexible with their own setup we now enforce specifying the monero daemon port to be used by the `monero-wallet-rpc`.
2021-05-14 09:50:52 +10:00
Daniel Karzel
343badbb4b
Remove duplication and cleanup
In the past we had problems with flags/parameter changes several times, where on instance was changed, buy another one was missed. This should mitigate this problem.
This patch introduces structs for all duplicated parameters and uses flatten to only have one point for changes.

Additionally removes all mentions of `alice` from the commands / variables. This code is on an application level and should not be concerned with swap protocol roles.
2021-05-14 09:50:50 +10:00
Daniel Karzel
4e1f3f82bd
Remove param from names
Did not add any value, more readable with just bitcoin and monero.
2021-05-14 09:50:49 +10:00
Daniel Karzel
657ac1e2e4
Bitcoin parameters that can be reused
Get rid of parameter duplication.
2021-05-14 09:50:47 +10:00
Daniel Karzel
a489564857
Remove unused Electrum HTTP default URL 2021-05-14 09:50:44 +10:00
Philipp Hoenisch
493545d07f
Improve logging for Swap Cli. 2021-05-12 16:31:32 +10:00
Philipp Hoenisch
4f45a26a83
Move check for max_giveable into the function. 2021-05-12 16:31:32 +10:00
Philipp Hoenisch
7fc5a47619
Add checks to max_giveable amount.
We need to check two things:
- balance to be higher than dust amount (546).
- balance to be higher than min-relay fee.

Additionally, the tx_builder might fail if not enough funds are in the wallet to pay for the overall transaction fees.
2021-05-12 16:31:32 +10:00
Philipp Hoenisch
26e0383e17
Apply suggestions from code review
Co-authored-by: Daniel Karzel <daniel.karzel@coblox.tech>
2021-05-11 16:06:44 +10:00
Philipp Hoenisch
fc0cceb180
Toggle json logs using commandline flag. 2021-05-11 15:28:25 +10:00
Philipp Hoenisch
316f95c65b
Always log whole causality chain for errors. 2021-05-11 15:27:53 +10:00
Philipp Hoenisch
c011e95062
Improve logging by adding details as fields instead of into the msg. 2021-05-11 15:27:53 +10:00
Philipp Hoenisch
1706b36800
Log exchange rate at each state. 2021-05-11 15:27:49 +10:00
bors[bot]
227c383d76
Merge #481
481: Min buy amount r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-05-11 04:08:59 +00:00
Daniel Karzel
652aae9590
Introduce a minimum buy amount
Introduces a minimum buy Bitcoin amount similar to the maximum amount already present.
For the CLI the minimum amount is enforced by waiting until at least the minimum is available as max-giveable amount.
2021-05-11 12:03:02 +10:00
Daniel Karzel
6d3cf0af91
Include too low balance into Alice's error 2021-05-11 12:03:02 +10:00
Daniel Karzel
1d62f4916c
Move max_buy and ask_spread into config
Max-buy and spread is not something that one would configure on every run.
More convenient to keep this in the config.

The max-buy Bitcoin value was adapted to `0.02` which is more reasonable for mainnet.
Activated feature `serde-float` to serialize the spread (Decimal) as float instead of string.

```
...

[maker]
max_buy_btc = 0.02
ask_spread = 0.02
```
2021-05-11 12:02:57 +10:00
Philipp Hoenisch
330269a1e9
Update assert_weight test to account for a range up to 8 bytes.
Weights fluctuate because of the length of the signatures. Valid ecdsa signatures can have 68, 69, 70, 71, or 72 bytes. Since most of our transactions have 2 signatures the weight can be up to 8 bytes less than the static weight (4 bytes per signature).
2021-05-11 10:50:24 +10:00
Daniel Karzel
538b25a6dd
Only create config-directory on init success
We should only create the file if the user finished the initial setup correctly.
2021-05-11 10:32:25 +10:00
bors[bot]
d96e20a5b0
Merge #479
479: Use rust_decimal in estimate_fee function. r=bonomat a=bonomat

Follow-up PR from #466 

Co-authored-by: Philipp Hoenisch <philipp@hoenisch.at>
2021-05-10 23:00:12 +00:00
Philipp Hoenisch
b5073e3052
Use rust_decimal in estimate_fee function. 2021-05-10 10:53:43 +10:00
Daniel Karzel
23d9637a4b
Work in review comments 2021-05-07 16:21:02 +10:00
Daniel Karzel
daa572e5bf
Move recovery commands in dedicated module
Less clutter in the folder structure.
2021-05-07 16:21:02 +10:00
Daniel Karzel
4deb96a3c5
ASB manual recovery commands
Adds `cancel`, `refund`, `punish`, `redeem` and `safely-abort` commands to the ASB that can be used to trigger the specific scenario for the swap by ID.
2021-05-07 16:19:11 +10:00
Daniel Karzel
efcd39eeef
Add info messages to each subcommand
`asb --help` :

(...)

SUBCOMMANDS:
    balance         Prints the Bitcoin and Monero balance. Requires the monero-wallet-rpc to be running.
    help            Prints this message or the help of the given subcommand(s)
    history         Prints swap-id and the state of each swap ever made.
    start           Main command to run the ASB.
    withdraw-btc    Allows withdrawing BTC from the internal Bitcoin wallet.
2021-05-07 16:12:50 +10:00
Daniel Karzel
0c616c7437
Move loading the state into the function
In the production code it is a weird indirection that we load the state and then pass in the state and the database.
In the tests we have one additional load by doing it inside the command, but loading from the db is not expensive.
2021-05-07 16:12:49 +10:00
Daniel Karzel
89b3d07eba
Network protocol tests for spot_price behaviour
Each test spawns swarm for Alice and Bob that only contains the spot_price behaviours and uses a memory transport.
Tests cover happy path (i.e. expected price is returned) and error scenarios.
Implementation of `TestRate` on `LatestRate` allows testing rate fetch error and quote calculation error behaviour.

Thanks to @thomaseizinger for ramping up the test framework for comit-rs in the past!
2021-05-07 15:00:29 +10:00
Daniel Karzel
03a0dc73cd
Alice's spot_price Behaviour reports back Error
Instead of handling all errors on the inside spot_price errors are bubbled up (as `SwapRequestDeclined`).
This allows us to test both Alice's and Bob's behaviour for all scenarios.
2021-05-07 15:00:29 +10:00
Daniel Karzel
5aac76598d
Decouple ASB/CLI Errors from Error sent over wire
What goes over the wire should not be coupled to the errors being printed.
For the CLI and ASB we introduce a separate error enum that is used for logging.
When sending over the wire the errors are mapped to and from the `network::spot_price::Error`.

As part of Bob-specific spot_price code was moved from the network into bob.
Clearly separation of the network API from bob/alice.
2021-05-07 15:00:29 +10:00
Daniel Karzel
52f648e1de
Alice's spot price logic into dedicated behaviour
Move Alice's spot price logic into a dedicated network behaviour that handles all the logic.
The new behaviour encapsulates the complete state necessary for spot price request decision making.
The network behaviour cannot handle asynchronous calls, thus the balance is managed inside the spot price and has to updated regularly from the outside to ensure the spot price balance check has up to date data.
At the moment the balance is updated upon an incoming quote requests.

Code that is relevant for both ASB and CLI remains in the `network::spot_price` module (e.g. `network::spot_price::Error`).
2021-05-07 15:00:29 +10:00
Daniel Karzel
ea76ae5821
Return proper error to CLI for all expected scenarios
When a CLI requests a spot price have some errors that are expected, where we can provide a proper error message for the CLI:
- Balance of ASB too low
- Buy amount sent by CLI exceeds maximum buy amount accepted by ASB
- ASB is running in maintenance mode and does not accept incoming swap requests

All of these errors returns a proper error to the CLI and prints a warning in the ASB logs.
Any other unexpected error will result in closing the channel with the CLI and printing an error in the ASB logs.
2021-05-07 14:52:51 +10:00
Daniel Karzel
f6497778ed
Add resume-only mode for the ASB
Resume-only is a maintenance mode where no swaps are accepted but unfinished swaps are resumed.
This is achieve by ignoring incoming spot-price requests (that would lead to execution setup) in the event-loop.
2021-05-07 14:52:51 +10:00
Philipp Hoenisch
0090e3b48e
Typo 2021-05-07 10:35:22 +10:00
Philipp Hoenisch
59a55dcbdd
Remove todo for cleanup note. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
e93eeb81a2
Added some proptests. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
040cce1eb6
Format all the files 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
68ae47edf4
Log error message. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
aebdb063f1
Remove TODO 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
9fb1a43f29
Rename variable. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
cfdbacfbb5
Add comment.
The weight of our transactions can fluctuate by +-2 wu because our transactions have 2 signatures
2021-05-07 10:24:41 +10:00
Philipp Hoenisch
e69a2c9111
Apply suggestions from code review
Co-authored-by: Daniel Karzel <daniel.karzel@coblox.tech>
2021-05-07 10:24:41 +10:00
Philipp Hoenisch
dc8dd5af28
Add relative and absolute max transaction fee. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
dc6ab0fa52
Ensure that constant weights do not go out of sync with code. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
7fe9087bc2
Pull trait-bounds up one level for easier testing. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
77f6f11a7f
Pass address/fees into State0 instead of passing in the wallet. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
14c5a4f025
Add upper bound for bitcoin fees of 100,000 satoshi.
Fees are hard to compute and it is too easy to get wrong and lose a lot of money. Hence, a hardcoded maximum of 100,000 satoshi for a single transaction is in place.
2021-05-07 10:24:41 +10:00
Philipp Hoenisch
46e0449b8e
Add config/argument to swap/asb to configure bitcoin tx fees. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
9e8b788aa9
Rename weight constants. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
ee90c228b4
Dynamically calculate fees using electrum's estimate_fee.
Electrum has an estimate-fee feature which takes as input the block you want a tx to be included.
The result is a recommendation of BTC/vbyte.
Using this recommendation and the knowledge about the size of our transactions we compute an appropriate fee.
The size of the transactions were taken from real transactions as published on bitcoin testnet.
Note: in reality these sizes might fluctuate a bit but not for much.
2021-05-07 10:24:41 +10:00
Philipp Hoenisch
38540b4de5
Dynamically chose fee for TxCancel.
Bob chooses the fee for TxCancel because he is the one that cares.
2021-05-07 10:24:41 +10:00
Philipp Hoenisch
1012e39527
Dynamically chose fee for TxRefund and TxPunish.
Alice chooses the fee for TxPunish because she is the one that cares.
Bob chooses the fee for TxRefund because he is the one that cares.

Note must be taken here because if the fee is too low (e.g. < min tx fee) then she might not be able to publish TxRedeem at all.
2021-05-07 10:24:41 +10:00
Philipp Hoenisch
d5c1b6693e
Dynamically chose fee for TxRedeem.
Alice chooses the fee for TxRedeem because she is the one that cares. Note must be taken here because if the fee is too low (e.g. < min tx fee) then she might not be able to publish TxRedeem at all.
2021-05-07 10:24:41 +10:00
Philipp Hoenisch
002e7b38c3
Define TX_FEE within test files only. 2021-05-07 10:24:41 +10:00
Philipp Hoenisch
1db7586632
Increase timeout sending/receiving protocol messages. 2021-05-04 15:38:55 +10:00
bors[bot]
e7785d2c83
Merge #434
434: Introduce monero-wallet crate r=thomaseizinger a=thomaseizinger

This PR:

1. ~Introduce a crate for the epee binary serialization as a serde format~: Released here: https://github.com/comit-network/monero-epee-bin-serde
2. Extends the MoneroRPC client with two binary calls
3. Introduces a `monero-wallet` crate that for now just provides functionality for choosing random key offsets. Together with the the ability to produce bulletproofs and ring signatures, this should be enough for signing Monero transactions locally.

(1) and (2) are a prerequisite for (3).

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-05-03 03:21:18 +00:00
bors[bot]
cf1c448b7c
Merge #460
460: Different default directories for CLI and ASB r=da-kami a=da-kami

Fixes #437 

Using the same default directory as data-/config-dir has caused unwanted side effects when running both applications on the same machine.
Use these directory names:
- ASB: `xmr-btc-swap-asb`
- CLI: `xmr-btc-swap-cli`

Since the functionality is now application specific the respective functions were moved into the appropriate module of the application.

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-04-30 04:24:29 +00:00
bors[bot]
1244b30094
Merge #459
459: Use dprint for formatting Cargo.toml files r=thomaseizinger a=thomaseizinger

Invoking cargo tomlfmt on all files is a PITA and as we can see from
the CI scripts, it is often forgotten to as new crates are added to
the workspace.

Using dprint for toml files fixes this.

Unfortunately, we can't use dprint for Rust code yet because there
hasn't been a release of rustfmt in quite a while but we are already
using features from a newer rustfmt via rustup.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-04-30 01:19:40 +00:00
Daniel Karzel
69f7565746
!fixup Different default directories for CLI and ASB
Using the same default directory as data-/config-dir has caused unwanted side effects when running both applications on the same machine.
Use these directory names:
- ASB: xmr-btc-swap/asb
- CLI: xmr-btc-swap/cli

Since the functionality is now application specific the respective functions were moved into the appropriate module of the application.
2021-04-30 11:03:13 +10:00
Thomas Eizinger
dd6bfd3bf4
Extend RPC client for monerod with binary requests 2021-04-30 10:28:45 +10:00
Daniel Karzel
b0ffeeab1d
Different default directories for CLI and ASB
Using the same default directory as data-/config-dir has caused unwanted side effects when running both applications on the same machine.
Use these directory names:
- ASB: xmr-btc-swap-asb
- CLI: xmr-btc-swap-cli

Since the functionality is now application specific the respective functions were moved into the appropriate module of the application.
2021-04-29 19:02:16 +10:00
Daniel Karzel
08fecb8fe3
Peer check for incoming transfer proofs
Bob validates that incoming transfer proof messages are coming from the peer-id of Alice.
Currently Bob will ignore any transfer proof message that is not coming from the counterparty peer-id associated to the current swap in execution.
Once we add support for trying to save received transfer proofs for swaps that are currently not in execution we can also adapy allowing this for different counterparty peer-ids. This requires access to the database in Bob's event loop.
2021-04-29 18:28:14 +10:00
Daniel Karzel
3c2dfa830a
Peer check for incoming encrypted signatures
Alice validates that incoming encsig messages are coming from the peer-id that is associated with the swap.
Encsig message from a peer-id different to the one associated with the swap are ignored.
2021-04-29 18:24:45 +10:00
Thomas Eizinger
1820139786
Use dprint for formatting Cargo.toml files
Invoking cargo tomlfmt on all files is a PITA and as we can see from
the CI scripts, it is often forgotten to as new crates are added to
the workspace.

Using dprint for toml files fixes this.

Unfortunately, we can't use dprint for Rust code yet because there
hasn't been a release of rustfmt in quite a while but we are already
using features from a newer rustfmt via rustup.
2021-04-29 17:35:02 +10:00
Philipp Hoenisch
ea6e2f8f09
Simplify to_address_string by implying more context on the structure. 2021-04-28 16:21:31 +10:00
Philipp Hoenisch
c8e6db24f8
Derive Tor secret key from seed. 2021-04-27 16:39:32 +10:00
Philipp Hoenisch
3a5395d7a5
Optimize torut features.
OnionV2 addresses are being deprecated and will be fully phased out on 15.10.2021: https://blog.torproject.org/v2-deprecation-timeline
2021-04-27 16:39:32 +10:00
Philipp Hoenisch
632293cf91
Add support for swapping through Tor.
This PR does a few things.
* It adds a TorTransport which either dials through Tor's socks5 proxy or via clearnet.
* It enables ASB to register hidden services for each network it is listening on. We assume that we only care about different ports and re-use the same onion-address for all of them. The ASB requires to have access to Tor's control port.
* It adds support to dial through a local Tor socks5 proxy. We assume that Tor is always available on localhost.  Swap cli only requires Tor to be running so that it can send messages via Tor's socks5 proxy.
* It adds a new e2e test which swaps through Tor. For this we assume that Tor is currently running on localhost. All other tests are running via clear net.
2021-04-27 14:51:41 +10:00
bors[bot]
e262345b4f
Merge #442
442: Minor cleanups towards implementing a Monero wallet for local signing r=thomaseizinger a=thomaseizinger

Extracted out of #434.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-04-27 02:16:27 +00:00
Thomas Eizinger
8d76607343
Refactor monero-harness containers
1. Split up image::Monero into Monerod and MoneroWalletRpc
2. Don't use `bash` to run the internal command. Instead we disable
the entrypoint script as per https://github.com/XMRto/monero#raw-commands
3. Remove the start up delay by listening for the correct log message.
To make this more resilient, we make the log level NOT configurable and
instead always log verbosely.
2021-04-26 18:12:57 +10:00
Thomas Eizinger
0970c2bc72
Initialize reqwest clients with verbose logging 2021-04-26 18:12:56 +10:00
Daniel Karzel
0f11ab051e
Print peer ID on debog when starting CLI
In order to add more context to the debug logs we print Bob's peer ID.
This allows identifying peer related logs on the ASB.
2021-04-26 13:00:37 +10:00
Thomas Eizinger
dc840e1562
Take wallet names by reference
We are always passing constants here. Make that more ergonomic.
2021-04-26 12:45:40 +10:00
Thomas Eizinger
22bdc08c83
Get rid of Bob's swap Builder
Doesn't serve any purpose. We are better of just having two
constructors.
2021-04-26 12:45:40 +10:00
Thomas Eizinger
e266fb07ef
Don't stutter 2021-04-26 12:45:39 +10:00
Thomas Eizinger
7adeaae12d
Be smart about how we import Config
By saying env::Config, we can save a line of code in the imports
and make it clearer, what kind of `Config` this is.
2021-04-26 12:45:39 +10:00
Thomas Eizinger
be5bf01ed4
Don't overqualify types that are already imported 2021-04-26 12:45:38 +10:00
Thomas Eizinger
325fcbdb8c
Introduce protocol::bob::behaviour to mimic structure from alice module 2021-04-26 12:45:37 +10:00
Thomas Eizinger
5b515d6fb2
Don't qualify with alice:: if we are within a module of Alice 2021-04-26 12:45:37 +10:00
Thomas Eizinger
a31d6febca
We don't need to import ourselves 2021-04-26 12:45:36 +10:00
Thomas Eizinger
881913ad9c
Re-order content of harness/mod.rs in a sane way
Most important things come first, remaining items are defined roughly
in the order they are used by the top level components.
2021-04-26 12:45:36 +10:00
Thomas Eizinger
6d06db3259
Use macro-based JSON-RPC client 2021-04-26 12:45:35 +10:00
dependabot[bot]
19483c5ead
Bump libp2p from 0.36.0 to 0.37.1
Bumps [libp2p](https://github.com/libp2p/rust-libp2p) from 0.36.0 to 0.37.1.
- [Release notes](https://github.com/libp2p/rust-libp2p/releases)
- [Changelog](https://github.com/libp2p/rust-libp2p/blob/master/CHANGELOG.md)
- [Commits](https://github.com/libp2p/rust-libp2p/compare/v0.36.0...v0.37.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-04-20 11:51:40 +10:00
Thomas Eizinger
39eea61538
Upgrade to bdk 0.6 2021-04-19 10:14:14 +10:00
COMIT Botty McBotface
43dc74cd9d Prepare release 0.5.0 2021-04-17 07:23:09 +00:00
Daniel Karzel
c1e993deb2
Json codec for quote protocol
A `RequestResponseCodec` for pull-based protocols where the response is encoded using JSON.
This was added to more properly express the behavior of the quote protocol, where the dialer
doesn't send any message and expects the listener to directly send the response.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-04-16 16:00:45 +10:00
Daniel Karzel
f70e2aa8d6
Listen on tcp and websocket transports
- Listen on both tcp and websockets as default
- Listening addresses in config as array
- Configure fallback transport using `or_transport` - if listening on a given address fails on WS, we fall back to TCP.
2021-04-16 16:00:38 +10:00
Thomas Eizinger
b417950f99
Improve error reporting of failed protocols
Instead of forwarding every error, we deliberately ignore certain
variants that are not worth being printed to the log. In particular,
this concerns "UnsupportedProtocols" and "ResponseOmission".

To make this less verbose we introduce a macro for mapping a
`RequestResponseEvent` to `{alice,bob}::OutEvent`. We use a macro
because those `OutEvent`s are different types and the only other
way of abstracting over them would be to introduce traits that we
implement on both of them.

To make the macro easier to use, we move all the `From` implementations
that convert between the protocol and the more high-level behaviour
into the actual protocol module.
2021-04-14 10:34:06 +10:00
Thomas Eizinger
f0f7288bb6
Introduce a redial::Behaviour
This behaviour makes Bob re-dial Alice with an exponential backoff as
soon as the connection is lost.
2021-04-14 10:07:14 +10:00
Thomas Eizinger
d4c10a1292
Introduce swarm::{alice,bob} function to construct a Swarm instance 2021-04-14 10:06:32 +10:00
bors[bot]
19766b9759
Merge #405
405: Concurrent swaps with same peer r=da-kami a=da-kami

Fixes #367 

- [x] Concurrent swaps with same peer

Not sure how much more time I should invest into this. We could just merge the current state and then do improvements on top...?

Improvements:

- [x] Think `// TODO: Remove unnecessary swap-id check` through and remove it
- [x] Add concurrent swap test, multiple swaps with same Bob
- [ ] Save swap messages without matching swap in execution in the database
- [ ] Assert the balances in the new concurrent swap tests
- [ ] ~~Add concurrent swap test, multiple swaps with different Bobs~~
- [ ] ~~Send swap-id in separate message, not on top of `Message0`~~

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-04-13 08:50:44 +00:00
Daniel Karzel
c976358c37
Multiple swaps with the same peer
- Swap-id is exchanged during execution setup. CLI (Bob) sends the swap-id to be used in his first message.
- Transfer poof and encryption signature messages include the swap-id so it can be properly associated with the correct swap.
- ASB: Encryption signatures are associated with swaps by swap-id, not peer-id.
- ASB: Transfer proofs are still associated to peer-ids (because they have to be sent to the respective peer), but the ASB can buffer multiple
- CLI: Incoming transfer proofs are checked for matching swap-id. If a transfer proof with a different swap-id than the current executing swap is received it will be ignored. We can change this to saving into the database.

Includes concurrent swap tests with the same Bob.

- One test that pauses and starts an additional swap after the transfer proof was received. Results in both swaps being redeemed after resuming the first swap.
- One test that pauses and starts an additional swap before the transfer proof is sent (just after BTC locked). Results in the second swap redeeming and the first swap being refunded (because the transfer proof on Bob's side is lost). Once we store transfer proofs that we receive during executing a different swap into the database both swaps should redeem.

Note that the monero harness was adapted to allow creating wallets with multiple outputs, which is needed for Alice.
2021-04-13 18:16:19 +10:00
Daniel Karzel
46f144ac67
Switch monero-rpc to debug in tests
To be able to see CI monero RPC errors.
2021-04-13 17:43:10 +10:00
bors[bot]
2f19222948
Merge #397
397: Always log at debug level to file r=rishflab a=rishflab

WILL SQUASH DOWN TO 3 COMMITS WHEN APPROVED!

Log at debug level to file

EnvFilter is applied globally. This means you cannot log at INFO level 
to the terminal and at DEBUG level to log files. To get a around this 
limitation I had to implement the layer trait on a new type and filter 
in the on_event() trait method. Each swap has its own log file denoted 
by its swap_id. The logger appends to the existing file when resuming a 
swap.

Closes #278 


I think the `DebugTerminalPritner` and `InfoTerminalPrinter` could be consolidated with some effort with some generics wizardry. It works for now and I think it can be done later. I wish in general there was a cleaner way to do this.
 

Co-authored-by: rishflab <rishflab@hotmail.com>
2021-04-09 00:19:56 +00:00
Daniel Karzel
489696ee08
Swap-id as file name for generated Monero wallet
Instead of using the private view-key as wallet filename we use the swap-id, to be able to identify which wallet is associated with which swap.
2021-04-08 19:23:54 +10:00
Daniel Karzel
548f057726
Try to open wallet in case generate_from_keys fails 2021-04-08 19:15:30 +10:00
Daniel Karzel
b60790a32c
Allow buffering multiple transfer proofs per peer
Allowing multiple swaps with the same peer requires buffering multiple transfer proofs per peer.
2021-04-08 17:02:18 +10:00
rishflab
8805002f96 Remove redundant noun from tracing initialiser functions 2021-04-08 16:14:32 +10:00
rishflab
9745d150e7 Log at debug level to file
EnvFilter is applied globally. This means you cannot log at INFO level
to the terminal and at DEBUG level to log files. To get a around this
limitation I had to implement the layer trait on a new type and filter
in the on_event() trait method. Each swap has its own log file denoted
by its swap_id. The logger appends to the existing file when resuming a
swap.

Closes #278
2021-04-08 16:10:35 +10:00
rishflab
e517c5934e Move asb tracing initializer to asb module 2021-04-08 10:51:54 +10:00
COMIT Botty McBotface
1687f84aa1 Prepare release 0.4.0 2021-04-06 08:20:31 +00:00
bors[bot]
32912ebd4a
Merge #394
394: Add a configurable spread to the ASB r=thomaseizinger a=thomaseizinger

Fixes #381.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-04-06 07:39:11 +00:00
bors[bot]
f0a8be6835
Merge #396
396: Remove default connection details from CLI r=thomaseizinger a=rishflab

Connecting buyers to us by default is not consistent with our vision of
a decentralised network of sellers.

Closes #395

Co-authored-by: rishflab <rishflab@hotmail.com>
2021-04-06 07:26:24 +00:00
rishflab
9b0467d43a Remove default connection details from CLI
Connecting buyers to us by default is not consistent with our vision of
a decentralised network of sellers.

Closes #395
2021-04-06 16:59:11 +10:00
bors[bot]
e0b859bb1e
Merge #387
387: Improve the resilience of the network layer r=thomaseizinger a=thomaseizinger

We improve the resilience in two ways:

1. Use a timeout on Bob's side for the execution-setup.
2. Use the `bmrng` library to model the communication between Alice and Bob.

See commit messages for details.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-04-06 06:20:30 +00:00
Thomas Eizinger
a99d12b9df
Add a configurable spread to the ASB
Fixes #381.
2021-04-06 16:16:58 +10:00
Thomas Eizinger
3e0301a9d4
Move FixedRate into event_loop module
This is where these types are used, they can be defined in there.
2021-04-06 16:16:57 +10:00
Thomas Eizinger
654cfff2a8
Make kraken module emit PriceUpdates instead of Rates 2021-04-06 16:16:56 +10:00
Thomas Eizinger
cfc530e8ab
Make ask field of Rate private 2021-04-06 16:16:53 +10:00
Thomas Eizinger
bc46d95985
Remove unnecessary Serialize implementations 2021-04-06 16:08:42 +10:00
Daniel Karzel
0341e7c9fc
Point BDK to commit that fixes overflow error
Edge cases of UTXOs where value < fee cause the BDK's `coin_select` calculation to panic.
This issue was fixed upstream thus we point the BDK dependency against the commit of the merged fix.
2021-04-06 14:50:27 +10:00
rishflab
7df93faa4b Remove unnecessary wrapper struct 2021-04-06 11:05:36 +10:00
Daniel Karzel
04b49d7117 Add command to print Bitcoin and Monero balance 2021-04-06 09:19:43 +10:00
Daniel Karzel
96008ec130 Add command to withdraw BTC
If no amount is given the wallet will be drained.
2021-04-06 09:19:43 +10:00
Daniel Karzel
f5e81bb0ee Move seed and env_config outside Start command 2021-04-06 09:19:43 +10:00
Daniel Karzel
d9d697821e Separate bitcoin and monero wallet initialization 2021-04-06 09:19:43 +10:00
Daniel Karzel
084fc618b4 Test Alice refunds if restarted and Bob refunded 2021-04-01 17:47:01 +11:00
Thomas Eizinger
1b2f476cae
Have --force flag only override the timelock check
It might very well be that the cancel transaction is already published.
If that is the case, there is no point in failing the command. We simply
transition to cancel and exit normally.

The reason this comes up now is because Alice now properly waits for
the cancel timelock as well and publishes the cancel transaction first.

Ultimately, she should not do that because there is no benefit to her
unless she can also publish the punish transaction.
2021-04-01 17:28:38 +11:00
Thomas Eizinger
24f444b9f7
Race sending transfer proof against cancel timelock
Sending the transfer proof might never resolve because Bob doesn't
come back online. In that case, we need to make sure we bail out
as soon as the timelock expires.
2021-04-01 17:09:18 +11:00
Thomas Eizinger
c0785ab05a
"Buffer" all requests to Alice until we are connected
We use the "precondition" feature of the `tokio::select!` macro to
avoid polling certain futures. In particular, we skip polling all
futures that - when resolved - require us to send a message to Alice.
2021-04-01 17:09:17 +11:00
Thomas Eizinger
1b0c29b424
Use bmrng to model communicaton of Alice's EventLoop with the handle
This allows us to delay the ACKing of the encrypted signature up until
the swap has actually requested it.

Similarly, it allows us to wait for the ACK of the transfer proof within
the swap before continuing.
2021-04-01 17:09:17 +11:00
Thomas Eizinger
1c47b32681
Use bmrng to model communicaton of Bob's EventLoop with the handle
bmrng is a library providing a request-response channel that allows
the receiving end of the channel to send a response back to the sender.
This allows us to more accurately implement the functions on the
`EventLoopHandle`. In particular, we now _wait_ for the ACK of specific
messages from the other party before resolving the future.

For example, when sending the encrypted signature, the async function
on the `EventLoopHandle` does not resolve until we received the ACK
from the other party.

We also delete the `Channels` abstraction in favor of directly creating
bmrng channels. This allows us to directly control the channel buffer
which we set to 1 because we don't need more than that on Bob's side.
2021-04-01 17:09:17 +11:00
Thomas Eizinger
958e5b12bc
Don't match on expired_timelocks and race it in a select in parallel
There is no point in first checking for the expired timelocks and
then constructing a `select!` that also watches for the timelock to
expiry.

We can simply only have the select! invocation to achieve the same
effect. In case the timelock is already expired, this future will
resolve immediately.

Normally, the polling order of `select!` is pseudo-random. We
configure it to be _biased_ here to make sure the futures are polled
in order.
2021-04-01 17:08:26 +11:00
Thomas Eizinger
dbe03ba1cf
Timeout Bob's execution-setup after 10 seconds
The execution setup is our only libp2p protocol that doesn't have
a timeout built-in. Hence, if anything fails on Alice's side, we
would wait here forever.

Wrapping the future in a timeout ensures that we fail eventually
if this protocol doesn't succeed.
2021-04-01 17:08:26 +11:00
Thomas Eizinger
5d75f1adba
Remove import line in favor of FQ macro usage 2021-04-01 17:08:26 +11:00
Thomas Eizinger
4c2e254543
Don't log subscription
This object is very verbose and not meant to be logged.
2021-04-01 17:08:25 +11:00
Thomas Eizinger
5b230bc75f
Don't import tracing macros
Typing them out is quicker than constantly adjusting imports.
2021-04-01 17:08:25 +11:00
Thomas Eizinger
90a7760124
Add some log statements to bob::cancel 2021-04-01 17:08:25 +11:00
Thomas Eizinger
3f54b39281
Make all error messages start with an uppercase letter 2021-04-01 16:12:14 +11:00
Thomas Eizinger
0ef9d97679
Remove delegation functions in favor of public fields
We don't need to hide the fields of this Behaviour as the only reason
for why this struct exists is because libp2p forces us to compose our
NetworkBehaviours into a new struct.
2021-04-01 16:12:13 +11:00
Thomas Eizinger
b1d0ae8db7
Remove dead code
No codepath constructs this event, we can delete the associated code.
2021-04-01 16:11:57 +11:00
Daniel Karzel
2135a6e53e
Alice resumes swaps 2021-04-01 16:09:13 +11:00
Daniel Karzel
b6e4fb4f9d
Improve comment 2021-04-01 16:06:49 +11:00
Daniel Karzel
d233e9914e
Avoid problems when re-ordering / changing Bob's states
Make it explicit in which states we are able NOT to cancel/refund.
2021-04-01 16:06:48 +11:00
Daniel Karzel
e6dd194f77
next_state loop always exits in final state
Otherwise we can run into scenarios where the loop never properly exits.
2021-04-01 16:06:48 +11:00
Daniel Karzel
d90496931b
Save Alice's peer-id in the db for Bob
This allows loading the seller-peer-id from the database upon resuming a swap.
Thus, the parameters `--seller-peer-id` is removed for the `resume` command.
Other than the peer-id the multi address of a seller can change and thus is
still a parameter. This parameter might become optional once we add DHT support.
2021-04-01 16:06:48 +11:00
Daniel Karzel
bc442bcad3
Await 10 confirmations of lock tx in refund
Awaiting the confirmations in an earlier state can cause trouble with resuming
swaps with short cancel expiries (test scenarios).
Since it is the responsibility of the refund state to ensure that the XMR can
be sweeped, we now ensure that the lock transaction has 10 confirmations before
refunding the XMR using generate_from_keys.
2021-04-01 16:03:38 +11:00
Daniel Karzel
1c129d58c4
Distinguish loading all swaps for alice or bob on db level 2021-04-01 16:03:28 +11:00
Daniel Karzel
183e8f02de
Wait for lock tx and send transfer proof in separate state
Sending the transfer transaction in a distinct state helps ensuring
that we do not send the Monero lock transaction twice in a restart
scenario.
Waiting for the first transaction confirmation in a separate state
helps ensuring that we send the transfer proof in a restart scenario.
2021-04-01 16:03:19 +11:00
Daniel Karzel
dfd69c9c80
Alice aborts if any timelock expired before locking XMR
Once we resume unfinished swaps upon startup we have to ensure that
it is safe for Alice to act.
If Bob has locked BTC it is only make sense for Alice to lock up the
XMR as long as no timelock has expired. Hence we abort if the BTC is
locked, but any timelock expired already.
2021-04-01 16:02:42 +11:00
bors[bot]
6df26109aa
Merge #389
389: Bump bdk-testutils from 0.3.0 to 0.4.0 r=thomaseizinger a=dependabot[bot]

Bumps [bdk-testutils](https://github.com/bitcoindevkit/bdk) from 0.3.0 to 0.4.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/bitcoindevkit/bdk/releases">bdk-testutils's releases</a>.</em></p>
<blockquote>
<h2>v0.4.0</h2>
<p>The v0.4.0 release brings updated dependencies, more sanity checks and an overhauled API to build transactions.</p>
<p>You can find the full v0.4.0 changelog on GitHub.</p>
<p>As always, thanks to everybody who contributed to this release!</p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/bitcoindevkit/bdk/blob/master/CHANGELOG.md">bdk-testutils's changelog</a>.</em></p>
<blockquote>
<h2>[v0.5.0] - [v0.4.0]</h2>
<h3>Misc</h3>
<h4>Changed</h4>
<ul>
<li>Updated <code>electrum-client</code> to version <code>0.7</code></li>
</ul>
<h3>Wallet</h3>
<h4>Changed</h4>
<ul>
<li><code>FeeRate</code> constructors <code>from_sat_per_vb</code> and <code>default_min_relay_fee</code> are now <code>const</code> functions</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="e3f893dbd1"><code>e3f893d</code></a> Bump version to 0.4.0</li>
<li><a href="3f5513a2d6"><code>3f5513a</code></a> Update 'bdk-macros', 'bdk-testutils', 'bdk-testutils-macros' dep versions</li>
<li><a href="fcf5e971a6"><code>fcf5e97</code></a> Bump 'bdk-macros' version to 0.3.0</li>
<li><a href="cdf7b33104"><code>cdf7b33</code></a> Bump 'bdk-testutils' version to 0.3.0</li>
<li><a href="7bbff79d4b"><code>7bbff79</code></a> Bump 'bdk-testutils-macros' version to 0.3.0</li>
<li><a href="3a2b8bdb85"><code>3a2b8bd</code></a> Small CHANGELOG cleanup</li>
<li><a href="7843732e17"><code>7843732</code></a> [descriptor] Perform additional checks before using a descriptor</li>
<li><a href="6092c6e789"><code>6092c6e</code></a> Don't fix tokio minor version</li>
<li><a href="b61427c07b"><code>b61427c</code></a> [policy] Allow specifying a policy path for <code>Multisig</code></li>
<li><a href="fa2610538f"><code>fa26105</code></a> [policy] Remove the <code>TooManyItemsSelected</code> error</li>
<li>Additional commits viewable in <a href="https://github.com/bitcoindevkit/bdk/compare/v0.3.0...v0.4.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=bdk-testutils&package-manager=cargo&previous-version=0.3.0&new-version=0.4.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-03-31 01:13:05 +00:00
dependabot[bot]
8440cb9d9a
Bump monero from 0.10.0 to 0.11.1
Bumps [monero](https://github.com/monero-rs/monero-rs) from 0.10.0 to 0.11.1.
- [Release notes](https://github.com/monero-rs/monero-rs/releases)
- [Commits](https://github.com/monero-rs/monero-rs/compare/v0.10.0...v0.11.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-30 07:26:53 +00:00
dependabot[bot]
04fc870756
Bump bdk-testutils from 0.3.0 to 0.4.0
Bumps [bdk-testutils](https://github.com/bitcoindevkit/bdk) from 0.3.0 to 0.4.0.
- [Release notes](https://github.com/bitcoindevkit/bdk/releases)
- [Changelog](https://github.com/bitcoindevkit/bdk/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bitcoindevkit/bdk/compare/v0.3.0...v0.4.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-30 07:26:39 +00:00
Thomas Eizinger
52b9a78de2
Alice to validate Bob's PSBT for correctness
In order for the re-construction of TxLock to be meaningful, we limit
`Message2` to the PSBT instead of the full struct. This is a breaking
change in the network layer.

The PSBT is valid if:

- It has at most two outputs (we allow a change output)
- One of the outputs pays the agreed upon amount to a shared output script

Resolves #260.
2021-03-30 13:02:56 +11:00
Thomas Eizinger
8576894c10
Split bitcoin::Wallet functions into various impl blocks
This allows us to construct instances of bitcoin::Wallet for test
purposes that use a different blockchain and database implementation.

We also parameterize the electrum-client to make it possible to
construct a bitcoin::Wallet for tests that doesn't have one. This
is necessary because the client validates the connection as it is
constructed and we don't want to provide an Electrum backend for
unit tests.
2021-03-30 13:02:55 +11:00
Thomas Eizinger
b9d8cbeaa2
Rename testutils to harness
This allows us to bring in a dependency named `testutils`.
2021-03-30 12:59:34 +11:00
Thomas Eizinger
11b45cd8c0
Move messages into protocol module
This allows us to remove all visibility modifiers from the message
fields because child modules (in this case {alice,bob}::state) can
always access private fields of structs.

It also moves the messages into a more natural place. Previously,
they were defined within the network layer even though they are
independent of the libp2p implementation.
2021-03-30 12:59:34 +11:00
Thomas Eizinger
e130448200
Make as many fields of Alice's states private as possible
To achieve this, we need to add some pure helpers to the state structs.
This has the added benefit that we can reduce the amount of code within
the swap function.
2021-03-30 12:59:34 +11:00
Thomas Eizinger
7f5715e147
Remove unnecessary serde implementations 2021-03-30 12:59:33 +11:00
Thomas Eizinger
c539465925
Make it possible to create random public keys
This is useful for tests.
2021-03-30 12:59:30 +11:00
rishflab
86f312e143 Safely abort swap if TxLock is not confirmed in a reasonable time
If TxLock does not confirm in a reasonable amount of time, Alice should
give up on the swap rather than waiting forever. Watching for TxLock in
the mempool is not required and it causes unnecessary complexity. What
if Alice does not see the transaction in mempool but it is already
confirmed? She will abort the swap for no reason.
2021-03-30 11:13:09 +11:00
Thomas Eizinger
01739eddb1
Introduce a more flexible transaction subscription system
Instead of watching for status changes directly on bitcoin::Wallet,
we return a Subscription object back to the caller. This subscription
object can be re-used multiple times.

Among other things, this now allows callers of `broadcast` to decide
on what to wait for given the returned Subscription object.

The new API is also more concise which allows us to remove some of
the functions on the actor states in favor of simple inline calls.

Co-authored-by: rishflab <rishflab@hotmail.com>
2021-03-30 10:29:19 +11:00
bors[bot]
6fb495b6ab
Merge #383 #385 #386
383: Improve resilience of balance assertions r=thomaseizinger a=thomaseizinger

The final commit is the relevant patch!

It sits on top of several refactoring commits that happened while I was debugging why things didn't work as expected. Turned out to be reasonably useful so I just left them in :)

385: Bump anyhow from 1.0.39 to 1.0.40 r=thomaseizinger a=dependabot[bot]

Bumps [anyhow](https://github.com/dtolnay/anyhow) from 1.0.39 to 1.0.40.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/dtolnay/anyhow/releases">anyhow's releases</a>.</em></p>
<blockquote>
<h2>1.0.40</h2>
<ul>
<li>Reduce memory footprint of errors on Rust versions 1.51+ (<a href="https://github-redirect.dependabot.com/dtolnay/anyhow/issues/145">#145</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="704622f25d"><code>704622f</code></a> Release 1.0.40</li>
<li><a href="64ac0c00a9"><code>64ac0c0</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/dtolnay/anyhow/issues/145">#145</a> from dtolnay/addrof</li>
<li><a href="ef082670ea"><code>ef08267</code></a> Eliminate functionally duplicate vtable methods on rustc 1.51+</li>
<li><a href="1295b1fef9"><code>1295b1f</code></a> Add additional builds on 1.50 and 1.51 validating addr_of codepath</li>
<li><a href="be89adf403"><code>be89adf</code></a> Detect whether ptr::addr_of is supported by current compiler</li>
<li><a href="ac64560c42"><code>ac64560</code></a> Switch object_ref return from real ref to Ref ptr</li>
<li><a href="2987c9b59e"><code>2987c9b</code></a> Ignore redundant_else pedantic clippy lint</li>
<li><a href="827bb9d4c6"><code>827bb9d</code></a> Catch some warnings in addr_of-related codepaths</li>
<li><a href="ce0041866d"><code>ce00418</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/dtolnay/anyhow/issues/144">#144</a> from dtolnay/ptr</li>
<li><a href="3c32aa7dcd"><code>3c32aa7</code></a> Relax Sized bound on Own, Ref, Mut ptrs</li>
<li>Additional commits viewable in <a href="https://github.com/dtolnay/anyhow/compare/1.0.39...1.0.40">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=anyhow&package-manager=cargo&previous-version=1.0.39&new-version=1.0.40)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

386: Bump hyper from 0.14.4 to 0.14.5 r=thomaseizinger a=dependabot[bot]

Bumps [hyper](https://github.com/hyperium/hyper) from 0.14.4 to 0.14.5.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/hyperium/hyper/releases">hyper's releases</a>.</em></p>
<blockquote>
<h2>v0.14.5</h2>
<h2>Bug Fixes</h2>
<ul>
<li><strong>client:</strong> omit default port from automatic Host headers (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2441">#2441</a>) (<a href="0b11eee9bd">0b11eee9</a>)</li>
<li><strong>headers:</strong> Support multiple Content-Length values on same line (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2471">#2471</a>) (<a href="48fdaf1606">48fdaf16</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2470">#2470</a>)</li>
<li><strong>server:</strong> skip automatic Content-Length headers when not allowed (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2216">#2216</a>) (<a href="8cbf9527df">8cbf9527</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2215">#2215</a>)</li>
</ul>
<h2>Features</h2>
<ul>
<li><strong>client:</strong> allow HTTP/0.9 responses behind a flag (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2473">#2473</a>) (<a href="68d4e4a3db">68d4e4a3</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2468">#2468</a>)</li>
<li><strong>server:</strong> add <code>AddrIncoming::from_listener</code> constructor (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2439">#2439</a>) (<a href="4c946af49c">4c946af4</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/hyperium/hyper/blob/master/CHANGELOG.md">hyper's changelog</a>.</em></p>
<blockquote>
<h3>v0.14.5 (2021-03-26)</h3>
<h4>Bug Fixes</h4>
<ul>
<li><strong>client:</strong> omit default port from automatic Host headers (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2441">#2441</a>) (<a href="0b11eee9bd">0b11eee9</a>)</li>
<li><strong>headers:</strong> Support multiple Content-Length values on same line (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2471">#2471</a>) (<a href="48fdaf1606">48fdaf16</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2470">#2470</a>)</li>
<li><strong>server:</strong> skip automatic Content-Length headers when not allowed (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2216">#2216</a>) (<a href="8cbf9527df">8cbf9527</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2215">#2215</a>)</li>
</ul>
<h4>Features</h4>
<ul>
<li><strong>client:</strong> allow HTTP/0.9 responses behind a flag (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2473">#2473</a>) (<a href="68d4e4a3db">68d4e4a3</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2468">#2468</a>)</li>
<li><strong>server:</strong> add <code>AddrIncoming::from_listener</code> constructor (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2439">#2439</a>) (<a href="4c946af49c">4c946af4</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="98e7e0bd15"><code>98e7e0b</code></a> v0.14.5</li>
<li><a href="895e4cf3fb"><code>895e4cf</code></a> refactor(ffi): return null ptr instead of aborting in C API (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2478">#2478</a>)</li>
<li><a href="68d4e4a3db"><code>68d4e4a</code></a> feat(client): allow HTTP/0.9 responses behind a flag (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2473">#2473</a>)</li>
<li><a href="51ed71b0a6"><code>51ed71b</code></a> docs(client): use Method::POST to match the example in <a href="https://hyper.rs/guide">https://hyper.rs/guide</a>...</li>
<li><a href="41f99578a5"><code>41f9957</code></a> refactor(dependencies): update to socket2 v0.4.0 (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2472">#2472</a>)</li>
<li><a href="48fdaf1606"><code>48fdaf1</code></a> fix(headers): Support multiple Content-Length values on same line (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2471">#2471</a>)</li>
<li><a href="eb0e718696"><code>eb0e718</code></a> docs(body): add links to to_bytes and aggregate (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2464">#2464</a>)</li>
<li><a href="297a068454"><code>297a068</code></a> docs(examples): upgrade tokio version (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2456">#2456</a>)</li>
<li><a href="34085afef6"><code>34085af</code></a> docs(examples): use hyper v0.14 and full feature (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2451">#2451</a>)</li>
<li><a href="8cbf9527df"><code>8cbf952</code></a> fix(server): skip automatic Content-Length headers when not allowed (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2216">#2216</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/hyperium/hyper/compare/v0.14.4...v0.14.5">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=hyper&package-manager=cargo&previous-version=0.14.4&new-version=0.14.5)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-03-29 22:31:43 +00:00
bors[bot]
a18c071559
Merge #384
384: Include author information in the `--help` text r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-29 22:20:48 +00:00
Thomas Eizinger
0a82ce989b
Improve resilience of balance assertions
Sometimes, a single sync is not enough because we are still waiting
for the block to be mined.

We introduce an abstraction that loops on fetching the latest balance
with a certain timeout for asserting the balance.
2021-03-29 12:15:52 +11:00
Thomas Eizinger
a4c70dfe94
Don't call as_ref() unless necessary 2021-03-29 12:15:52 +11:00
Thomas Eizinger
4ab7e83806
Make use of cargo tests scoped test output
By using `test_writer`, cargo can automatically scope the output
of the test to the relevant thread and will also only output it
if the test fails or is run with `--nocapture`.
2021-03-29 12:15:51 +11:00
Thomas Eizinger
908dae3442
Inline tracing initialization
This code snippet is so short, it might as well be inlined to give
the test more control over what it wants to log.
2021-03-29 12:15:51 +11:00
Thomas Eizinger
c01cccb288
Use tracing-log feature flag instead of manual initialization
This also formats `log` events more nicely. Instead of

```
Mar 29 09:46:16.775  INFO log: Found message after comparing 82 lines log.target="testcontainers::core::wait_for_message" log.module_path="testcontainers::core::wait_for_message" log.file="/home/thomas/.cargo/registry/src/github.com-1ecc6299db9ec823/testcontainers-0.12.0/src/core/wait_for_message.rs" log.line=35
```

We now have

```
Mar 29 09:57:15.860  INFO testcontainers::core::wait_for_message: Found message after comparing 81 lines
```
2021-03-29 12:15:50 +11:00
Thomas Eizinger
c5827f84ca
Refactor recursive function to loop
This should get rid of the ever-growing stack size issue.
2021-03-29 12:15:48 +11:00
Thomas Eizinger
fc175a3f53
De-couple state from Monero wallet 2021-03-29 12:15:12 +11:00
Thomas Eizinger
42b6368298
Use full-qualified path for tracing macros
Saves an import line and makes it clear that we are using tracing.
2021-03-29 12:14:19 +11:00
Thomas Eizinger
5616683d7d
Monero confirmations are a u64
Trying to deserialize the number as a u32 caused deserialization
errors.
2021-03-29 12:14:19 +11:00
Thomas Eizinger
1b63d5486d
Move tick to the beginning of the loop
This ensures that we always wait for the provided interval, even in
the case of a `continue` which happens if there is an error within
the RPC call.
2021-03-29 12:14:19 +11:00
Thomas Eizinger
393ed45b9e
Say who we are in the --help message
The message now says:

swap 0.3.0
The COMIT guys <hello@comit.network>
CLI for swapping BTC for XMR

USAGE:
    swap [FLAGS] [OPTIONS] <SUBCOMMAND>

...
2021-03-26 14:31:14 +11:00
Thomas Eizinger
39b27e37d8
Delete empty file 2021-03-26 14:31:04 +11:00
rishflab
a3e85526c6 Specify LANG env variable for monero wallet rpc for unix systems
By specifying the language we can look for a specific string to check if
 monero wallet rpc is ready
2021-03-25 19:52:43 +11:00
rishflab
bc902ea63a Use language agnostic heuristic to check if monero_wallet_rpc is ready
Our strategy of searching for a english string to determine if
monero_wallet_rpc is ready is not compatible with languages other than
english. Instead we assume the monero rpc is ready if it has stopped
writing to stdout. We make a json rpc request to confirm this. A better
solution would have been to configure the monero_wallet_rpc to always
output in english but there is not command line argument to configure
the language.

Closes #353.
2021-03-25 18:13:06 +11:00
bors[bot]
7397cb5990
Merge #359
359: Bump bdk from 0.4.0 to 0.5.0 r=thomaseizinger a=dependabot[bot]

Bumps [bdk](https://github.com/bitcoindevkit/bdk) from 0.4.0 to 0.5.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/bitcoindevkit/bdk/blob/master/CHANGELOG.md">bdk's changelog</a>.</em></p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="f7944e871b"><code>f7944e8</code></a> Bump version to 0.5.0</li>
<li><a href="2fea1761c1"><code>2fea176</code></a> Bump deps version</li>
<li><a href="fa27ae210f"><code>fa27ae2</code></a> Update version in lib.rs</li>
<li><a href="46fa41470e"><code>46fa414</code></a> Update CHANGELOG with the new release tag</li>
<li><a href="8ebe7f0ea5"><code>8ebe7f0</code></a> Merge commit 'refs/pull/308/head' of github.com:bitcoindevkit/bdk into releas...</li>
<li><a href="eb85390846"><code>eb85390</code></a> Merge commit 'refs/pull/309/head' of github.com:bitcoindevkit/bdk into releas...</li>
<li><a href="dc83db273a"><code>dc83db2</code></a> better derivation path building</li>
<li><a href="201bd6ee02"><code>201bd6e</code></a> better derivation path building</li>
<li><a href="396ffb42f9"><code>396ffb4</code></a> handle descriptor xkey origin</li>
<li><a href="9cf62ce874"><code>9cf62ce</code></a> [ci] Manually install libclang-common-10-dev to 'check-wasm' job</li>
<li>Additional commits viewable in <a href="https://github.com/bitcoindevkit/bdk/compare/v0.4.0...v0.5.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=bdk&package-manager=cargo&previous-version=0.4.0&new-version=0.5.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-24 06:12:52 +00:00
bors[bot]
9c9b1e4f0c
Merge #370
370: No Bitcoin deposit for Alice r=da-kami a=da-kami

The message to deposit Bitcoin only applies to Bob, not Alice.
Alice does not require any initial Bitcoin.

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-03-24 05:03:19 +00:00
Thomas Eizinger
1057d115d1
Re-order bob::event_loop based on importance 2021-03-24 15:17:54 +11:00
Thomas Eizinger
638a169a04
Buffer transfer proof if we are not connected to Bob
The request-response behaviour that is used for sending the transfer
proof actually has a functionality for buffering a message if we
are currently not connected. However, the request-response behaviour
also emits a dial attempt and **drops** all buffered messages if this
dial attempt fails. For us, the dial attempt will very likely always
fail because Bob is very likely behind NAT and we have to wait for
him to reconnect to us.

To mitigate this, we build our own buffer within the EventLoop and
send transfer proofs as soon as we are connected again.

Resolves #348.
2021-03-24 15:17:54 +11:00
Thomas Eizinger
cde3f0f74a
Remove connection handling from swap execution
The swap should not be concerned with connection handling. This is
the responsibility of the overall application.

All but the execution-setup NetworkBehaviour are `request-response`
behaviours. These have built-in functionality to automatically emit
a dial attempt in case we are not connected at the time we want to
send a message. We remove all of the manual dialling code from the
swap in favor of this behaviour.

Additionally, we make sure to establish a connection as soon as the
EventLoop gets started. In case we ever loose the connection to Alice,
we try to re-establish it.
2021-03-24 15:17:54 +11:00
Daniel Karzel
1e2a3c2d32 No Bitcoin deposit for Alice
The message to deposit Bitcoin only applies to Bob, not Alice.
Alice does not require any initial Bitcoin.
2021-03-24 11:51:25 +11:00
Thomas Eizinger
804b34f6b0
Listen on all swarm events instead of just behaviour events 2021-03-24 11:39:41 +11:00
Thomas Eizinger
2200fce3f3
Pass Swarm into EventLoop
This reduces the amount of arguments we need to pass into the eventloop
at the expense of slightly more setup of the swarm.
2021-03-24 11:39:41 +11:00
Thomas Eizinger
2c9ab4f6eb
Improve code structure and error messages for running swaps
The quote message was repeated and we should set the overall
failure into a context to know what went wrong.
2021-03-24 11:39:41 +11:00
Thomas Eizinger
0c0a322a8f
Rename module to better represent what it contains
This module provides an implementation of the RequestResponseCodec
using a cbor serialization.
2021-03-24 11:39:40 +11:00
Thomas Eizinger
1de0b39b32
Unify encrypted-signature protocol to a single one 2021-03-24 11:39:40 +11:00
Thomas Eizinger
9979cc9f1f
Unify transfer-proof protocol to a single one
Previously, we had two implementations of this protocol. To reduce
code size, we make Alice and Bob use the same implementation.
2021-03-24 11:39:40 +11:00
Thomas Eizinger
9d0b9abde0
Introduce helper function for mapping RequestResponseEvent
Decomposing a RequestResponseEvent is quite verbose. We can introduce
a helper function that does the matching for us and delegates to
specific `From` implementations for the protocol specific bits.
2021-03-24 11:39:39 +11:00
Thomas Eizinger
73f30320a6
Seed should neither be Clone nor Copy
It is better to not copy around secret data within our process to
make heartbleed-like attacks harder.
2021-03-24 11:39:39 +11:00
Thomas Eizinger
96b2a76971
Take advantage of upgraded electrum-client dependency
The new version implements std::error::Error and fixes a bug that
allows us to use the default config again.
2021-03-23 14:57:27 +11:00
dependabot[bot]
7f6299075c
Bump bdk from 0.4.0 to 0.5.0
Bumps [bdk](https://github.com/bitcoindevkit/bdk) from 0.4.0 to 0.5.0.
- [Release notes](https://github.com/bitcoindevkit/bdk/releases)
- [Changelog](https://github.com/bitcoindevkit/bdk/blob/master/CHANGELOG.md)
- [Commits](https://github.com/bitcoindevkit/bdk/compare/v0.4.0...v0.5.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-23 03:54:18 +00:00
bors[bot]
968502827a
Merge #339
339: Bump dependency versions r=thomaseizinger a=thomaseizinger

Otherwise it will take a long time for dependabot to update all of
these.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-23 00:09:49 +00:00
bors[bot]
097197783c
Merge #351
351: Show the actual BTC amount and fee to be swapped r=da-kami a=da-kami

We got user feedback, that it is confusing that the amount "found" in the wallet does not match the amount actually being swapped, thus with this PR we explicitly display the amount swapped and fees.

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-03-22 23:42:31 +00:00
bors[bot]
189a13c063
Merge #319
319: Alice sweeps refunded funds into default wallet r=da-kami a=da-kami

Alice's refund scenario starts with generating the temporary wallet
from keys to claim the XMR which results in Alice' unloading the wallet.
Alice then loads her original wallet to be able to handle more swaps.
Since Alice is in the role of the long running daemon handling concurrent
swaps, the operation to close, claim and re-open her default wallet must
be atomic.
This PR adds an additional step, that sweeps all the refunded XMR back into
the default wallet. In order to ensure that this is possible, Alice has to
ensure that the locked XMR got enough confirmations.
These changes allow us to assert Alice's balance after refunding.

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-03-22 05:12:49 +00:00
Daniel Karzel
62079fc342 Punish scenario falls back to refund or fails
If we enter a punish scenario we can be sure the punish timelock is expired.
Thus, we must be able to punish unless Bob published the refund transaction.
There is no benefit in racing punish against refund here, because we cannot recover from a punish tx failure anyway.

The logic was changed to:
Try to broadcast punish tx and await finality.
  If either punish broadcasting of finality fails, try to fetch the refund transaction.
    If it is available extract Bob's Monero key part and transition to refund.
    If refund tx is not available fail without a status update.

Note that we do not distinguish different errors upon failure of punish, because
we cannot recover anyway. If we fail to retrieve Bob's refund tx, we just exit without
a status update so punish can be retried by resuming the swap.
2021-03-22 16:10:01 +11:00
Thomas Eizinger
a228349d8b
Bump dependency versions
Otherwise it will take a long time for dependabot to update all of
these.
2021-03-22 14:48:39 +11:00
Daniel Karzel
668d34080d Show the actual BTC amount and fee to be swapped 2021-03-19 17:40:14 +11:00
Thomas Eizinger
f49f8977d3
Remove dead code 2021-03-18 18:09:30 +11:00
Daniel Karzel
396c4177a6 Alice sweeps refunded funds into default wallet
Since Alice's refund scenario starts with generating the temporary wallet
from keys to claim the XMR which results in Alice' unloading the wallet.
Alice then loads her original wallet to be able to handle more swaps.
Since Alice is in the role of the long running daemon handling concurrent
swaps, the operation to close, claim and re-open her default wallet must
be atomic.
This PR adds an additional step, that sweeps all the refunded XMR back into
the default wallet. In order to ensure that this is possible, Alice has to
ensure that the locked XMR got enough confirmations.
These changes allow us to assert Alice's balance after refunding.
2021-03-18 17:59:48 +11:00
Thomas Eizinger
16dfea035b
Simplify code within BobState::XmrLockProofReceived
To achieve this, we decompose `watch_for_locked_xmr` into two parts:

1. A non-self-consuming function to construct a `WatchRequest`
2. A state transition that can now consume `self` again because
it is only called once within the whole select! expression.

Ideally, we would move more logic onto this state transition (like
comparing the actual amounts and fail the transition if it is not
valid). Doing so would have an unfortunate side-effect: We would
always wait for the full confirmations before checking whether or
not we actually receive enough XMR.

This allows us to have state transitions that consume self.
2021-03-18 15:45:58 +11:00
Thomas Eizinger
338f4b82e5
Introduce dedicated bob::State6 for cancelling 2021-03-18 15:45:57 +11:00
Thomas Eizinger
c32ef92cf5
Simplify code within BobState::EncSigSent 2021-03-18 15:45:57 +11:00
Thomas Eizinger
09e2d5b5d7
Simplify code within BobState::XmrLocked
By reducing the number of local variables, we can greatly simplify
this piece of code.
2021-03-18 15:45:57 +11:00
Thomas Eizinger
776a50137d
Use tokio::select macro instead of function
This is slightly less verbose and therefore hopefully easier to read.
2021-03-18 15:45:56 +11:00
Thomas Eizinger
b1affe3ecf
Insert latest state and call run_until only once
Instead of calling this function in all the branches, we can simply
make the whole match statement evaluate to the new state and perform
this functionality at the very end.
2021-03-18 15:45:56 +11:00
Thomas Eizinger
0d8962762a
Use early return to reduce one level of indentation 2021-03-18 15:45:55 +11:00
Thomas Eizinger
05849505b1
Inline wait_for_bitcoin_refund
This function is essentially a single select! statement and can
easily be inlined into the swap state machine.
2021-03-18 15:45:39 +11:00
Thomas Eizinger
8c9285f1f9
Inline step function because it has been reduced to a single statement 2021-03-18 15:45:36 +11:00
Thomas Eizinger
afb7e816a1
Don't wait for confirmations again
We only call this function within `CancelTimelockExpired`. There is
no need to check the confirmations again.
2021-03-18 15:44:37 +11:00
Thomas Eizinger
c92f2dbc77
Move more domain knowledge onto the TxCancel type 2021-03-18 15:44:37 +11:00
Thomas Eizinger
75aec95b0c
Introduce monero::TransferRequest
This allows us to move critical crypto logic onto `State3` which
holds all the necessary data which consequently allows us to get
rid of `lock_xmr` altogether by inlining it into the swap function.
The reduced indirection improves readability.
2021-03-18 15:44:36 +11:00
Thomas Eizinger
d682433ec9
Move EventLoopHandle next to its impl block
This struct is not that important so it can move further down.
2021-03-18 15:44:36 +11:00
Thomas Eizinger
e77f1729b4
Move extract_monero_private_key onto TxRefund
This functionality is domain-specific to the refund transaction.
Move it onto there.
2021-03-18 15:44:36 +11:00
Thomas Eizinger
a1e065b4e7
Simplify racing cancel timelock against learning enc-sig 2021-03-18 15:44:36 +11:00