-
Notifications
You must be signed in to change notification settings - Fork 126
Add Kotlin JVM bindings #1797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Kotlin JVM bindings #1797
Changes from all commits
8094d8f
319d477
4ed61f7
6357afb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| plugins { | ||
| kotlin("jvm") version "1.9.24" apply false | ||
| } |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this different then the one we're already using for our bindings. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| plugins { | ||
| kotlin("jvm") | ||
| `java-library` | ||
| `maven-publish` | ||
| } | ||
|
|
||
| java { | ||
| sourceCompatibility = JavaVersion.VERSION_17 | ||
| targetCompatibility = JavaVersion.VERSION_17 | ||
| withSourcesJar() | ||
| withJavadocJar() | ||
| } | ||
|
|
||
| kotlin { | ||
| jvmToolchain(17) | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation("net.java.dev.jna:jna:5.14.0") | ||
| implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.24") | ||
| implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1") | ||
|
|
||
| testImplementation("org.junit.jupiter:junit-jupiter:5.10.2") | ||
| testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.8.1") | ||
| } | ||
|
|
||
| sourceSets { | ||
| main { | ||
| kotlin.srcDirs("src/main/kotlin") | ||
| resources.srcDirs("src/main/resources") | ||
| } | ||
| } | ||
|
|
||
| tasks.test { | ||
| useJUnitPlatform() | ||
| testLogging { | ||
| events("passed", "skipped", "failed") | ||
| showStandardStreams = true | ||
| } | ||
| systemProperty("junit.jupiter.execution.timeout.default", "60s") | ||
| jvmArgs("-Djava.library.path=${project.projectDir}/src/main/resources") | ||
| } | ||
|
|
||
| tasks.processResources { | ||
| duplicatesStrategy = DuplicatesStrategy.INCLUDE | ||
| } | ||
|
|
||
| publishing { | ||
| publications { | ||
| create<MavenPublication>("maven") { | ||
| groupId = project.property("GROUP") as String | ||
| artifactId = "cdk-jvm" | ||
| version = project.property("VERSION_NAME") as String | ||
| from(components["java"]) | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package org.cashudevkit | ||
|
|
||
| import kotlinx.coroutines.runBlocking | ||
| import org.junit.jupiter.api.AfterEach | ||
| import org.junit.jupiter.api.Assertions.* | ||
| import org.junit.jupiter.api.BeforeEach | ||
| import org.junit.jupiter.api.Test | ||
| import java.io.File | ||
|
|
||
| class WalletTest { | ||
|
|
||
| private lateinit var wallet: Wallet | ||
| private lateinit var dbFile: File | ||
|
|
||
| @BeforeEach | ||
| fun setUp() { | ||
| dbFile = File.createTempFile("cdk_test_", ".sqlite") | ||
| val mnemonic = generateMnemonic() | ||
| wallet = Wallet( | ||
| mintUrl = "https://testnut.cashudevkit.org", | ||
| unit = CurrencyUnit.Sat, | ||
| mnemonic = mnemonic, | ||
| store = WalletStore.Sqlite(path = dbFile.absolutePath), | ||
| config = WalletConfig(targetProofCount = null), | ||
| ) | ||
| } | ||
|
|
||
| @AfterEach | ||
| fun tearDown() { | ||
| wallet.close() | ||
| dbFile.delete() | ||
| } | ||
|
|
||
| @Test | ||
| fun `initial balance is zero`() = runBlocking { | ||
| val balance = wallet.totalBalance() | ||
| assertEquals(0UL, balance.value) | ||
| } | ||
|
|
||
| @Test | ||
| fun `mint flow`() = runBlocking { | ||
| val quote = wallet.mintQuote( | ||
| paymentMethod = PaymentMethod.Bolt11, | ||
| amount = Amount(value = 100UL), | ||
| description = null, | ||
| extra = null, | ||
| ) | ||
|
|
||
| assertTrue(quote.id.isNotEmpty()) | ||
| assertTrue(quote.request.isNotEmpty()) | ||
|
|
||
| // testnut pays quotes automatically, wait for payment to settle | ||
| kotlinx.coroutines.delay(3000) | ||
|
|
||
| val proofs = wallet.mint( | ||
| quoteId = quote.id, | ||
| amountSplitTarget = SplitTarget.None, | ||
| spendingConditions = null, | ||
| ) | ||
|
|
||
| assertTrue(proofs.isNotEmpty()) | ||
|
|
||
| val balance = wallet.totalBalance() | ||
| assertEquals(100UL, balance.value) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 | ||
| org.gradle.parallel=true | ||
| org.gradle.caching=true | ||
| kotlin.code.style=official | ||
|
|
||
| GROUP=org.cashudevkit | ||
| VERSION_NAME=0.16.0-rc.2 |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we gitignore this?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like its also committed in cdk-kotlin so maybe we need it. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip | ||
| networkTimeout=10000 | ||
| validateDistributionUrl=true | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists |
Uh oh!
There was an error while loading. Please reload this page.