cba69e681aClean up of From traits implementations (thunderbiscuit)35d8fb3139Clean up extract_tx method on PSBT (thunderbiscuit)f003a6275eClean up conversion between BDK TransactionDetails to ffi TransactionDetails (thunderbiscuit)2f62377eecAdd Eq and PartialEq traits on the Transaction type (thunderbiscuit)81e208222aAdd uniffi/cli as default feature to cargo (thunderbiscuit)3dc6596aa2Add include_raw boolean parameter on wallet list_transactions method (thunderbiscuit)2342265c26Remove unused NetworkLocalUtxo type (thunderbiscuit)6c561228c2Use the latest version of the Android NDK (thunderbiscuit)e86909ab3dClean up input and output methods on Transaction type (thunderbiscuit)8e51756a3aFix clippy errors (thunderbiscuit)40263b425eRemove deprecated bdk-ffi-bindgen tool (thunderbiscuit)9437051668Fix fmt and clippy errors (thunderbiscuit)7557e214c8Add optional transaction field on the TransactionDetails type (thunderbiscuit)40ca62086cExpose all fields on the Transaction type (thunderbiscuit)e0506deffaAdd new utility methods on Transaction type (thunderbiscuit)d3e183a498Add Kotlin API docs for new Transaction methods (thunderbiscuit)1e9ecfbe52Add weight, size, and vsize methods on the Transaction type (thunderbiscuit) Pull request description: ## Description We've recently exposed the `Transaction` type, and I think a few methods on it would be useful. ~This is a draft PR with the first 3: `weight()`, `size()`, and `vsize()`~ _Edit: it's now much more_. I think there might be other methods we might want to expose as well. [Take a look at the docs to see them all](https://docs.rs/bitcoin/0.29.2/bitcoin/blockdata/transaction/struct.Transaction.html). Other candidates have now been added: 1. [is_explicitly_rbf](https://docs.rs/bitcoin/0.29.2/bitcoin/blockdata/transaction/struct.Transaction.html#method.is_explicitly_rbf) 2. [is_lock_time_enabled](https://docs.rs/bitcoin/0.29.2/bitcoin/blockdata/transaction/struct.Transaction.html#method.is_lock_time_enabled) 3. [is_absolute_timelock_satisfied](https://docs.rs/bitcoin/0.29.2/bitcoin/blockdata/transaction/struct.Transaction.html#method.is_absolute_timelock_satisfied) 4. [is_coin_base](https://docs.rs/bitcoin/0.29.2/bitcoin/blockdata/transaction/struct.Transaction.html#method.is_coin_base) 5. [txid](https://docs.rs/bitcoin/0.29.2/bitcoin/blockdata/transaction/struct.Transaction.html#method.txid) This PR is growing in size but I decided to add all 4 fields on the `Transaction` type. This is useful because it means we can now add the `transaction` field on the `TransactionDetails` type (also added in this PR). I still have a few questions regarding all the translation between the ffi and bdk/rust types, some of the traits I had to remove (Eq and PartialEq on the TransactionDetails type) as well as the usage of `Option<Arc<T>>` vs `Arc<Option<T>>`. Will outline those tomorrow. Closes #303 Closes #187 ## Changelog notice ```md APIs Added - `Transaction` type now exposes the `.weight()`, `.size()`, `.vsize()`, `is_explicitly_rbf()`, `is_lock_time_enabled()`, `is_coin_base(), and `txid()` methods [#307] [#307]: https://github.com/bitcoindevkit/bdk-ffi/pull/307 ``` ## Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [ ] I've added tests for the new feature * [x] I've added docs for the new feature ACKs for top commit: notmandatory: ACKcba69e681aTree-SHA512: 83e860407b230b6cdca59c0d74a486e52e7ea34d655d418ddc115418551a61665cad8f1d6182858d8ed6d7d72a8558e595e61644efed6c704de8a0b6960a0df2
Native language bindings for BDK
The workspace in this repository creates the libbdkffi multi-language library for the Rust-based
bdk library from the Bitcoin Dev Kit project. The bdk-ffi-bindgen package builds a tool for
generating the actual language binding code used to access the libbdkffi library.
Each supported language and the platform(s) it's packaged for has its own directory. The Rust code in this project is in the bdk-ffi directory and is a wrapper around the bdk library to expose its APIs in a uniform way using the mozilla/uniffi-rs bindings generator for each supported target language.
Supported target languages and platforms
The below directories (a separate repository in the case of bdk-swift) include instructions for using, building, and publishing the native language binding for bdk supported by this project.
| Language | Platform | Published Package | Building Documentation | API Docs |
|---|---|---|---|---|
| Kotlin | JVM | bdk-jvm (Maven Central) | Readme bdk-jvm | Kotlin JVM API Docs |
| Kotlin | Android | bdk-android (Maven Central) | Readme bdk-android | Android API Docs |
| Swift | iOS, macOS | bdk-swift (GitHub) | Readme bdk-swift | |
| Python | linux, macOS, Windows | bdk-python (PyPI) | Readme bdk-python |
Language bindings generator tool
Use the bdk-ffi-bindgen tool to generate language binding code for the above supported languages.
To run bdk-ffi-bindgen and see the available options use the command:
cargo run -p bdk-ffi-bindgen -- --help
Contributing
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.udlfile with newdictionary
For pass by reference values
- Create wrapper rust struct/impl with only fields that are
Sync + Send - Update mapping
bdk.udlfile 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
Using the libraries
bdk-android
// build.gradle.kts
repositories {
mavenCentral()
}
dependencies {
implementation("org.bitcoindevkit:bdk-android:<version>")
}
bdk-jvm
// build.gradle.kts
repositories {
mavenCentral()
}
dependencies {
implementation("org.bitcoindevkit:bdk-jvm:<version>")
}
Note: We also publish snapshot versions of bdk-jvm and bdk-android. See the specific readmes for instructions on how to use those.
bdk-python
pip3 install bdkpython
bdk-swift
Add bdk-swift to your dependencies in XCode.
Developing language bindings using uniffi-rs
If you are interested in better understanding the base structure we use here in order to build your own Rust-to-Kotlin/Swift/Python language bindings, check out the uniffi-bindings-template repository. We maintain it as an example and starting point for other projects that wish to leverage the tech stack used in producing the BDK language bindings.
Verifying Signatures
Both libraries and all their corresponding artifacts are signed with a PGP key you can find in the root of this repository. To verify the signatures follow the below steps:
- Import the PGP key in your keyring.
# Navigate to the root of the repository and import the ./PGP-BDK-BINDINGS.asc public key
gpg --import ./PGP-BDK-BINDINGS.asc
# Alternatively, you can import the key directly from a public key server
gpg --keyserver keyserver.ubuntu.com --receive-key 2768C43E8803C6A3
# Verify that the correct key was imported
gpg --list-keys
# You should see the below output
pub ed25519 2022-08-31 [SC]
88AD93AC4589FD090FF3B8D12768C43E8803C6A3
uid [ unknown] bitcoindevkit-bindings <bindings@bitcoindevkit.org>
sub cv25519 2022-08-31 [E]
- Download the binary artifacts and corresponding signature files.
- from bdk-jvm
bdk-jvm-<version>.jarbdk-jvm-<version>.jar.asc
- from bdk-android
bdk-android-<version>.aarbdk-android-<version>.aar.asc
- Verify the signatures.
gpg --verify bdk-jvm-<version>.jar.asc
gpg --verify bdk-android-<version>.aar.asc
# you should see a "Good signature" result
gpg: Good signature from "bitcoindevkit-bindings <bindings@bitcoindevkit.org>" [unknown]
PGP Metadata
Full key ID: 88AD 93AC 4589 FD09 0FF3 B8D1 2768 C43E 8803 C6A3
Fingerprint: 2768C43E8803C6A3
Name: bitcoindevkit-bindings
Email: bindings@bitcoindevkit.org
Thanks
This project is made possible thanks to the wonderful work by the mozilla/uniffi-rs team.