Skip to content

Add UniFFI Kotlin bindings for payjoin-ffi - #1869

Merged
chavic merged 6 commits into
payjoin:masterfrom
ram0verflow:kotlin-bindings-pr
Sep 13, 2026
Merged

Add UniFFI Kotlin bindings for payjoin-ffi#1869
chavic merged 6 commits into
payjoin:masterfrom
ram0verflow:kotlin-bindings-pr

Conversation

@ram0verflow

Copy link
Copy Markdown
Contributor
Pull Request Checklist

Please confirm the following before requesting review:

What

UniFFI Kotlin/JVM bindings for payjoin-ffi, plus a BIP77 v2 round-trip
integration test.

Layout matches python/csharp:

  • payjoin-ffi/kotlin/scripts/generate_bindings.sh
  • payjoin-ffi/kotlin/contrib/test.sh
  • PAYJOIN_FFI_FEATURES (default _test-utils; empty string is passed
    through) and PAYJOIN_FFI_PROFILE (default devtarget/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 Disposable and AutoCloseable, so
close() drops the Rust handle. Payjoin also exports protocol close() on
ReceiverPendingFallback, SenderPendingFallback, and the four JSON
session 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 keep close.

Integration test

IntegrationTests.kt drives a full BIP77 v2 round trip, sender and
receiver, against the in-process directory, OHTTP relay, and a real
bitcoind. Under the kotlin nix shell, BITCOIND_EXE comes from nixpkgs
and BITCOIND_SKIP_DOWNLOAD=1. Outside the shell, corepc-node may
download Bitcoin Core into a temp regtest dir.

On Linux, v2ToV2Payjoin completes in about 4s.

TestHttp trusts only the directory's rcgen cert and proxies through the
OHTTP relay.

Wrapper pin

Gradle 9.1.0 wrapper is pinned with distributionSha256Sum.
validateDistributionUrl only 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's
tag 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)

  • No ktfmt / treefmt registration for .kt
  • No Windows CI (same as python/dart/javascript)

Disclosure

This PR was written with Cursor Cloud Agent (Grok 4.6).

  • Code: Kotlin Gradle project, generate/test scripts, nix kotlin
    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).
  • PR body: AI-drafted (this text).

Disclosure: co-authored by Cursor Grok 4.6

@chavic

chavic commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

@ram0verflow Thanks, I'll take a look today

@chavic
chavic requested review from chavic and removed request for DanGould, benalleng and spacebear21 September 10, 2026 14:30
@coveralls

coveralls commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 34760182247

Coverage remained the same at 86.646%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 16549
Covered Lines: 14339
Line Coverage: 86.65%
Coverage Strength: 341.7 hits per line

💛 - Coveralls

@chavic

chavic commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

@ram0verflow it looks like you're hitting an unrelated probelm, that's fixed on master, you want to rebase

@chavic chavic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments below.

Comment thread payjoin-ffi/kotlin/build.gradle.kts
Comment thread payjoin-ffi/kotlin/src/test/kotlin/org/payjoindevkit/UriTests.kt Outdated
Comment thread payjoin-ffi/kotlin/CONTRIBUTING.md Outdated

@caarloshenriq caarloshenriq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread payjoin-ffi/kotlin/CONTRIBUTING.md Outdated
Comment thread payjoin-ffi/kotlin/README.md Outdated
Comment thread payjoin-ffi/kotlin/build.gradle.kts Outdated
@ram0verflow

Copy link
Copy Markdown
Contributor Author

will fix and update

@chavic chavic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments on the tests.

Comment thread payjoin-ffi/kotlin/src/test/kotlin/org/payjoindevkit/UriTests.kt Outdated
Comment thread payjoin-ffi/kotlin/src/test/kotlin/org/payjoindevkit/ValidationTests.kt Outdated

@chavic chavic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments.

Comment thread payjoin-ffi/kotlin/scripts/generate_bindings.sh Outdated
Comment thread payjoin-ffi/kotlin/src/test/kotlin/org/payjoindevkit/IntegrationTests.kt Outdated
Comment thread payjoin-ffi/kotlin/build.gradle.kts Outdated
Comment thread .github/workflows/kotlin.yml
ram0verflow and others added 4 commits September 12, 2026 09:46
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.
Honor CARGO_TARGET_DIR, load the OS-native library, and assert
percent-encoded URIs, overflow variants, and persister close via Rust.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread payjoin-ffi/kotlin/scripts/generate_bindings.sh Outdated
Honor CARGO_TARGET_DIR and [build] target-dir instead of assuming ../target.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread payjoin-ffi/kotlin/scripts/generate_bindings.sh Outdated
Comment thread payjoin-ffi/kotlin/scripts/generate_bindings.sh Outdated
Use the compiler-artifact filename so generate follows target-dir,
CARGO_BUILD_TARGET, and custom profiles.
@ram0verflow

Copy link
Copy Markdown
Contributor Author

updated

@chavic chavic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK

@chavic
chavic merged commit 83a33c8 into payjoin:master Sep 13, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants