diff --git a/.editorconfig b/.editorconfig index f8d19dc..4f1c5cd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,6 +17,9 @@ indent_size = 4 [*.kt] indent_size = 4 +[*.gradle] +indent_size = 4 + [tests/**/*.rs] charset = utf-8 end_of_line = unset diff --git a/README.md b/README.md index 4ace128..f9fd29c 100644 --- a/README.md +++ b/README.md @@ -42,3 +42,14 @@ See the [UniFFI User Guide](https://mozilla.github.io/uniffi-rs/) 1. Use `build.sh` script (TODO do it all in build.rs instead) 2. Create tests in `bindings/bdk-kotlin` and/or `bindings/bdk-swift` 3. Use `test.sh` to run all bindings tests + +### Run kotlin demo application + +We have a kotlin demo console application which uses bdk. +It uses stdin for inputs and can be run from gradle. + +```sh +cd bindings/bdk-kotlin +./gradlew :demo:run +``` + diff --git a/bindings/bdk-kotlin/demo/build.gradle b/bindings/bdk-kotlin/demo/build.gradle new file mode 100644 index 0000000..191a764 --- /dev/null +++ b/bindings/bdk-kotlin/demo/build.gradle @@ -0,0 +1,36 @@ +plugins { + id 'org.jetbrains.kotlin.jvm' + id 'application' +} + +group = 'uniffi.bdk' +version = '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation 'org.jetbrains.kotlin:kotlin-test' + implementation project(':jvm') +} + +test { + useJUnit() +} + +compileKotlin { + kotlinOptions.jvmTarget = '1.8' +} + +compileTestKotlin { + kotlinOptions.jvmTarget = '1.8' +} + +application { + mainClassName = 'MainKt' +} + +run { + standardInput = System.in +} diff --git a/bindings/bdk-kotlin/demo/gradle/wrapper/gradle-wrapper.jar b/bindings/bdk-kotlin/demo/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7454180 Binary files /dev/null and b/bindings/bdk-kotlin/demo/gradle/wrapper/gradle-wrapper.jar differ diff --git a/bindings/bdk-kotlin/demo/gradle/wrapper/gradle-wrapper.properties b/bindings/bdk-kotlin/demo/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..69a9715 --- /dev/null +++ b/bindings/bdk-kotlin/demo/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/bindings/bdk-kotlin/demo/src/main/kotlin/Main.kt b/bindings/bdk-kotlin/demo/src/main/kotlin/Main.kt new file mode 100644 index 0000000..bca1c3a --- /dev/null +++ b/bindings/bdk-kotlin/demo/src/main/kotlin/Main.kt @@ -0,0 +1,25 @@ +import uniffi.bdk.* + +class LogProgress: BdkProgress { + override fun update(progress: Float, message: String? ) { + println(progress); + println(message); + } +} + +fun main(args: Array) { + val descriptor = + "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)"; + val db = DatabaseConfig.Memory("") + val client = BlockchainConfig.Electrum(ElectrumConfig("ssl://electrum.blockstream.info:60002", null, 5u, null, 100u)) + val wallet = OnlineWallet(descriptor, Network.TESTNET, db, client) + val address = wallet.getNewAddress() + println("Please send satoshis to wallet address: $address") + readLine() + println("Syncing...") + wallet.sync(LogProgress(), null) + val balance = wallet.getBalance() + println("New wallet balance: $balance") + println("Press any key to exit") + readLine() +} diff --git a/bindings/bdk-kotlin/settings.gradle b/bindings/bdk-kotlin/settings.gradle index c23d1d9..ac610be 100644 --- a/bindings/bdk-kotlin/settings.gradle +++ b/bindings/bdk-kotlin/settings.gradle @@ -1,4 +1,4 @@ rootProject.name = 'bdk-kotlin' -include ':jvm' //, ':android', ':test-fixtures' +include ':jvm', ':demo' //, ':android', ':test-fixtures' diff --git a/build.sh b/build.sh index eaeb2cd..b67fff0 100755 --- a/build.sh +++ b/build.sh @@ -32,11 +32,13 @@ copy_lib_kotlin() { echo -n "darwin " mkdir -p bindings/bdk-kotlin/jvm/src/main/resources/darwin-x86-64 cp target/debug/libuniffi_bdk.dylib bindings/bdk-kotlin/jvm/src/main/resources/darwin-x86-64 + cp target/debug/libuniffi_bdk.dylib bindings/bdk-kotlin/demo/src/main/resources/darwin-x86-64 ;; "Linux") echo -n "linux " mkdir -p bindings/bdk-kotlin/jvm/src/main/resources/linux-x86-64 cp target/debug/libuniffi_bdk.so bindings/bdk-kotlin/jvm/src/main/resources/linux-x86-64 + cp target/debug/libuniffi_bdk.so bindings/bdk-kotlin/demo/src/main/resources/linux-x86-64 ;; esac echo "libs to kotlin sub-project"