Add UniFFI Kotlin bindings for payjoin-ffi - #1869
Conversation
|
@ram0verflow Thanks, I'll take a look today |
Coverage Report for CI Build 34260940347Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage remained the same at 86.64%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
|
@ram0verflow it looks like you're hitting an unrelated probelm, that's fixed on master, you want to rebase |
|
|
||
| tasks.test { | ||
| useJUnitPlatform() | ||
| val libDir = layout.projectDirectory.dir("lib").asFile |
There was a problem hiding this comment.
We should add inputs.file(native) here. Otherwise changing the Rust library without changing the generated Kotlin leaves the tests UP-TO-DATE. Confirmed with an isolated Gradle 9.1 repro.
| @Test | ||
| fun missingAmountShouldBeOk() { | ||
| val uri = "bitcoin:12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX?pj=https://testnet.demo.btcpayserver.org/BTC/pj" | ||
| assertNotNull(Url.parse(uri)) |
There was a problem hiding this comment.
Should this be Uri.parse()? Same on line 36. Url.parse() accepts invalid Bitcoin addresses, so we're not testing the URI validation here.
| Protocol `close` is renamed to `closeSession` only in `[bindings.kotlin.rename]` in | ||
| `payjoin-ffi/uniffi.toml`, so it does not clash with `AutoCloseable.close()`. | ||
|
|
||
| A nix `.#kotlin` shell is not in the flake yet. Use a local JDK 21+ and the Gradle wrapper. |
There was a problem hiding this comment.
This is outdated or mismatched. The PR adds .#kotlin. The README also says nix doesn't supply bitcoind, but the shell sets BITCOIND_EXE. Let's update both.
caarloshenriq
left a comment
There was a problem hiding this comment.
Concept ACK.
Kotlin/JVM bindings alongside the other four is a good addition, and the layout mirrors python/csharp closely enough that it should be easy to keep in sync
| Protocol `close` is renamed to `closeSession` only in `[bindings.kotlin.rename]` in | ||
| `payjoin-ffi/uniffi.toml`, so it does not clash with `AutoCloseable.close()`. | ||
|
|
||
| A nix `.#kotlin` shell is not in the flake yet. Use a local JDK 21+ and the Gradle wrapper. |
There was a problem hiding this comment.
That same commit adds kotlinDevShell and CI runs nix develop .#kotlin.
|
|
||
| Or `bash ./contrib/test.sh` from this directory (uses `Cargo-recent.lock`). | ||
|
|
||
| `./gradlew test` includes a v2↔v2 integration test that starts a local payjoin directory, OHTTP relay, and bitcoind. Bitcoin Core is downloaded by corepc-node (`29_0`) on first run; it is not supplied by nix. |
There was a problem hiding this comment.
Bitcoin Core is downloaded by corepc-node (
29_0) on first run; it is not supplied by nix.
Inside .#kotlin it is: BITCOIND_EXE points at nixpkgs bitcoind and
BITCOIND_SKIP_DOWNLOAD=1. Reads correct if scoped to "outside the nix shell".
| @@ -0,0 +1,38 @@ | |||
| plugins { | |||
| kotlin("jvm") version "2.1.20" | |||
There was a problem hiding this comment.
against the Gradle 9.1.0 wrapper pinned in gradle/wrapper/gradle-wrapper.properties: KGP 2.1.20's compatibility table tops out in the 8.x range, so 9.1.0 is outside the versions it is tested against. It may well build clean today, but a KGP bump (2.2.x) would put the pair back in the supported matrix and cost nothing here, since nothing is published yet.
There was a problem hiding this comment.
Checked the KGP compatibility table. 2.2.x still caps at Gradle 8.14, so it wouldn't cover the 9.1.0 wrapper. 2.3.0 and 2.3.10 cap at 9.0.0. The first KGP that covers 9.1.0 is 2.3.20 (7.6.3–9.3.0).
|
will fix and update |
Generate with in-tree uniffi-bindgen --language kotlin, siloed like Python (no extra cargo feature). Rename protocol close to closeSession in Kotlin only so AutoCloseable still works. Pin the Gradle 9.1.0 wrapper with distributionSha256Sum; validateDistributionUrl only checks the download URL. Add a kotlin nix dev shell (JDK 21, MSRV, bitcoind) and run CI inside it, matching the other language bindings. Unit tests cover URIs, persistence, cancel, and validation.
Drive a full BIP77 round trip against the in-process directory, OHTTP relay, and bitcoind, mirroring the Python suite's RPC sequence and assertions. TestHttp trusts only the self-signed rcgen directory cert so HTTPS through the relay succeeds in the JVM. Parse bitcoind RPC responses with kotlinx-serialization-json.
a991880 to
df8922e
Compare
Pull Request Checklist
Please confirm the following before requesting review:
AI
in the body of this PR.
What
UniFFI Kotlin/JVM bindings for
payjoin-ffi, plus a BIP77 v2 round-tripintegration test.
Layout matches python/csharp:
payjoin-ffi/kotlin/scripts/generate_bindings.shpayjoin-ffi/kotlin/contrib/test.shPAYJOIN_FFI_FEATURES(default_test-utils; empty string is passedthrough) and
PAYJOIN_FFI_PROFILE(defaultdev→target/debug)Generated sources are not committed (gitignored under
kotlin/src/main/kotlin/org/). Generate is a build step.CI runs inside
nix develop .#kotlin(JDK 21, MSRV, nixpkgs bitcoind),matching csharp/python/dart.
Unit tests (15) cover URIs, persistence, cancel, and validation — the
same count as the Python unit suite. The second commit adds the v2
integration test (16 Gradle tests on HEAD).
Why
[bindings.kotlin.rename]Generated UniFFI objects implement
DisposableandAutoCloseable, soclose()drops the Rust handle. Payjoin also exports protocolclose()onReceiverPendingFallback,SenderPendingFallback, and the four JSONsession persister traits. Kotlin cannot overload on return type.
The table is Kotlin-only. It maps those protocol methods to
closeSession(). No Rust API change. Other language bindings keepclose.Integration test
IntegrationTests.ktdrives a full BIP77 v2 round trip, sender andreceiver, against the in-process directory, OHTTP relay, and a real
bitcoind. Under the kotlin nix shell,
BITCOIND_EXEcomes from nixpkgsand
BITCOIND_SKIP_DOWNLOAD=1. Outside the shell,corepc-nodemaydownload Bitcoin Core into a temp regtest dir.
On Linux,
v2ToV2Payjoincompletes in about 4s.TestHttptrusts only the directory's rcgen cert and proxies through theOHTTP relay.
Wrapper pin
Gradle 9.1.0 wrapper is pinned with
distributionSha256Sum.validateDistributionUrlonly checks the URL.Release / publish
Not published anywhere. No pack, Maven, signing, or attestation jobs.
The workflow does not trigger on
payjoin-kotlin-*tags. python.yml'stag trigger runs wheel build, PyPI publish, and GitHub release assets.
Until Kotlin has something to publish, a tag trigger would only re-run
tests.
Follow-ups (out of this PR)
.ktDisclosure
This PR was written with Cursor Cloud Agent (Grok 4.6).
shell, CI workflow, unit tests, and the v2 integration test were
AI-generated and then hand-reviewed against the Python suite and a
known-good round trip (~4s).
Disclosure: co-authored by Cursor Grok 4.6