Skip to content

Abitrary persistence for wallet #771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rustaceanrob
Copy link
Collaborator

Description

With the following approach we can accomplish two things at once:

  1. Make it easy to add new Rust backends without sacrifing performance
  2. Allow for arbitrary persistence accross the FFI

To accomplish this we can differentiate between a native backend and a foreign backend. The foreign backend interacts with the FFI ChangeSet, whereas the native backend can just use the Rust changeset directly. Whenever a new backend is introduced in Rust, a new enum variant may simply be added to the PersistenceType. To build a Sqlite backend, or a foreign backend, the user will use the Persister structure.

Abitrary persistence is allowed by implementing the Persistence trait. This was accomplished with no changes to #756.

I hope 1. motivates this change thoroughly, as we expect BDK will add support for new backends in the future. I am also interested in the applications of 2., where a user might be able to do encrypted and/or cloud storage.

Notes to the reviewers

We use an enum to allow for Rust backends to use Rust changesets directly. Otherwise we may convert them to FFI types. I've thought through many approaches, and I am convinced this is the most robust.

Changelog notice

  • Add possibility for any type of persistence

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

With the following approach we can accomplish two things at once:
1. Make it easy to add new Rust backends without sacrifing performance
2. Allow for arbitrary persistence accross the FFI

To accomplish this we can differentiate between a native backend and a
foreign backend. The foreign backend interacts with the FFI `ChangeSet`,
whereas the native backend can just use the Rust changeset directly.
Whenever a new backend is introduced in Rust, a new enum variant may
simply be added to the `PersistenceType`. To build a Sqlite backend, or
a foreign backend, the user will use the `Persister` structure.

Abitrary persistence is allowed by implementing the `Persistence`
trait. This was accomplished with no changes to bitcoindevkit#756.

I hope 1. motivates this change thoroughly, as we expect BDK will add
support for new backends in the future. I am also interested in the
applications of 2., where a user might be able to do encrypted and cloud
storage.
@rustaceanrob
Copy link
Collaborator Author

Should be ready to go. The integration tests ensure SQL still works.

I may implement a simple database in Swift or Python just to ensure the roundtrips are okay. Otherwise, I think this approach is pretty nifty, as the performance should be the same for SQL users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant