2021-12-14 08:24:41 -08:00
# bdk-kotlin
2021-10-30 00:27:02 +05:30
2021-12-14 08:24:41 -08:00
This project builds .jar and .aar packages for the `jvm` and `android` platforms that provide
[Kotlin] language bindings for the [`bdk` ] library. The Kotlin language bindings are created by the
[`bdk-ffi` ] project which is included as a git submodule of this repository.
2021-10-30 00:27:02 +05:30
2021-12-14 08:24:41 -08:00
## How to Use
2021-10-30 00:27:02 +05:30
2021-12-14 08:24:41 -08:00
To use the Kotlin language bindings for [`bdk` ] in your `jvm` or `android` project add the
following to your gradle dependencies:
```groovy
repositories {
mavenCentral()
}
2021-10-30 00:27:02 +05:30
2021-12-14 08:24:41 -08:00
dependencies {
// for jvm
2022-02-03 20:02:28 -06:00
implementation 'org.bitcoindevkit:bdk-jvm:0.3.2'
2021-12-14 08:24:41 -08:00
// OR for android
2022-02-03 20:02:28 -06:00
implementation 'org.bitcoindevkit:bdk-android:0.3.2'
2021-12-14 08:24:41 -08:00
}
2021-11-06 01:30:36 +05:30
2021-12-14 08:24:41 -08:00
```
2021-11-06 01:30:36 +05:30
2021-12-14 08:24:41 -08:00
You may then import and use the `org.bitcoindevkit` library in your Kotlin code. For example:
2021-11-06 01:30:36 +05:30
2021-12-14 08:24:41 -08:00
```kotlin
import org.bitcoindevkit.*
2021-11-06 01:30:36 +05:30
2021-12-14 08:24:41 -08:00
// ...
2021-11-06 01:30:36 +05:30
2021-12-14 08:24:41 -08:00
val descriptor = "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)"
val db = DatabaseConfig.Memory("")
2021-11-06 01:30:36 +05:30
2021-12-14 08:24:41 -08:00
val client =
BlockchainConfig.Electrum(
ElectrumConfig("ssl://electrum.blockstream.info:60002", null, 5u, null, 10u)
)
val wallet = OnlineWallet(descriptor, null, Network.TESTNET, db, client)
val newAddress = wallet.getNewAddress()
```
2021-11-06 01:30:36 +05:30
2021-12-21 14:25:15 -08:00
### Example Projects
#### `bdk-android`
2022-02-07 16:30:13 -05:00
* [Devkit Wallet ](https://github.com/thunderbiscuit/devkit-wallet )
* [Padawan Wallet ](https://github.com/thunderbiscuit/padawan-wallet )
2021-12-21 14:25:15 -08:00
#### `bdk-jvm`
2022-02-07 16:30:13 -05:00
* [Tatooine Faucet ](https://github.com/thunderbiscuit/tatooine )
2021-12-21 14:25:15 -08:00
2022-01-28 23:34:33 -06:00
### How to build
2021-10-30 00:27:02 +05:30
2022-01-24 18:22:53 +00:00
1. Clone this repository and init and update it's [`bdk-ffi` ] submodule.
```shell
git clone https://github.com/bitcoindevkit/bdk-kotlin
git submodule update --init
```
1. Follow the "General" bdk-ffi ["Getting Started (Developer)"] instructions.
2022-01-28 23:34:33 -06:00
1. If building on MacOS install required intel and m1 jvm targets
```sh
rustup target add x86_64-apple-darwin aarch64-apple-darwin
```
2021-10-30 00:27:02 +05:30
1. Install required targets
```sh
2021-12-14 08:24:41 -08:00
rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi i686-linux-android
2021-10-30 00:27:02 +05:30
```
2022-01-02 20:25:18 +01:00
1. Install `uniffi-bindgen`
```sh
2022-02-22 21:48:18 -08:00
cargo install uniffi_bindgen --version 0.16.0
2022-01-02 20:25:18 +01:00
```
See the [UniFFI User Guide ](https://mozilla.github.io/uniffi-rs/ ) for more info
2021-10-30 00:27:02 +05:30
1. Install Android SDK and Build-Tools for API level 30+
2021-12-14 08:24:41 -08:00
1. Setup `$ANDROID_SDK_ROOT` and `$ANDROID_NDK_HOME` path variables (which are required by the
2022-01-24 18:19:17 +00:00
build scripts), for example (NDK major version 21 is required):
2021-12-14 08:24:41 -08:00
```shell
export ANDROID_SDK_ROOT=~/Android/Sdk
2022-01-24 18:19:17 +00:00
export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/21.< NDK_VERSION >
2021-10-30 00:27:02 +05:30
```
2021-12-14 08:24:41 -08:00
1. Build kotlin bindings
2021-10-30 00:27:02 +05:30
```sh
2021-12-14 08:24:41 -08:00
./build.sh
2021-10-30 00:27:02 +05:30
```
2022-01-28 23:34:33 -06:00
1. Start android emulator and run tests
```sh
./gradlew connectedAndroidTest
```
2021-10-16 14:45:32 +05:30
2021-12-21 14:25:15 -08:00
## How to publish
### Publish to your local maven repo
2021-12-14 08:24:41 -08:00
1. Set your `~/.gradle/gradle.properties` signing key values
```properties
signing.gnupg.keyName=< YOUR_GNUPG_ID >
signing.gnupg.passphrase=< YOUR_GNUPG_PASSPHRASE >
```
1. Publish
```shell
2021-12-18 10:45:08 -08:00
./gradlew :jvm:publishToMavenLocal
./gradlew :android:publishToMavenLocal
2021-12-14 08:24:41 -08:00
```
2021-12-21 14:25:15 -08:00
### Publish to maven central with [Gradle Nexus Publish Plugin] (project maintainers only)
2021-12-14 08:24:41 -08:00
1. Set your `~/.gradle/gradle.properties` signing key values and SONATYPE login
```properties
signing.gnupg.keyName=< YOUR_GNUPG_ID >
signing.gnupg.passphrase=< YOUR_GNUPG_PASSPHRASE >
ossrhUserName=< YOUR_SONATYPE_USERNAME >
ossrhPassword=< YOUR_SONATYPE_PASSWORD >
```
1. Publish
```shell
./gradlew :jvm:publishToSonatype closeAndReleaseSonatypeStagingRepository
./gradlew :android:publishToSonatype closeAndReleaseSonatypeStagingRepository
```
[Kotlin]: https://kotlinlang.org/
[Android Studio]: https://developer.android.com/studio/
[`bdk` ]: https://github.com/bitcoindevkit/bdk
[`bdk-ffi` ]: https://github.com/bitcoindevkit/bdk-ffi
["Getting Started (Developer)"]: https://github.com/bitcoindevkit/bdk-ffi#getting -started-developer
2021-12-18 10:45:08 -08:00
[Gradle Nexus Publish Plugin]: https://github.com/gradle-nexus/publish-plugin