Commit Graph

105 Commits

Author SHA1 Message Date
rishflab
a738c9df8a Remove multiple occurrences of db initialisation 2021-09-30 18:59:40 +10:00
rishflab
da9d09aa5e Create Database trait
Use domain types in database API to prevent leaking of database types.
This trait will allow us to smoothly introduce the sqlite database.
2021-09-30 18:56:52 +10:00
rishflab
a94c320021 Reorganise modules for multiple database implementations 2021-09-30 18:54:23 +10:00
bors[bot]
1a2b42ccd1
Merge #721
721: Make --force the default behaviour for manual recovery r=rishflab a=rishflab

Also removed the --force flag

Co-authored-by: rishflab <rishflab@hotmail.com>
2021-09-09 10:46:29 +00:00
rishflab
f511ff093c Make --force the default behaviour for manual recovery
Remove the force flag. There is a resume command that tries to
gracefully restarts the protocol and tries to execute the happy path.
Remove e2e tests which test the --force flag.
2021-09-09 18:08:18 +10:00
rishflab
0afe83e4e8 Move "swap started" UI message after swap confirmed with ASB
The "swap started" message was being too early, before the ASB had
confirmed they could perform the swap. This was leading to a confusing
scenario where the UI incorrectly indicated to the user that the swap
had started. Users were trying to resume or refund the swaps but there
was no swap id in the db. Moving this message after the swap setup
should resolve this problem. Closes #756, #729, #560.
2021-09-09 16:58:17 +10:00
devbordecraft
e8a6af1517 Allow withdrawing and viewing of the bitcoin balance on swap-cli
Fix formatting issue

Fix after review
2021-08-31 20:42:28 +02:00
bors[bot]
238e52228e
Merge #618
618: Don't spam on transaction status change r=da-kami a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-07-08 05:49:39 +00:00
bors[bot]
b7a832eb7a
Merge #616
616: Don't spam the user while waiting for BTC to be deposited r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-07-08 04:48:55 +00:00
Thomas Eizinger
2c8bbe4913
Remove left-over "half" of log message
With the move to using tracing's fields, this log message was not
properly updated.
2021-07-08 13:40:11 +10:00
Thomas Eizinger
2eb7fab0c3
Make capture_logs available for the whole crate 2021-07-08 12:55:33 +10:00
Daniel Karzel
6abf83f4ad
Sort seller list inside of list_sellers
By sorting the list inside we have a more deterministic output that makes processing in JSON easier.
2021-07-08 12:42:26 +10:00
Thomas Eizinger
cacfc50fb2
Don't spam the user while waiting for BTC 2021-07-08 12:14:37 +10:00
Thomas Eizinger
56a48e71ef
Add failing test that shows spamming of output 2021-07-08 12:12:55 +10:00
Thomas Eizinger
56ea23c2a3
Assert log output for determine_btc_to_swap 2021-07-08 12:10:49 +10:00
Thomas Eizinger
a347dd8b97
Move helper structs below tests 2021-07-08 11:15:24 +10:00
Thomas Eizinger
5c37fe6733
Make struct-opt docs more consistent
- Remove dots from the of help messages
- Unify wording
2021-07-07 17:14:56 +10:00
Thomas Eizinger
987f8abb9d
Include unreachable nodes in table output
We emit an `info!` log for every peer that we discover but only ever
emitted a `debug!` log if we fail to connect. This leads to a situation
where the user would run `swap list-sellers`, the logs would say
"Discovered XYZ at ABC" but then get a potentially empty table.

To not confuse the user, we include unreachable nodes in the table output.
For example:

```
Connected to rendezvous point, discovering nodes in 'xmr-btc-swap-testnet' namespace ...
Discovered peer 12D3KooWPZ69DRp4wbGB3wJsxxsg1XW1EVZ2evtVwcARCF3a1nrx at /dns4/ac4hgzmsmekwekjbdl77brufqqbylddugzze4tel6qsnlympgmr46iid.onion/tcp/8765
+-------+--------------+--------------+-------------+----------------------------------------------------------------------------------------------------------------------------------------+
| PRICE | MIN_QUANTITY | MAX_QUANTITY | STATUS      | ADDRESS                                                                                                                                |
+============================================================================================================================================================================================+
| ???   | ???          | ???          | Unreachable | /dns4/ac4hgzmsmekwekjbdl77brufqqbylddugzze4tel6qsnlympgmr46iid.onion/tcp/8765/p2p/12D3KooWPZ69DRp4wbGB3wJsxxsg1XW1EVZ2evtVwcARCF3a1nrx |
+-------+--------------+--------------+-------------+----------------------------------------------------------------------------------------------------------------------------------------+
```
2021-07-07 17:14:56 +10:00
Thomas Eizinger
9119ce5cc4
Tidy up log messages across the codebase
1. Clearly separate the log messages from any fields that are
captured. The log message itself should be meaningful because it
depends on the underlying formatter, how/if the fields are displayed.
2. Some log messages had very little context, expand that.
3. Wording of errors was inconsistent, hopefully all errors should
now start with `Failed to ...`.
4. Some log messages were duplicated across multiple layers (like opening
the database).
5. Some log messages were split into two where one part is now an `error!`
and the 2nd part is an `info!` on what is happening next.
6. Where appropriate, punctuation has been removed to not interrupt
the reader's flow.
2021-07-07 16:02:00 +10:00
Thomas Eizinger
78480547d5
Don't import tracing's macros
Log statements end up getting changed constantly and having to clean
up imports after that is annoying, for example, if the last `info!`
in a file disappears, you end up with an unused import warning.

Fully qualifying tracing's macros prevents that and also communicates
clearly that we are using tracing and not log.
2021-07-07 16:01:33 +10:00
Thomas Eizinger
acfd2dd6bb
Store Monero receive address in database and load it on resume 2021-07-06 20:08:24 +10:00
Thomas Eizinger
5463bde4f8
Add a mandatory --change-address parameter to buy-xmr
Fixes #513.
2021-07-06 20:07:53 +10:00
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
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
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
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
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
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
90deb6451c
Rename swarm constructors to be per tool instead of per role 2021-06-21 09:00:10 +10:00
xscd
03857ca835 Print the Bitcoin address to the terminal as a QR code 2021-06-16 15:18:16 +03:00
Thomas Eizinger
229d840990
Introduce dedicated ParseResult to simplify error handling in main 2021-05-28 15:22:55 +10: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
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
Daniel Karzel
af60d3bb54
Network check upon spot price request 2021-05-20 13:03:29 +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
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
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
c011e95062
Improve logging by adding details as fields instead of into the msg. 2021-05-11 15:27:53 +10: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
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
Philipp Hoenisch
46e0449b8e
Add config/argument to swap/asb to configure bitcoin tx fees. 2021-05-07 10:24:41 +10:00