35 Commits

Author SHA1 Message Date
志宇
75f8b81d58
Update documentation
* Add `warn(missing_docs)` for `bdk_wallet` and `bdk_chain`.
* Add missing documentation.
* Remove `LocalChain::heights` method.
* Remove old TODOs.
2023-06-04 03:32:19 +08:00
Shourya742
ac80829caa
Rename fields of tx_graph::Additions
* Changed `tx` to `txs`
* Changed `txout` to `txouts`
2023-06-04 03:32:18 +08:00
志宇
50425e979b
Introduce keychain::LocalChangeSet
This corresponds to `keychain::KeychainChangeSet` but for the redesigned
structures with `LocalChain`.

This structure is now used in `Wallet` as well as the examples.
2023-06-04 03:32:18 +08:00
志宇
f55974a64b
[examples_redesign] Introduce example_cli package
This is the equivalent of `keychain_tracker_example_cli` that works with
the redesigned structures.
2023-06-04 03:32:17 +08:00
志宇
e01d17d59b
Improve txout listing and balance APIs for redesigned structures
Instead of relying on a `OwnedIndexer` trait to filter for relevant
txouts, we move the listing and balance methods from `IndexedTxGraph` to
`TxGraph` and add an additional input (list of relevant outpoints) to
these methods.

This provides a simpler implementation and a more flexible API.
2023-05-10 23:57:24 +08:00
志宇
2aa08a5898
[persist_redesign] Introduce redesigned persist types
This is a more generic version of `keychain::persist::*` structures.

Additional changes:

* The `Append` trait has a new method `is_empty`.
* Introduce `Store` structure for `bdk_file_store`.
2023-05-09 12:55:44 +08:00
志宇
4ae727a1fb
[chain_redesign] Relax generic constraints 2023-05-05 16:35:39 +08:00
rajarshimaitra
911af34f50
[bdk_chain_redesign] Fix calculation bugs.
* `IndexedTxGraph::try_balance` should include "confirmed and spendable"
  into `confirmed` balance.
* `TxGraph::try_list_chain_unspents` filter logic should be reversed.
2023-04-28 19:07:12 +08:00
志宇
1b152647c5
[bdk_chain_redesign] Change insert_relevant_txs method
Instead of forcing all transactions inserted to use the same anchors, we
change the API to have unique anchors per transaction.

This allows for more flexibility in general. For example, use `Anchor`
implementations that contain the position in a block of a transaction.
2023-04-23 00:21:31 +08:00
志宇
ac336aa32f
[bdk_chain_redesign] Make insert_relevant_txs topologically-agnostic
The `insert_relevant_txs` test has also been changed to used
`KeychainTxOutIndex` so that index additions can be checked
(`SpkTxOutIndex` has no additions).

Additionally, generic bounds of some `IndexedTxGraph` list methods have
been fixed.
2023-04-22 23:09:39 +08:00
志宇
165b874dfe
[bdk_chain_redesign] Add test for insert_relevant_txs
Ensure `insert_relevant_txs` does not require transactions to be in
topological order.

Other changes: Rm `try_list_owned_txs` as it is useless
2023-04-21 14:55:30 +08:00
志宇
f3e7b67bf1
[bdk_chain_redesign] Various tweaks and fixes
The `ConfirmationHeight` trait has been removed in favour of a second
method on the `Anchor` trait: `confirmation_height_upper_bound()`.

Methods `try_balance_at()` and `balance_at()` of `IndexedTxGraph` have
been removed as they do not provide additional functionality.

`IndexedTxGraph::insert_relevant_txs` now uses two loops, the first loop
indexes all transactions first. This is done as some indexes require
ancestor transactions to be indexed first and we cannot guarantee that
the input transactions are in topological order.
2023-04-21 13:29:44 +08:00
志宇
34a7bf5afe
[bdk_chain_redesign] Rm unnecessary code and premature optimisation
* Remove `chain_oracle::CacheBackend` for now as it is not used.
* `SparseChain` does not need to implement `ChainOracle`.
* Remove filter predicate for `list..` methods of `TxGraph` and
  `IndexedTxGraph` as this is premature optimisation.
* `Append` can be implemented for all `BTreeMap`s and `BTreeSet`s,
  instead of only `local_chain::ChangeSet`.
2023-04-20 18:07:26 +08:00
志宇
8e36a2e5f6
[bdk_chain_redesign] Remove incomplete logic
`ObservedAs::ConfirmedImplicit` is incomplete, remove for now.

`local_chain::ChangeSet` does not need to be a single-element tuple
struct.
2023-04-19 12:21:39 +08:00
志宇
81436fcd72
[bdk_chain_redesign] Fix Anchor definition + docs
Previously, I have misunderstood the definition of anchor. If a tx is
anchored in a block, it does not necessarily mean it is confirmed in
that block. The tx can be confirmed in an ancestor block of the anchor
block.

With this new definition, we need a new trait `ConfirmationHeight` that
has one method `confirmation_height`. This trait can be used to extend
`Anchor` for those implementations that can give us the exact
conirmation height of a tx (which is useful in most cases).

Another change is to add another variant to the `ObservedAs` enum;
`ObservedAs::ConfirmedImplicit(A)`. If a tx does not have an anchor, but
another tx that spends it has an anchor that in in the best chain, we
can assume that tx is also in the best chain. The logic of
`TxGraph::try_get_chain_position` is also changed to reflect this.

Some methods from `IndexedTxGraph` have been moved to `TxGraph` as they
do not require the `Indexer`. Some `TxGraph` methods have been renamed
for clarity and consistency.

Also more docs are added.
2023-04-18 00:02:14 +08:00
志宇
10ab77c549
[bdk_chain_redesign] MOVE TxIndex into indexed_chain_graph.rs
`tx_graph.rs` is rearranged as well.
2023-04-12 11:24:05 +08:00
志宇
7d92337b93
[bdk_chain_redesign] Remove IndexedTxGraph::last_height
It is better to have this external to this structure.
2023-04-10 16:51:16 +08:00
志宇
a7fbe0ac67
[bdk_chain_redesign] Documentation improvements 2023-04-10 16:23:10 +08:00
志宇
611d2e3ea2
[bdk_chain_redesign] Consistent ChainOracle
The problem with the previous `ChainOracle` interface is that it had no
guarantee for consistency. For example, a block deemed to be part of the
"best chain" can be reorged out. So when `ChainOracle` is called
multiple times for an operation (such as getting the UTXO set), the
returned result may be inconsistent.

This PR changes `ChainOracle::is_block_in_chain` to take in another
input `static_block`, ensuring `block` is an ancestor of `static_block`.
Thus, if `static_block` is consistent across the operation, the result
will be consistent also.

`is_block_in_chain` now returns `Option<bool>`. The `None` case means
that the oracle implementation cannot determine whether block is an
ancestor of static block. `IndexedTxGraph::list_chain_txouts` handles
this case by checking child spends that are in chain, and if so, the
parent tx must be in chain too.
2023-04-10 13:03:51 +08:00
志宇
24cd8c5cc7
[bdk_chain_redesign] More tweaks and renamings 2023-04-05 19:13:42 +08:00
志宇
ddd5e951f5
[bdk_chain_redesign] Modify signature of TxIndex
This makes the API of `TxIndex` more consistent between scanning in data
and checking whether certain data is relevant.
2023-04-05 18:17:08 +08:00
志宇
da4cef044d
[bdk_chain_redesign] Introduce Append trait for additions
Before, we were using `core::ops::AddAsign` but it was not the most
appropriate.
2023-04-05 17:29:20 +08:00
志宇
89cfa4d78e
[bdk_chain_redesign] Better names, comments and generic bounds
* Instead of implementing `ChainPosition` for `ObservedIn<BlockId>` to
  use `FullTxOut` methods (`is_spendable_at` and `is_mature`), we create
  alternative versions of those methods that require bounds with `Anchor`.
  This removes all `ObservedIn<A>: ChainPosition` bounds for methods of
  `IndexedTxGraph`.

* Various improvements to comments and names.
2023-04-05 16:39:54 +08:00
志宇
a7eaebbb77
[bdk_chain_redesign] Add serde support for IndexedAdditions 2023-03-31 22:55:57 +08:00
志宇
c09cd2afce
[bdk_chain_redesign] Added methods to LocalChain
Also made the `IndexedTxGraph::index` field public (`index()` and
`index_mut()` methods are no longer needed).
2023-03-31 22:42:47 +08:00
志宇
a63ffe9739
[bdk_chain_redesign] Simplify TxIndex 2023-03-31 13:45:15 +08:00
志宇
a1172def7d
[bdk_chain_redesign] Revert some API changes
Methods of old structures that return transaction(s) no longer return
`TxNode`, but `Transaction` as done previously.

`TxInGraph` is renamed to `TxNode`, while the internal `TxNode` is
renamed to `TxNodeInternal`.
2023-03-31 11:55:11 +08:00
志宇
468701a129
[bdk_chain_redesign] Initial work on LocalChain. 2023-03-30 13:07:13 +08:00
志宇
3440a05711
[bdk_chain_redesign] Add docs 2023-03-28 10:58:23 +08:00
志宇
236c50fa7b
[bdk_chain_redesign] IndexedTxGraph keeps track of the last synced height
This is important as a `ChainOracle` implementation is updated
separately to an `IndexedTxGraph`.
2023-03-27 22:42:39 +08:00
志宇
e902c10295
[bdk_chain_redesign] Fix apply_additions logic for IndexedTxGraph. 2023-03-27 21:51:11 +08:00
志宇
313965d8c8
[bdk_chain_redesign] mut_index should be index_mut 2023-03-27 20:56:42 +08:00
志宇
db7883d813
[bdk_chain_redesign] Add balance methods to IndexedTxGraph 2023-03-27 19:55:57 +08:00
志宇
d0a2aa83be
[bdk_chain_redesign] Add apply_additions to IndexedTxGraph
* Get mutable index from `IndexedChainGraph`.
* Also add `apply_additions` method to `TxIndex` trait.
2023-03-27 16:02:21 +08:00
志宇
6cbb18d409
[bdk_chain_redesign] MOVE: IndexedTxGraph into submodule 2023-03-27 14:21:10 +08:00