Commit Graph

35 Commits

Author SHA1 Message Date
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
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
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
9f0b1c5cbe
Calculate max_giveable based on spending script size 2021-03-01 15:35:45 +11:00
Thomas Eizinger
f472070546
Remove --send-btc in favor of swapping the available balance
If the current balance is 0, we wait until the user deposits money
to the given address. After that, we simply swap the full balance.

Not only does this simplify the interface by removing a parameter,
but it also integrates the `deposit` command into the `buy-xmr`
command.

Syncing a wallet that is backed by electrum includes transactions
that are part of the mempool when computing the balance.
As such, waiting for a deposit is a very quick action because it
allows us to build our lock transaction on top of the yet to be
confirmed deposit transactions.

This patch introduces another function to the `bitcoin::Wallet` that
relies on the currently statically encoded fee rate. To make sure
future developers don't forget to adjust both, we extract a function
that "selects" a fee rate and return the constant from there.

Fixes #196.
2021-02-26 14:36:59 +11:00
Thomas Eizinger
32cb0eb896
Rename build_tx_lock_psbt to send_to_address
Being defined on the wallet itself, a more generic name fits better
on what this function actually does.
2021-02-26 14:36:59 +11:00
Thomas Eizinger
67fe01a2ef
Remove BuildTxLockPsbt and GetNetwork traits
These traits were only used once within the `TxLock` constructor.
Looking at the rest of the codebase, we don't really seem to follow
any abstractions here where the protocol shouldn't know about the
exact types that is being passed in.

As such, these types are just noise and might as well be removed in
favor of simplicity.
2021-02-26 14:36:58 +11:00
Thomas Eizinger
0f8fbd087f
Make all fields of bitcoin::Wallet private
This reveals that the `network` field is actually unused.
2021-02-26 14:36:58 +11:00
Thomas Eizinger
1876d17ba4
Remove map_err in favor of ?
`?` maps the error automatically.
2021-02-26 14:36:57 +11:00
Thomas Eizinger
7d324d966a
Remove syncing wallet log
BDK already has a log line for the sync that we could enable if we
wanted such a log.
Additionally, _we_ are not actually syncing the wallet, bdk is so our
log line was lying. It should have said "calling bdk to sync wallet".
2021-02-26 14:36:57 +11:00
bors[bot]
81228c9d5b
Merge #209
209: Upgrade to bdk 0.4 r=thomaseizinger a=thomaseizinger

Effectively, this also means:

- Upgrading to rust-bitcoin 0.26
- Upgrading to miniscript 5
- Upgrading monero to 0.10
- Upgrading curve25519-dalek to 3
- Upgrading bitcoin-harness to rust-bitcoin 0.26 (https://github.com/coblox/bitcoin-harness-rs/pull/21)
- Upgrade `ecdsa_fun` to latest version
- Replace `cross_curve_dleq` with `sigma_fun` (to avoid an upgrade dance on that library)

I refrained from specifying `rev`s in the Cargo.toml because we have a lock-file anyway. This should allow us to update those dependencies easier in the future by just running `cargo update -p <dependency>`.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-02-22 00:00:06 +00:00
Daniel Karzel
164de3c524 Properly calculate the confirmations for Bitcoin tx
Once the transaction was included into a block it has one confirmation - before inclusion it has zero.
current-block-height - transaction-block-height = zero; but that means one confirmation.
Hence, the confirmation calculation was adapted to: Current-block-height - (transaction-block-height - 1).
2021-02-19 17:09:53 +11:00
Thomas Eizinger
2d8ede80e1
Use released version of backoff 2021-02-19 15:18:40 +11:00
Thomas Eizinger
84bc2c82b7
Upgrade to bdk 4.0
To achieve this we also:

- upgrade rust-bitcoin to 0.26
- upgrade bitcoin-harness to latest version (which also depends bitcoin 0.26)
- upgrade to latest edcsa-fun
- replace cross_curve_dleq proof with sigma_fun (to avoid an upgrade dance over there)
2021-02-19 15:18:37 +11:00
bors[bot]
8537b88a68
Merge #201
201: Fix ASB - Prevent the future from being stopped in production r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-02-17 04:45:48 +00:00
Daniel Karzel
ebb869e6f4 Distinguish transient and permanent Electrum errors 2021-02-17 11:56:17 +11:00
Daniel Karzel
9b93cabfdf Use context instead of map_error 2021-02-17 11:09:09 +11:00
rishflab
00e2b257c4 Remove misplaced sync wallet call 2021-02-17 10:56:10 +11:00
Daniel Karzel
77ec7e502f Distinguish permanent and transient error when watching tx 2021-02-16 16:26:37 +11:00
rishflab
bc1d2bda54 Test URL creation for default electrum HTTP API 2021-02-16 15:13:45 +11:00
rishflab
4768c79070 Derive bitcoin private key from seed 2021-02-16 14:57:12 +11:00
Thomas Eizinger
a51194b9fa Instantiate electrum client with custom config with 2 retries
The default number of retries is 1. Unfortunately, the way this config
value is interpreted doesn't actually lead to a retry. We have to set
it to 2 to actually make it retry.

See https://github.com/bitcoindevkit/rust-electrum-client/issues/47.
2021-02-16 14:57:12 +11:00
rishflab
180e778df9 Allow blockchain calls to fail
Prior to this change, functions could not fail early on permanent errors eg. parsing a url. Merged error enums.
2021-02-16 14:57:10 +11:00
rishflab
a0ef1f96ec Replace bitcoind wallet with bdk wallet
The bitcoind wallet required the user to run a bitcoind node. It was replaced with a bdk wallet which allows the user to connect to an electrum instance hosted remotely. An electrum and bitcoind testcontainer were created to the test the bdk wallet. The electrum container reads the blockdata from the bitcoind testcontainer through a shared volume. bitcoind-harness was removed as bitcoind initialisation code was moved into test_utils. The bdk wallet differs from the bitcoind wallet in that it needs to be manually synced with an electrum node. We synchronise the wallet once upon initialisation to prevent a potentially long running blocking task from interrupting protocol execution. The electrum HTTP API was used to get the latest block height and the transaction block height as this functionality was not present in the bdk wallet API or it required the bdk wallet to be re-synced to get an up to date value.
2021-02-16 14:04:52 +11:00
Franck Royer
c316ea5244
Upgrade toolchain
Needed to use libp2p-async-await
2021-02-04 15:18:33 +11:00
Daniel Karzel
89b3775e05 Rename config to execution_params 2021-01-29 17:27:50 +11:00
Daniel Karzel
802dc61e7e Configuration for RPC urls and Bitcoin wallet name 2021-01-29 17:21:19 +11:00
rishflab
77fc5743a2
Upgrade tokio to 1.0
Upgrade bitcoin harness dependency to latest commit

Upgrade backoff to fix failing tests. The previous version of backoff had a broken version of the retry function. Upgraded to a newer comit which fixes this problem.

Upgrade hyper to 0.14 as the 0.13 was bringing in tokio 0.2.24

Upgraded bitcoin harness to version that uses tokio 1.0 and reqwest 0.11

Upgrade reqwest to 0.11. Reqwest 0.11 uses tokio 1.0

Upgrade libp2p to 0.34 in preparation for tokio 1.0 upgrade
2021-01-29 11:36:10 +11:00
Daniel Karzel
44c4b5dcea Remove newlines from import statements to avoid problems
Rust fmt automatically groups the imports (from top to bottom) as `pub use` `use crate` and `use`.
There is no need to introduce sections which cause annoyance when auto importing using the IDE.
2021-01-21 19:10:51 +11:00
Franck Royer
31c63f0c4d
Remove dead code 2021-01-14 11:40:34 +11:00
rishflab
e7c00d742e Re-export bitcoin and monero types 2021-01-08 12:34:36 +11:00
rishflab
c900d12593 Merge xmr_btc crate
Created network, storage and protocol modules. Organised
files into the modules where the belong.

xmr_btc crate moved into isolated modulein swap crate.

Remove the xmr_btc module and integrate into swap crate.

Consolidate message related code

Reorganise imports

Remove unused parent Message enum

Remove unused parent State enum

Remove unused dependencies from Cargo.toml
2021-01-08 12:34:33 +11:00