Skip to content

[chore] SDK examples: Java v3.1.0 audit#2544

Open
ElliotFriend wants to merge 4 commits into
mainfrom
chore/sdk-examples-java-3.1.0-audit
Open

[chore] SDK examples: Java v3.1.0 audit#2544
ElliotFriend wants to merge 4 commits into
mainfrom
chore/sdk-examples-java-3.1.0-audit

Conversation

@ElliotFriend

Copy link
Copy Markdown
Contributor

Updating the Java code examples to the most up-to-date version of the SDK available (v3.1.0 at time of writing)

ElliotFriend and others added 2 commits July 1, 2026 16:05
Standing-correctness audit against java-stellar-sdk 3.1.0. The 1.0.0
package/builder reorg left several examples using classes and builders
that no longer exist at the referenced locations (verified against the
3.1.0 source tree). Import package root is unchanged (`org.stellar.sdk`);
only the moved classes and the removed nested builders were updated.

- invoke-contract-tx-sdk.mdx & stellar-transaction.mdx: exceptions moved
  to `org.stellar.sdk.exception.*`, `InvokeHostFunctionOperation` to
  `org.stellar.sdk.operations.*`; `SorobanRpcErrorResponse` was renamed
  to `SorobanRpcException` (in `org.stellar.sdk.exception`). Updated the
  imports and the `throws` clauses.
- control-asset-access.mdx: `Transaction.Builder` -> `TransactionBuilder`
  (which requires `setBaseFee`/`setTimeout`); nested
  `SetOptionsOperation.Builder().setSetFlags(...)` -> Lombok
  `SetOptionsOperation.builder().setFlags(...)`; imported the operation
  from `org.stellar.sdk.operations`.
- create-account.mdx: nested `CreateAccountOperation.Builder(id, "5")`
  -> `CreateAccountOperation.builder().destination(id)
  .startingBalance(new BigDecimal("5"))`; `Asset.createNonNative` ->
  `Asset.createNonNativeAsset`; added the operations and BigDecimal
  imports.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
….1.0

Follow-up to the java-stellar-sdk 3.1.0 audit: this file's five Java
snippets still used the pre-1.0.0 API (verified against the 3.1.0
source tree).

- `new Transaction.Builder(acct, net)` -> `new TransactionBuilder(...)`,
  which requires an explicit base fee/timeout, so added
  `.setBaseFee(Transaction.MIN_BASE_FEE)` (and `.setTimeout` where the
  runnable snippets lacked it).
- Nested operation builders replaced with Lombok `builder()`:
  `ChangeTrustOperation` (asset is now `ChangeTrustAsset`, limit is
  `BigDecimal`), `PaymentOperation` (amount is `BigDecimal`),
  `SetOptionsOperation` (`setMasterKeyWeight` -> `masterKeyWeight`).
- Per-operation source: `.setSourceAccount(id)` -> `.sourceAccount(id)`.
- `SetTrustLineFlagsOperation` was renamed `SetTrustlineFlagsOperation`;
  the removed `.setAuthorized(true)` convenience is now
  `.setFlags(EnumSet.of(TrustLineFlags.AUTHORIZED_FLAG))`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 2, 2026 13:49
@ElliotFriend ElliotFriend requested a review from Shaptic July 2, 2026 13:50

Copilot AI 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.

Pull request overview

Updates Stellar documentation Java snippets to align with java-stellar-sdk v3.1.0 APIs (notably the newer TransactionBuilder / *.builder() patterns) so readers can copy/paste examples against the current SDK.

Changes:

  • Migrated classic transaction examples from new Transaction.Builder(...) / new *Operation.Builder(...) to new TransactionBuilder(...) and *Operation.builder().
  • Updated Soroban examples to use the newer exception packages (org.stellar.sdk.exception.*) and operation package (org.stellar.sdk.operations.*).
  • Adjusted some examples to use BigDecimal-based amount/balance setters.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docs/tokens/how-to-issue-an-asset.mdx Updates asset issuance examples to v3.1.0 builder APIs (trustlines, payments, flags, set options).
docs/tokens/control-asset-access.mdx Updates authorization/flags example to TransactionBuilder + SetOptionsOperation.builder() and adds base fee/timeout.
docs/learn/fundamentals/contract-development/contract-interactions/stellar-transaction.mdx Updates Soroban Java imports/throws to new exception + operation packages.
docs/build/guides/transactions/invoke-contract-tx-sdk.mdx Updates Soroban Java imports/throws to new exception + operation packages.
docs/build/guides/transactions/create-account.mdx Updates CreateAccount + asset helper usage for v3.1.0 (builder API + createNonNativeAsset).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/build/guides/transactions/create-account.mdx Outdated
Comment thread docs/tokens/control-asset-access.mdx
Comment thread docs/tokens/how-to-issue-an-asset.mdx Outdated
@stellar-jenkins-ci

Copy link
Copy Markdown

ElliotFriend and others added 2 commits July 2, 2026 09:01
Addresses review feedback: this file was missed in the initial audit and
still used the pre-1.0.0 API. Migrated the SetOptions/home-domain snippet:
`new Transaction.Builder(...)` -> `new TransactionBuilder(...)` (with the
now-required base fee/timeout), and nested
`new SetOptionsOperation.Builder().setHomeDomain(...)` -> Lombok
`SetOptionsOperation.builder().homeDomain(...)`.

Verified via a full docs/ sweep that no other Java example still uses the
old Transaction.Builder / *Operation.Builder / setSourceAccount API.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- create-account.mdx: `Asset.createNonNativeAsset(...)` returns
  `org.stellar.sdk.Asset`, and USDC is a 4-char code, so the
  `AssetTypeCreditAlphaNum12` declaration was both wrong and wouldn't
  compile (narrowing from `Asset`). Typed the variable as `Asset`, which
  is also what the `getTrustlineBalance` helper accepts.
- how-to-issue-an-asset.mdx: the PaymentOperation "chaining" short-hand
  left `addOperation(...)` unclosed and the operation un-built; closed
  the operation with `.build()` and balanced the parentheses.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@stellar-jenkins-ci

Copy link
Copy Markdown

@overcat overcat 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.

LGTM

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.

3 participants