40 Commits

Author SHA1 Message Date
Antoine Poinsot
1cd61c9236
descriptors: require that an origin be set for the keys.
It would be possible for users to create a descriptor with xpubs without
an origin set. In fact, not many are used to origins and it's a very
likely mistake. Signers need this information in order to be able to
sign. So they could potentially create a wallet and potentially never be
able to sign for one or multiple keys.

Fix this by requiring an origin for all keys in the descriptor.
2023-02-01 13:54:18 +01:00
Antoine Poinsot
e22e30dc8d
descriptors: support Multisig in both the primary and recovery paths
We only allow to create "legacy" multisigs for now (that is, what fits
in a CHECKMULTISIG, ie k-of-n with n<=20). See
https://github.com/wizardsardine/liana/issues/53 for discussions around
this.

We are a bit more laxist on parsing, where any miniscript that
corresponds to a multisig policy will be accepted.

Note this makes the helper inferring the CSV value from semantic policy
incorrect, but this is fix in a later commit as part of a complete
refactor of this logic.
2023-01-24 19:38:34 +01:00
Antoine Poinsot
54410cd9c4
database: allow to query coins by their spending status 2022-12-09 12:19:01 +01:00
edouard
3cd709697b Add listconfirmed command 2022-11-22 19:31:02 +01:00
Antoine Poinsot
968a7d17a0
daemon: rename Minisafe to Liana 2022-11-17 17:10:22 +01:00
Antoine Poinsot
42d2ffeec1
db: more flexible interface for updating our next derivation indexes.
Instead of only incrementing it, allow to be able to set it to any
value. This will be useful for instance to set the derivation to the
latest used onchain, if another wallet is much further down the
derivation tree than we are (or after a rescan).
2022-11-16 15:19:50 +01:00
Antoine Poinsot
96b634b69c
bitcoind: make the rescan starting interface failible
This makes us more robust to races, where we'd crash previously
2022-11-14 09:47:43 +01:00
Antoine Poinsot
85cd261fcd
bitcoin: remove the BitcoinError enum, use String as error instead
It looks like we'd end up only using variants that contain a String, for
little benefit. Cut down on complexity for now.
2022-11-14 09:37:13 +01:00
Antoine Poinsot
7e83bfad55
db: the interface to store the state of an ongoing rescan
We'll need to store in persistent storage if a rescan was requested by a
user, and if so from what date.

For the SQLite implementation we introduce a rescan_timestamp to the
wallet table.
2022-11-14 09:20:26 +01:00
Antoine Poinsot
bd4de0b87a
bitcoin: interface for rescanning the chain on the Bitcoin backend
For now we are given a timestamp and use 'importdescriptors'. It might be
better to be passed a height and use 'rescanblockchain' instead.
2022-11-14 09:20:26 +01:00
Antoine Poinsot
80803c78a4
bitcoind: handle missing previousblockhash from getblockheader
It seems that internally bitcoind might temporarily not have a pprev
pointer for a block. This will result in the optional
"previousblockhash" field to be null and would previously make us crash.

Handle that gracefully.
2022-11-09 10:22:33 +01:00
Antoine Poinsot
d9f905a19a
db: track the next unused derivation index for change, too 2022-10-24 15:00:17 +02:00
Antoine Poinsot
58a0e57c59
db: record whether a coin was received on a change address
So we know what descriptor to use when spending it.
2022-10-24 15:00:16 +02:00
Antoine Poinsot
ca3d7c1f33
descriptors: introduce a newtype for the multipath descriptor
The multipath descriptor has very different properties than the receive
and change ones. Use a newtype to assist us in differentiating those.
2022-10-24 15:00:15 +02:00
Antoine Poinsot
1320ee30ba
daemon: use multipath descriptors
In config, expect to be given a multipath descriptor that contains a
derivation path for both receive and change addresses, but only for
those.

Instead of 'xpub/*', start using 'xpub/0/*' and 'xpub/1/*'.

When creating the watchonly wallet on bitcoind import both the receive
and change descriptors.

When polling, check for coins on both descriptors.
2022-10-24 15:00:14 +02:00
Antoine Poinsot
7a18c583cb
bitcoind: filter received coins based on parent descriptors
Our bitcoind watchonly wallet could, maybe, have other descriptors that
were imported. Sounds pretty unlikely since we use a dedicated wallet
but hey.

More importantly, we'll need to know the parent descriptor of the coin
in order to recognize it as newly received or change.
2022-10-24 15:00:13 +02:00
Antoine Poinsot
a4bdb1efb7
tree wide: upgrade to Miniscript 8.0.0
This also updates the indirect rust-bitcoin dependency to 0.29.

Major changes are in the descriptors management:
	- The rust-miniscript descriptors don't support raw hashes
	  within the pk_h() fragments, so we don't need all the boutique
	  management for this.
	- The key translator API changed.
	- We now take a u16 for the timelock instead of our previous
	  checks. This was inspired by the new rust-bitcoin Sequence
	  type.
	- We now take a path instead of just a derivation index in
	  DerivedKey. We might use paths after all...

As for rust-bitcoin it's just a few nits:
	- No more 'global' field on PSBTs (yay)
	- Couple more trait derivation on types
	- Some APIs were renamed.
2022-10-20 17:53:26 +02:00
Antoine Poinsot
b14bc602d4
bitcoin: interface for broadcasting a transaction 2022-10-18 19:48:20 +02:00
Antoine Poinsot
92f7ef1225
commands: make listcoins return all coins by default
We'll add some parameters to filter by status and/or outpoints later on.
But for now also list coins that were spent or are being spent.
2022-10-17 11:47:41 +02:00
Antoine Poinsot
e9e4acd69d
db: database interface to rollback to a previous best block 2022-10-17 11:47:40 +02:00
Antoine Poinsot
972c8dac86
db: require the spend block height from the DB interface
Hence add a 'spend_block_height' field to the 'coin' column in the
SQLite implementation. This also contains a couple cleanups, as well as
a fix (we were still checking if the blockheight was > 1).
2022-10-17 10:44:38 +02:00
Antoine Poinsot
6038843d33
database: rename coins' spent_at in spend_block_time 2022-10-17 10:27:03 +02:00
Antoine Poinsot
cce227f80f
bitcoin: interface to get the common block in our and the backend's chains
This will be used to get the common ancestor in the chain upon detecting
a block chain reorganization.
2022-10-17 10:26:23 +02:00
Antoine Poinsot
8b4866158b
daemon: clippification
That's a minimal API break because of some error variants that were
Box'd.
2022-10-13 14:24:24 +02:00
Antoine Poinsot
c9b6c6dedb
db: re-rename list_unspent_coins into unspent_coins 2022-10-12 17:19:27 +02:00
edouard
3cf6bcbb98 add spent_coins to bitcoind poller 2022-10-05 17:41:16 +02:00
edouard
94ee94edbd Add blocktime and spent_at to coins table
Spent coins are coins where spent_txid and spent_at
are both not null.
2022-10-05 17:41:16 +02:00
Antoine Poinsot
c73e8a42dd
commands: add a new 'delspendtx' command 2022-10-01 14:05:27 +02:00
Antoine Poinsot
c6e004806a
commands: add a 'list_spend' command (and 'listspendtxs' RPC) 2022-10-01 13:33:08 +02:00
Antoine Poinsot
bafcadf398
db: interface to upsert a Spend PSBT and query it by txid
I initially wanted to have a bridge table between the 'coins' and
'spend_transactions' table as we do in revaultd. But let's not optimize
to early, we'll see if/when we need it.
2022-09-15 11:41:33 +02:00
Antoine Poinsot
46320d5fc0
db: an interface to query coins by their outpoints 2022-09-15 11:41:29 +02:00
Antoine Poinsot
0fd57db8a8
Use the descriptor newtype instead of the raw miniscript Descriptor type 2022-08-18 12:02:27 +02:00
Antoine Poinsot
869d370daa
descriptors: introduce an InheritanceDescriptor type
We check it when creating it either from material or from string.
2022-08-18 12:02:26 +02:00
Antoine Poinsot
99a9cbf0f8
poller: query derivation index by address from DB 2022-08-18 12:01:26 +02:00
Antoine Poinsot
3f17e9f0c3
database: change interface from update_der_index to increment_der_index
And take care of updating the (addr->index) mapping in the SQLite implementation.
2022-08-18 12:01:26 +02:00
Antoine Poinsot
c6a25adfcd
bitcoin: interface for coins discovery and updates 2022-08-18 12:01:24 +02:00
Antoine Poinsot
05b3af1b5a
database: interface and implementation for coins storage and update 2022-08-18 12:01:24 +02:00
Antoine Poinsot
fe5de96312
Shorten the paths to the dummy datadirs in the unit tests
It failed CI on MacOS because of overflowing SUN_PATH_LEN.
2022-08-17 19:40:00 +02:00
Antoine Poinsot
726209cc0a
jsonrpc: add a 'stop' command
This also implements a simple JSONRPC server sanity check

And introduces a new tmp_dir() test utility, that i didn't have the courage to split from this commit
2022-08-17 19:39:57 +02:00
Antoine Poinsot
d03c469967
Introduce a testutils module with a DummyMinisafe for unit tests
So we can have unit tests without a dummy bitcoind thread, as we
currently do for the startup test.

This commit also implements sanity checks for the two existing commands
using this mechanism.
2022-08-17 19:39:56 +02:00