Add demo application in kotlin

This commit is contained in:
Sudarsan Balaji 2021-10-16 14:45:32 +05:30
parent 85d803afcf
commit 3f620ecf19
8 changed files with 83 additions and 1 deletions

View File

@ -17,6 +17,9 @@ indent_size = 4
[*.kt]
indent_size = 4
[*.gradle]
indent_size = 4
[tests/**/*.rs]
charset = utf-8
end_of_line = unset

View File

@ -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
```

View File

@ -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
}

Binary file not shown.

View File

@ -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

View File

@ -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<String>) {
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()
}

View File

@ -1,4 +1,4 @@
rootProject.name = 'bdk-kotlin'
include ':jvm' //, ':android', ':test-fixtures'
include ':jvm', ':demo' //, ':android', ':test-fixtures'

View File

@ -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"