Add demo application in kotlin
This commit is contained in:
parent
85d803afcf
commit
3f620ecf19
@ -17,6 +17,9 @@ indent_size = 4
|
|||||||
[*.kt]
|
[*.kt]
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.gradle]
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
[tests/**/*.rs]
|
[tests/**/*.rs]
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
end_of_line = unset
|
end_of_line = unset
|
||||||
|
11
README.md
11
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)
|
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`
|
2. Create tests in `bindings/bdk-kotlin` and/or `bindings/bdk-swift`
|
||||||
3. Use `test.sh` to run all bindings tests
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
36
bindings/bdk-kotlin/demo/build.gradle
Normal file
36
bindings/bdk-kotlin/demo/build.gradle
Normal 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
|
||||||
|
}
|
BIN
bindings/bdk-kotlin/demo/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
bindings/bdk-kotlin/demo/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
5
bindings/bdk-kotlin/demo/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
5
bindings/bdk-kotlin/demo/gradle/wrapper/gradle-wrapper.properties
vendored
Normal 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
|
25
bindings/bdk-kotlin/demo/src/main/kotlin/Main.kt
Normal file
25
bindings/bdk-kotlin/demo/src/main/kotlin/Main.kt
Normal 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()
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
rootProject.name = 'bdk-kotlin'
|
rootProject.name = 'bdk-kotlin'
|
||||||
|
|
||||||
include ':jvm' //, ':android', ':test-fixtures'
|
include ':jvm', ':demo' //, ':android', ':test-fixtures'
|
||||||
|
|
||||||
|
2
build.sh
2
build.sh
@ -32,11 +32,13 @@ copy_lib_kotlin() {
|
|||||||
echo -n "darwin "
|
echo -n "darwin "
|
||||||
mkdir -p bindings/bdk-kotlin/jvm/src/main/resources/darwin-x86-64
|
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/jvm/src/main/resources/darwin-x86-64
|
||||||
|
cp target/debug/libuniffi_bdk.dylib bindings/bdk-kotlin/demo/src/main/resources/darwin-x86-64
|
||||||
;;
|
;;
|
||||||
"Linux")
|
"Linux")
|
||||||
echo -n "linux "
|
echo -n "linux "
|
||||||
mkdir -p bindings/bdk-kotlin/jvm/src/main/resources/linux-x86-64
|
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/jvm/src/main/resources/linux-x86-64
|
||||||
|
cp target/debug/libuniffi_bdk.so bindings/bdk-kotlin/demo/src/main/resources/linux-x86-64
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
echo "libs to kotlin sub-project"
|
echo "libs to kotlin sub-project"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user