Repository navigation
feat(tx3c): add the java-client template - #364
Merged
scarmuega merged 2 commits intoSep 27, 2026
Merged
Conversation
`tx3c codegen --template java-client` renders a standalone Maven project: `pom.xml`, `README.md`, and `src/main/java/land/tx3/generated/<protocol>/ <Protocol>Client.java`, laid out through templated output paths. The client wraps the runtime SDK's `Tx3Client`: it embeds one `TirEnvelope` per transaction and one `Profile` per profile, takes a typed `Profile` enum when the protocol declares profiles, exposes `with<Party>` binders over `withPartyUnchecked`, and builds each transaction's arguments statically through `argTagged`, so no TII, schema or `ParamType` reaches the consumer. The Java backend now spells that static construction. Every value declaration is `public` and carries a `toArgValue()` built from its shape: records and variant cases become `struct` with their constructor index, tuples `tuple`, lists and maps convert their elements (maps sorted by key, as the SDK's dynamic encoder does), and aliases become one-field wrapper records so the aliased value survives. Identifier characters Java forbids collapse to one underscore, which gives the protocol-named package segment. New helpers: `argValue <schema> <language> <expr> [<member>]` spells a parameter's tagged argument, `stringLiteral` escapes embedded text (joining chunks at runtime past the class-file constant limit), `indent` nests a rendered block, and `kebabCase` names the Maven artifact. CI compiles the rendered transfer and complex fixtures with Maven and runs a smoke consumer inside each rendered project. Until `land.tx3:tx3-sdk:0.15.0` is on Maven Central the check installs java-sdk commit d7a6dc4da56f73a7a47fe2e77444ad056885cfe7 as `0.15.0-SNAPSHOT` and selects it through the generated `tx3.sdk.version` property. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
scarmuega
marked this pull request as ready for review
September 27, 2026 13:11
Contributor
Author
|
Merge observed. Plan: Trellis will verify the human merge evidence, adopt the domain pin, and retire the plan. No further merge action is needed. |
Reconciles the java-client template with the swift-client template that landed in #365. Both added static argument construction to the codegen core in different shapes; the merge keeps main's `Encoding` model and `argValue`/`member` backend surface and ports the Java backend onto it: - `Backend::argument` spells from a member's `Encoding`; the shape-based `argument`/`accessor` pair and `Member::argument` are gone. Java overrides `member` for record accessors and keeps `sanitize` and `string_literal`. - `Backend::declares_aliases` (Java: true) tells component resolution that an alias is a wrapper record converting itself, so a reference to an alias component spells `.toArgValue()` instead of the target's encoding. - The Java template calls main's `argValue <tii> <tx> <param> <lang> <expr>`. - Both templates are registered, listed in the CLI help and error, and in the CI codegen matrix and compile-check script. Rendered java-client and swift-client output is byte-identical to the committed goldens. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
scarmuega
marked this pull request as draft
September 27, 2026 13:59
scarmuega
marked this pull request as ready for review
September 27, 2026 14:15
scarmuega
deleted the
work/work-de755479921262fc570f0cd1b0b785cd01fec550
branch
September 27, 2026 14:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the built-in
java-clienttemplate to tx3c (tx3c codegen --template java-client), per decisions 0015 and 0016 and the design inputs bound inplans/lang-codegen-java-client.md.land.tx3.generated:<protocol>-client:0.0.0-SNAPSHOT, depending onland.tx3:tx3-sdk:0.15.0):pom.xml,README.md, andsrc/main/java/land/tx3/generated/<protocol>/<Protocol>Client.javathrough templated output paths. The client wrapsTx3ClientviaTx3ClientBuilder.fromParts, embeds one namedTirEnvelopeper transaction and oneProfileper profile, takes a typedProfileenum when profiles exist, exposeswith<Party>binders throughwithPartyUnchecked, and each transaction method sends its params throughargTaggedwith statically builtArgValues. No TII, schema orParamTypereaches the generated source. SDK types are spelled fully qualified so a protocol type named like an SDK type (the edge fixture'sAddress) cannot shadow them.publicand carries atoArgValue()built from its shape (records/variant cases →structwith the constructor index, tuples →tuple, lists/maps convert their elements, maps sorted by key like the SDK's dynamic encoder). Aliases become one-field wrapper records (record Amount(java.math.BigInteger value)) instead of empty records, so the aliased value survives. Characters Java forbids in identifiers collapse to one_, which is what gives the protocol-named package segment via themethodrole.argValue <schema> <language> <expr> [<member>],stringLiteral <text> <language>(chunked withString.joinbeyond the 65535-byte class-file constant limit),indent <text> <columns>,kebabCase.java-clientjoins the codegen compile matrix. The script compiles the rendered transfer and complex fixtures withmvn verifyand then runs a smoke consumer (.github/scripts/java-client-smoke/<fixture>/Smoke.java) inside the rendered project, so the client runs with no source TII present. Untilland.tx3:tx3-sdk:0.15.0is on Maven Central the check installs java-sdk commitd7a6dc4da56f73a7a47fe2e77444ad056885cfe7as0.15.0-SNAPSHOTand selects it with-Dtx3.sdk.version; the block to remove afterwards is marked in the script.Golden output changes to review
The Java backend change re-blesses the existing Java goldens under
tests/codegen/expected/custom/{java,compat-java,templated-paths}: declarations gainpublicandtoArgValue(), andOpaquebecomesrecord Opaque(land.tx3.sdk.ArgValue value). New goldens underexpected/java-client/cover transfer (two profiles, three parties), complex (one profile, every schema kind) and edge (no profiles, no parties, keyword transactionclass, builtin-named component).Verification
Local, Java 21 (Homebrew OpenJDK 21.0.12.1) against java-sdk
d7a6dc4installed as0.15.0-SNAPSHOT:cargo fmt --all -- --check,cargo clippy --workspace --all-targets --all-features --locked -- -D warnings,cargo test -p tx3c --locked(43 unit tests + golden corpus) pass;git diff --checkclean.bash .github/scripts/codegen-compile-check.sh java-client target/debug/tx3cpasses end to end: both fixtures render,mvn -B -ntp verifysucceeds, and both smoke consumers run (constructors for two profiles / one profile, typed party binders, typed transaction methods, variant constructor index and record field count asserted ontoArgValue()).mvn verify(not part of CI, matching the other languages).Notes
toArgValue(): they are argument bags and the client sends each member as its own tagged argument.null-typed or unknown-typed parameter is typedland.tx3.sdk.ArgValueand passed through, following the approved fallback mapping.🤖 Generated with Claude Code