Express the wallet changeset over the FFI layer #756
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Builds on #754 to create a fully expressive and serializable
ChangeSet
type. The goal is for this to enable arbitrary persistence backends across the FFI layer. Ultimately that would close #739 and any further database requests that are outside the immediately supported options.For context: The iterators in the BDK changesets are
BTree
based to beno_std
compatible and have deterministic ordering of duplicate data across all targets. UniFFI exposes only two iterators across the boundary,Vec
andHashMap
, but I can try to lay out why I think using these is acceptable.The goal here is to convert between
bdk_wallet::ChangeSet
and FFIChangeSet
, and the easiest way to go about that is to just make each field convertible. For theLocalChain::ChangeSet
, I iterate over theBTreeMap
, which will return the key-value pairs in order. That means the vector will be in order over the FFI layer. Everything else coming from BDK could be ordered by key, but is not required in my opinion to implement the persistence. For instance any mapping fromDescriptorId
to last revealed index is okay, as theDescirptorId
do not necessarily have to be in any particular order. Same goes forTxid
orOutpoint
mapping to some value. While it is nice to be reproducible, these keys are suitable for aHashMap
.Can elaborate on the next call
Notes to the reviewers
In Swift, and key of a
HashMap
must implementEquitable
andHashable
. We can exportEq
andHash
from Rust for Objects, but not for Records from what I can tell. As a result, I made a kind-of-gross wrapper calledHashableOutPoint
that is anObject
so it can be used as a key, but it is convertible to the underlyingRecord
if required. Open to ideas on that one.Also, I cannot for the life of me figure out the best way to go from a
Descriptor<DescriptorPublicKey>
intoDescriptorPublicKey
and vise versa without introducing anunwrap
. Feels like we can improve that.Changelog notice
Checklists
All Submissions:
cargo fmt
andcargo clippy
before committingNew Features:
Bugfixes: