Skip to content

fix(antd-kotlin): make put-response cost optional; ship missing gradle wrapper#77

Merged
Nic-dorman merged 1 commit into
mainfrom
fix/kotlin-dto-and-wrapper
May 14, 2026
Merged

fix(antd-kotlin): make put-response cost optional; ship missing gradle wrapper#77
Nic-dorman merged 1 commit into
mainfrom
fix/kotlin-dto-and-wrapper

Conversation

@Nic-dorman
Copy link
Copy Markdown
Collaborator

Fixes #69.

Two issues blocked antd-kotlin example 02 from running. Both fixed here because either one alone leaves the binding non-functional out of the box.

1. DataPutPublicDto deserialization failure

The example fataled on:

Caused by: kotlinx.serialization.MissingFieldException:
  Field 'cost' is required for type with serial name
  'com.autonomi.sdk.DataPutPublicDto', but it was missing
        at com.autonomi.sdk.AntdRestClient$dataPutPublic$$inlined$postJson$1.invokeSuspend(AntdRestClient.kt:284)

The daemon currently returns {address, chunks_stored, payment_mode_used} for PUT /v1/data/public — no cost field:

$ curl -s -X POST http://127.0.0.1:8082/v1/data/public \
       -H 'Content-Type: application/json' \
       -d '{"data":"SGVsbG8gd29ybGQ="}'
{"address":"5c0…666","chunks_stored":3,"payment_mode_used":"single"}

Make cost default to empty in DataPutPublicDto (and DataPutPrivateDto), mirroring how the PHP REST client falls back to '' and how the Python REST client uses .get(...) with implicit None. Non-breaking — PutResult.cost still ends up the same String type downstream.

2. Missing gradle wrapper files

antd-kotlin/ shipped gradle/wrapper/gradle-wrapper.properties but not gradlew or gradle/wrapper/gradle-wrapper.jar. The README tells users to run ./gradlew :examples:run --args=2, which gives:

bash: ./gradlew: No such file or directory

Add the wrapper script (executable) and the wrapper jar, copied from antd-java/. gradle-wrapper.jar is a checked-in binary in both antd-java/ and other JVM projects in this repo, so adding it here is consistent.

Test plan

Sample output

=== Example 02: Public Data ===
Estimate: 16 bytes in 3 chunks, storage 0 atto, gas 0 wei, mode single
Stored at address: 01b06330e4f4a8c565087e4087caabf860bdadbe96b7b8f0447493b0081c2335
Actual cost:  atto tokens
Retrieved: Hello, Autonomi network!
Public data round-trip OK!

(Actual cost blank for the same reason — daemon doesn't return it on this path. That's worth its own ticket if cost is supposed to be populated on PUT responses; the SDK-side change in this PR is correct either way since "optional with default" matches reality.)

…e wrapper

Two issues blocking antd-kotlin example 02 from running:

1) DataPutPublicDto deserialization failed:
   MissingFieldException: Field cost is required for type with serial name
   com.autonomi.sdk.DataPutPublicDto, but it was missing

   The daemon currently returns address, chunks_stored, payment_mode_used
   for PUT /v1/data/public, with no cost field. Make cost default to empty,
   mirroring how the PHP REST client falls back to empty string. Same for
   the DataPutPrivateDto sibling.

2) antd-kotlin/gradlew and antd-kotlin/gradle/wrapper/gradle-wrapper.jar
   were not committed - only gradle-wrapper.properties was. With the
   wrapper script absent, the README example invocation failed immediately
   with "No such file or directory". Add the wrapper files (copied from
   antd-java which shipped them correctly, modulo a missing executable bit).

Closes #69
@Nic-dorman Nic-dorman merged commit c411c79 into main May 14, 2026
@Nic-dorman Nic-dorman deleted the fix/kotlin-dto-and-wrapper branch May 14, 2026 11:03
Nic-dorman added a commit that referenced this pull request May 14, 2026
The Swift SDK is documented as macOS-only in `antd-swift/README.md`, but
in practice the swift.org Linux toolchain (6.0.x) builds and round-trips
against antd end-to-end after a small set of upstream-fixable patches.
This PR collects them and adds a snake-case-decoding fix for the cost
estimate that was hiding behind the "macOS-only" framing.

Verified end-to-end on Ubuntu 24.04 with Swift 6.0.3:
`swift build && swift run AntdExamples 2` → "Public data round-trip OK!"
with real `Estimate: 24 bytes in 3 chunks, storage 43945312500000000
atto, gas 150000000000000 wei, mode single`.

## Changes

### Package.swift — bump grpc-swift to 2.x

`grpc-swift-protobuf 1.x` requires Swift tools 6.0+, which conflicts
with the previous `from: "1.23.0"` pin on `grpc-swift` (which is on the
1.x line, requiring 5.x tooling). Bump `grpc-swift` to `2.0.0` and add
the new `grpc-swift-nio-transport` package — `GRPCNIOTransportHTTP2`
moved out of the main grpc-swift repo in 2.x.

### AntdRestClient.swift — three fixes

1. **`FoundationNetworking` import** — Linux builds split URLSession out
   of `Foundation` into a separate `FoundationNetworking` module.
   Guarded with `#if canImport(...)` so macOS/iOS are unaffected.
2. **PUT-response cost is optional** — daemon's `POST /v1/data/public`,
   `/v1/data/private`, `/v1/chunks` currently return `{address,
   chunks_stored, payment_mode_used}` without `cost`, so the previous
   `let cost: String` decoder fataled. Mirrors the antd-php / antd-py
   fallback to empty-string. Same shape addressed in #77 (kotlin) and
   the long-standing PHP/Python pattern.
3. **CostDTO snake_case decoding** — the bug hidden by today's e2e:
   `JSONDecoder.snakeCase` (which is `keyDecodingStrategy =
   .convertFromSnakeCase`) converts JSON `file_size` → expected Swift
   property `fileSize`. CostDTO had snake_case property names, so
   decoding silently nilled them out and `dataCost` / `fileCost` always
   returned zero for `fileSize`/`chunkCount`/`gas`/`mode`. Rename to
   camelCase so the decoder matches.

### Errors.swift — `override` keyword on subclass inits

Swift 6's stricter init resolution flagged the 9 error subclass
initializers as missing `override` against `AntdError.init(_:statusCode:)`.
Add the keyword.

### AntdExamples/Main.swift — Linux-safe minimal example

The previous bundled example used `SecRandomCopyBytes` from Apple's
`Security` framework (macOS-only) and had pre-existing arity bugs in
several of the per-example helper functions. Replace with a minimal
Linux-portable example 02 that exercises the public data round-trip and
exits non-zero on mismatch — enough for cross-SDK e2e validation. The
full example suite would be a separate restoration once
`SecRandomCopyBytes` is replaced and the arity bugs are fixed.

## Test plan

- [x] `cd antd-swift && swift build` clean on Ubuntu 24.04 with Swift
      6.0.3 (one cosmetic warning: `dependency 'grpc-swift' is not used
      by any target` — only the nio-transport sub-package is used)
- [x] `swift run AntdExamples 2` against a local devnet — round-trip OK,
      real estimate fields
- [x] Cross-SDK e2e harness: 15/15 SDKs pass, swift no longer skipped

## Companion PR

PR adding `swift run AntdExamples N` to the `ant dev example`
dispatcher (and removing the `skip_reason` that was auto-skipping
swift) is in #86. Either can land first; without the antd-swift
patches here, the dispatcher's swift adapter will fail at compile.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Nic-dorman added a commit that referenced this pull request May 14, 2026
Cuts v0.7.1 atop v0.7.0. Primarily refreshes the upstream `ant-core`
pin to the `ant-cli-v0.2.3` release tag (no API change for antd
consumers). Bundles a substantial round of cross-SDK example/build
fixes, dispatcher improvements, and CI/release workflow hardening.

## antd

- chore(antd): bump ant-core to v0.2.3 (#85)

## SDK example/build fixes

- fix(antd-php): use cost-estimate fields in example 02 (#74)
- fix(antd-elixir): print cost-estimate fields in examples (#75)
- fix(antd-lua): add missing discover module to rockspec (#76)
- fix(antd-kotlin): make put-response cost optional + ship gradle wrapper (#77)
- fix(antd-zig): pass payment_mode to dataPutPublic/dataPutPrivate (#79)
- fix(antd-java): make examples runnable via gradle :examples subproject (#80)
- fix(antd-zig): align stdlib API to declared 0.14.x minimum (#82)
- fix(antd-swift): port to Linux + populate cost-estimate fields (#87)

## ant-dev (developer CLI)

- fix(ant-dev): clean up orphan anvil/antnode and stale node identities on stop (#81)
- fix(ant-dev): tooling cluster — flag alias, sys.executable, anvil preflight, README (#83)
- feat(ant-dev): expand `ant dev example` to dispatch all 15 SDKs (#84)
- fix(ant-dev): dispatcher swift no-skip + lua LUA_PATH wrap (#86)
- feat(ant-dev): expose --preset flag on `ant dev start` (default: small) (#88)

## CI / release

- ci: authenticate arduino/setup-protoc on ci.yml too (#60)
- feat(release): publish antd-linux-arm64 artifact (#89)

## Validation

15/15 SDKs round-tripped end-to-end against a daemon built from this
commit on a Linux dev box (Ubuntu 24.04, 0.7.1 atop ant-core v0.2.3).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

antd-kotlin example 02 fails: DataPutPublicDto requires field 'cost' but daemon response omits it

1 participant