Commit Graph

580 Commits

Author SHA1 Message Date
bors[bot]
d1363d130c
Merge #265
265: Replace quote with spot-price protocol r=thomaseizinger a=thomaseizinger

This is essentially functionally equivalent but includes some
cleanups by removing a layer of abstraction: `spot_price::Behaviour`
is now just a type-alias for a request-response behaviour.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-04 02:52:06 +00:00
Daniel Karzel
7504c6ceee Context for monero address parsing errors
Most of the errors are not user friendly, thus added context to tell the user the given address is incorrect.
2021-03-04 13:36:10 +11:00
Daniel Karzel
35d0e246d8 Monero address network check
Add a network check to ensure the given monero address is on the configured network.
2021-03-04 10:46:12 +11:00
bors[bot]
cba9f119b6
Merge #261
261: Sweep xmr funds from generated temp wallet r=da-kami a=da-kami

Fixes #252

Please review by commit :)
Did a few cleanups before actually doing the feature.

Please note the comment that influenced this solution: https://github.com/comit-network/xmr-btc-swap/issues/252#issuecomment-789387074



Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-03-03 06:29:37 +00:00
Daniel Karzel
2e3c2d8edf Remove Arcs in favour of references 2021-03-03 17:23:07 +11:00
Daniel Karzel
5d807e9647 Reorder: Move utility functionality to bottom 2021-03-03 17:15:37 +11:00
Daniel Karzel
862c29f1a8 Reorder: Move sweep_all after transfer 2021-03-03 17:15:37 +11:00
Daniel Karzel
5a43b3453e Reorder: Move create after open 2021-03-03 17:15:37 +11:00
Daniel Karzel
b17e6cbd94 Reorder: Move open to top 2021-03-03 17:15:37 +11:00
Daniel Karzel
d63790c2a6 Remove unnecessary monero wallet trait abstractions 2021-03-03 17:15:37 +11:00
Daniel Karzel
1041212a60 Work in review comments 2021-03-03 17:15:37 +11:00
Daniel Karzel
66c8401c95 Sweep all from generated wallet to user wallet
The default implementation for the command was removed because it does not
add additional value if we have a mandatory parameter anyway.
2021-03-03 17:15:37 +11:00
Thomas Eizinger
7042ed9441
Replace quote with spot-price protocol
This is essentially functionally equivalent but includes some
cleanups by removing a layer of abstraction: `spot_price::Behaviour`
is now just a type-alias for a request-response behaviour.
2021-03-03 17:09:38 +11:00
Daniel Karzel
5111a12706 Wallet name constants for the e2e test setup
Container initialization and wallet initialization have to ensure to use the same wallet name.
In order to avoid problems constants are introduced to ensure we use the same wallet name.
2021-03-03 17:03:34 +11:00
Daniel Karzel
2bb1c1e177 No prefix for wallets in monero harness
Prefixing docker-containers and -networks is a necessity to be able to spin up multiple containers and networks.
However, there is no reason to prefix the wallet names that live inside a container. One cannot add a wallet with
the same name twice, so the prefixing of wallets does not bring any advantage. When re-opening a wallet by name
the wallet name prefix is cumbersome and was thus removed.
2021-03-03 17:03:34 +11:00
Daniel Karzel
9f53dab3c6 Harmonize names to make more sense
The wallet is an instance of a wallet that has a name.
When we use `CreateWalletForOutputThenReloadWallet` we actually unload the wallet.
It would be cleaner to create a new instance that does that swap, but I did not go that far.
2021-03-03 17:03:34 +11:00
Daniel Karzel
70494fcb4f Create means creating the current wallet 2021-03-03 17:03:34 +11:00
Daniel Karzel
5b798217bc Open means opening the current wallet 2021-03-03 17:03:33 +11:00
Thomas Eizinger
2440964385
Allow ASB to be configured with max BTC buy amount
This will make it easier to also configure the CLI to display an appropriate max amount the user has to deal with.
2021-03-03 16:56:34 +11:00
Thomas Eizinger
ce077a3ff5
Decouple Bob's EventLoop from the builder
Instead of instantiating the `EventLoop` within the builder, we only
pass in the necessary arguments (which is the `EventLoopHandle`) to
the Builder upon `new`.

This is work towards #255 which will require us to perform network
communication (which implies having the `EventLoop`) before starting
a swap.
2021-03-03 14:53:05 +11:00
Thomas Eizinger
54bc91581f
Don't unnecessarily create async blocks
If our expression directly evaluates to a future, we don't need to
create an async block.

This requires us to have `EventLoopRun::run` consume the instance
instead of just taking a mutable reference (otherwise we run into
lifetime issues). However, that is better anyway because `run` is
an endless loop so you never get to use the handle afterwards
anyway.
2021-03-03 14:53:05 +11:00
Thomas Eizinger
a4c25080b6
Merge network::Seed into crate::Seed
This allows us to unify the way we derive new secret key material
and simplify the usage of seed by only having a single one.
2021-03-03 14:53:01 +11:00
Thomas Eizinger
089ac0806e
Simplify constructor of Bob's EventLoop
We never customize the behaviour or transport. Might as well hide
those details in the implementation.
2021-03-03 14:08:56 +11:00
Daniel Karzel
1b167f3eb6 Cleanup swap initialization for Alice and Bob 2021-03-03 14:07:00 +11:00
bors[bot]
a8ebd4d16e
Merge #259
259: Upgrade bitcoin wallet to use BIP84 derivation scheme r=rishflab a=rishflab

Closes #258 

Co-authored-by: rishflab <rishflab@hotmail.com>
2021-03-03 01:53:16 +00:00
rishflab
a41b255dab Upgrade bitcoin wallet to use BIP84 derivation scheme
Explicitly specify the change descriptor because the behaviour when it
is not specified is unclear.
2021-03-03 12:12:10 +11:00
rishflab
bcdde021eb Add windows support to monero rpc installer 2021-03-02 15:09:12 +11:00
rishflab
27df9128be Bail if monero wallet rpc is not found in downloaded archive
Previously we were ignoring if the monero wallet rpc was not found and
unpacked from archive leading to a failure down the line when trying to
run a non-existent executable. Bail when the executable is no found in
the archive.
2021-03-02 15:09:12 +11:00
Thomas Eizinger
3ad9516188
Reduce logging when signing transactions
1. We can generalize the signing interface by passing a PSBT in
instead of the `TxLock` transaction.
2. Knowing the transaction ID of a transaction that we are about
to sign is not very useful. Instead, it is much more useful to know
what failed. Hence we add a `.context` to the call of `sign_and_finalize`.
3. In case the signing succeeds, we will immediately broadcast it
afterwards. The new broadcasting interface will tell us that we broadcasted
the "lock" transaction.
2021-03-02 12:53:40 +11:00
Thomas Eizinger
8c9b087e39
Unify logging of broadcasted transactions
We eliminate unnecessary layers of indirection for broadcasting logic
and force our callers to provide us with the `kind` of transaction
that we are publishing.

Eventually, we can replace this string with some type-system magic
we can derive the name from the actual transaction. For now, we just
require the caller to duplicate this information because it is faster
and good enough TM.
2021-03-02 12:51:22 +11:00
Thomas Eizinger
3a503bf95f
Shorten function name
This struct is a wallet. The only thing it can meaningfully broadcast
are transactions. The fact that they have to be signed for that is
implied. You cannot broadcast unsigned transactions.
2021-03-02 12:25:47 +11:00
Thomas Eizinger
45cff81ea5
Remove traits in favor of using the wallet struct directly
Abstracting over the individual bits of functionality of the wallet
does have its place, especially if one wants to keep a separation
of an abstract protocol library that other people can use with their
own wallets.

However, at the moment, the traits only cause unnecessary friction.
We can always add such abstraction layers again once we need them.
2021-03-02 12:22:23 +11:00
Thomas Eizinger
8c0df23647
Only show _log_ output if the user passes --debug
If the user doesn't pass `--debug`, we only show `INFO` logs but
without time and level to make it clearer that it is meant to be
read by the user.

Without `--debug`, the user sees:

 Still got 0.00009235 BTC left in wallet, swapping ...

With `--debug`, they see:

2021-03-01 12:21:07  DEBUG Database and seed will be stored in /home/thomas/.local/share/xmr-btc-swap
2021-03-01 12:21:07  DEBUG Starting monero-wallet-rpc on port 40779
2021-03-01 12:21:11   INFO Still got 0.00009235 BTC left in wallet, swapping ...
2021-03-01 12:21:11  DEBUG Dialing alice at 12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi
2021-03-01 12:21:12  DEBUG Requesting quote for 0.00008795 BTC
2021-03-02 09:50:17 +11:00
Thomas Eizinger
cb4e2c041b
Rename opt to args 2021-03-02 09:50:17 +11:00
Thomas Eizinger
f4827e3fa4
Improve time formatting of log output
Previously, the time was formatted as ISO8601 timestamps which is
barely readable by humans. Activating the `chrono` feature allows
us to format with a different format string. The output now looks
like this:

2021-03-01 11:59:52  DEBUG Database and seed will be stored in /home/thomas/.local/share/xmr-btc-swap
2021-03-01 11:59:52  DEBUG Starting monero-wallet-rpc on port 40673
2021-03-01 11:59:59  DEBUG Still got 0.00009235 BTC left in wallet, swapping ...
2021-03-01 11:59:59  DEBUG Dialing alice at 12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi
2021-03-01 11:59:59  DEBUG Requesting quote for 0.00008795 BTC

There is a double space after the time which is already fixed in
tracing-subscriber but not yet released.

See https://github.com/tokio-rs/tracing/issues/1271.
2021-03-02 09:50:16 +11:00
Thomas Eizinger
a82e82edd5
Tell the user about the monero-wallet-rpc download
Fixes #242.
2021-03-02 09:50:16 +11:00
Thomas Eizinger
06e3bccaa6
Don't print PeerId when requesting quote
Bob always just talks to one party, the PeerId is just noise.
2021-03-02 09:50:16 +11:00
Thomas Eizinger
cbef577e2d
Inform user that we are going to swap the remainder of the balance 2021-03-02 09:50:15 +11:00
Thomas Eizinger
b7c3524b4f
Abort the eventloop if the dialling fails 2021-03-02 09:50:14 +11:00
Thomas Eizinger
4e9e186462
Don't log things the user doesn't care about
The user configured neither a Bitcoin wallet backend nor the monero-wallet-rpc so let's not tell them about it.

Fixes #244.
2021-03-02 09:49:55 +11:00
Thomas Eizinger
6b74761e34
Remove tracing context
The swap_cli can only do one swap at a time, no need for the swap ID span.
2021-03-02 09:49:55 +11:00
Thomas Eizinger
3d2d447fba
Improve error message
YMMV but I think this sounds better.
2021-03-02 09:49:55 +11:00
Thomas Eizinger
bbbe5f7ae8
Demote / promote log messages to their appropriate level 2021-03-02 09:49:53 +11:00
Thomas Eizinger
7387884e6d
Move log messages to the appropriate abstraction layer
Log messages are ideally as close to the functionality they are talking about, otherwise we might end up repeating ourselves on several callsites or the log messages gets outdated if the behaviour changes.
2021-03-02 09:49:33 +11:00
Thomas Eizinger
b8df4a3145
Inline tracing configuration for swap_cli
This allows us to configure the presentation separately from the ASB.
2021-03-02 09:49:33 +11:00
Thomas Eizinger
a0e7c6ecf7
Don't Arc the AtomicU32
We never clone this type, there is no need to wrap it in an `Arc`.
2021-03-02 09:49:33 +11:00
Thomas Eizinger
40dcf0355a
Simplify Transfer::transfer return type
We never use the fee returned from this function, remove it.
2021-03-02 09:49:30 +11:00
bors[bot]
1de3fa486e
Merge #247
247: Calculate max_giveable based on spending script size r=da-kami a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-01 05:27:28 +00:00
Thomas Eizinger
9f0b1c5cbe
Calculate max_giveable based on spending script size 2021-03-01 15:35:45 +11:00
Daniel Karzel
8c40ee1da4 Change anyhow! to bail! in error scenarios 2021-03-01 14:24:44 +11:00