Daniel Karzel [Thu, 1 Apr 2021 05:14:59 +0000 (16:14 +1100)]
Avoid over-/underflow error in coin_select
Adds fix for edge-cases involving small UTXOs (where value < fee) where the coin_select calculation would panic with overflow/underflow errors.
Bitcoin is limited to 21*(10^6), so any Bitcoin amount fits into i64.
LLFourn [Mon, 8 Feb 2021 04:40:56 +0000 (15:40 +1100)]
Added `add_foreign_utxo`
To allow adding UTXOs external to the current wallet.
The caller must provide the psbt::Input so we can create a coherent PSBT
at the end and so this is compatible with existing PSBT workflows.
Main changes:
- There are now two types of UTXOs, local and foreign reflected in a
`Utxo` enum.
- `WeightedUtxo` now captures floating `(Utxo, usize)` tuples
- `CoinSelectionResult` now has methods on it for distinguishing between
local amount included vs total.
Tobin Harding [Wed, 24 Feb 2021 02:39:36 +0000 (13:39 +1100)]
Use mixed order insertions
Currently we have a unit test to test that signers are sorted by
ordering. We call `add_external` to add them but currently we add them
in the same order we expect them to be in. This means if the
implementation happens to insert them simply in the order they are
added (i.e. insert to end of list) then this test will still pass.
Insert in a mixed order, including one lower followed by one higher -
this ensures we are not inserting at the front or at the back but are
actually sorting based on the `SignerOrdering`.
Tobin Harding [Wed, 24 Feb 2021 02:23:17 +0000 (13:23 +1100)]
Use id() for DummySigner comparison
If we give the `DummySigner` a valid identifier then we can use this to
do comparison.
Half the time we do comparison we only have a `dyn Signer` so we cannot
use `PartialEq`, add a helper function to check equality (this is in
test code so its not toooo ugly).
Tobin Harding [Wed, 10 Feb 2021 00:18:39 +0000 (11:18 +1100)]
Add cargo check script
We build against various targets on CI, in order to not abuse CI its
nice to see if code is good before pushing.
Add a script that runs `cargo check` with various combinations of
features and targets in order to enable thorough checking of the project
source code during development.
Tobin Harding [Wed, 30 Dec 2020 03:58:42 +0000 (14:58 +1100)]
Do not compare vtable
Clippy emits error:
comparing trait object pointers compares a non-unique vtable address
The vtable is an implementation detail, it may change in future. we
should not be comparing vtable addresses for equality. Instead we can
get a pointer to the data field of a fat pointer and compare on that.
Tobin Harding [Wed, 23 Dec 2020 05:19:37 +0000 (16:19 +1100)]
Refactor db/batch matching
Remove the TODO; refactor matching to correctly handle conditionally
built `Sled` variants. Use `unreachable` instead of `unimplemented` with
a comment hinting that this is a bug, this makes it explicit, both at
runtime and when reading the code, that this match arm should not be hit.
Tobin Harding [Wed, 23 Dec 2020 05:15:09 +0000 (16:15 +1100)]
Conditionally compile constructor
The `ChunksIterator` constructor is only used when either `electrum` or
`esplora` features are enabled. Conditionally build it so that we do not
get a clippy warning when building without these features.
Tobin Harding [Wed, 23 Dec 2020 04:58:57 +0000 (15:58 +1100)]
Allow mutex_atomic
Clippy complains about use of a mutex, suggesting we use an
`AtomicUsize`. While the same functionality _could_ be achieved using an
`AtomicUsize` and a CAS loop it makes the code harder to reason about
for little gain. Lets just quieten clippy with an allow attribute and
document why we did so.
Tobin Harding [Wed, 23 Dec 2020 03:08:54 +0000 (14:08 +1100)]
Use next instead of nth(0)
As suggested by clippy we can use `.next()` on an iterator instead of
`nth(0)`. Although arguably no clearer, and certainly no worse, it keeps
clippy quiet and a clean lint is a good thing.
Alekos Filini [Sat, 13 Feb 2021 16:00:03 +0000 (11:00 -0500)]
[policy] Allow specifying a policy path for `Multisig`
While technically it's not required since there are no timelocks inside,
it's still less confusing for the end user if we allow this instead of
failing like we do currently.
Alekos Filini [Sat, 13 Feb 2021 15:58:26 +0000 (10:58 -0500)]
[policy] Remove the `TooManyItemsSelected` error
The `TooManyItemsSelected` error has been removed, since it's not technically an
error but potentailly more of an "over-constraint" over a tx: for instance,
given a `thresh(3,pk(a),pk(b),older(10),older(20))` descriptor one could create
a spending tx with the `[0,1,2]` items that would only be spendable after `10`
blocks, or a tx with the `[0,2,3]` items that would be spendable after `20`.
In this case specifying more items than the threshold would create a tx with
the maximum constraint possible, in this case the `20` blocks. This is not
necessarily an error, so we should allow it without failing.