cc3736809a2910d3a739b37a61f1613404fba572 Fix memory database configuration enum (thunderbiscuit) Pull request description: The `DatabaseConfig.Memory` enum currently requires a "junk" string argument which is not used when creating the wallet: ```rust // lib.rs line 24 pub enum DatabaseConfig { Memory { junk: String }, Sled { config: SledDbConfiguration }, } // lib.rs line 209 impl Wallet { fn new( descriptor: String, change_descriptor: Option<String>, network: Network, database_config: DatabaseConfig, blockchain_config: BlockchainConfig, ) -> Result<Self, BdkError> { let any_database_config = match database_config { DatabaseConfig::Memory { .. } => AnyDatabaseConfig::Memory(()), DatabaseConfig::Sled { config } => AnyDatabaseConfig::Sled(config), }; ``` Which translates to the udl file like this: ```txt [Enum] interface DatabaseConfig { Memory(string junk); Sled(SledDbConfiguration config); }; ``` According to the [docs from uniffi-rs](https://mozilla.github.io/uniffi-rs/udl/enumerations.html) the `interface` here is required because the enums have named fields. But after testing I found that we can declare the udl file like so, and remove the requirement for the `junk` argument: ```txt [Enum] interface DatabaseConfig { Memory(); Sled(SledDbConfiguration config); }; ``` On the Rust side we then have ```rust pub enum DatabaseConfig { Memory, Sled { config: SledDbConfiguration }, } ``` And the resulting bindings go from (note that the bindings transform the enum into a sealed class rather than a Kotlin enum) ```kotlin sealed class DatabaseConfig { data class Memory( val junk: String ) : DatabaseConfig() data class Sled( val config: SledDbConfiguration ) : DatabaseConfig() ``` to ```kotlin sealed class DatabaseConfig { object Memory : DatabaseConfig() data class Sled( val config: SledDbConfiguration ) : DatabaseConfig() ``` Which makes the API simpler to use, and removes the confusion created by having to provide an empty string (or not know what we're supposed to provide) to the `Memory()` enum. The final call-site looks like this: ```kotlin fun onlineWalletSyncGetBalance() { // val db = DatabaseConfig.Memory("") val db = DatabaseConfig.Memory val client = BlockchainConfig.Electrum( ElectrumConfig( "ssl://electrum.blockstream.info:60002", null, 5u, null, 100u ) ) val wallet = Wallet(descriptor, null, Network.REGTEST, databaseConfig, blockchainConfig) wallet.sync(LogProgress(), null) val balance = wallet.getBalance() assertTrue(balance > 0u) } ``` All tests run well on my side of things, but I'm opening this more as a discussion piece because I wasn't sure if there were other reasons for the choice of providing the argument to the `Memory` enum, or other design choices I'm not aware of. Any thoughts on this @artfuldev? I think you were the one who wrote the initial enum. Top commit has no ACKs. Tree-SHA512: 135e5943039a08522773f721a7cf6bbb93bd5bb9394bf42a30bab5f3e16fd35ce078056756e020a666d4f574d74080bc3404cc81809c0d7e0afe5c9471878425
Native language bindings for BDK
This repository contains source code for generating native language bindings for the rust based bdk library which is the central artifact of the Bitcoin Dev Kit project.
Each supported language has it's own repository that includes this project as a git submodule. The rust code in this project is a wrapper around the bdk library to expose it's APIs in a uniform way using the mozilla/uniffi-rs bindings generator for each supported target language.
Supported target languages and platforms
The below repositories include instructions for using, building, and publishing the native language binding for bdk supported by this project.
Language | Platform | Repository |
---|---|---|
Kotlin | jvm | bdk-kotlin |
Kotlin | android | bdk-kotlin |
Swift | iOS, macOS | bdk-swift |
Python | linux, macOS | bdk-python |
Contributing
Install uniffi-bindgen cli tool
Install the uniffi-bindgen binary on your system using:
cargo install uniffi_bindgen
The version must be the same as the uniffi
dependency in Cargo.toml
.
Adding new structs and functions
See the UniFFI User Guide
For pass by value objects
- create new rust struct with only fields that are supported UniFFI types
- update mapping
bdk.udl
file with newdictionary
For pass by reference values
- create wrapper rust struct/impl with only fields that are
Sync + Send
- update mapping
bdk.udl
file with newinterface
Goals
- Language bindings should feel idiomatic in target languages/platforms
- Adding new targets should be easy
- Getting up and running should be easy
- Contributing should be easy
- Get it right, then automate
Thanks
This project is made possible thanks to the wonderful work by the mozilla/uniffi-rs team.