Skip to content

feat(ffi): cost estimation + file/data-map API symmetry (V2-584 A+B)#207

Merged
Nic-dorman merged 3 commits into
mainfrom
feat/ffi-cost-estimation
Jul 9, 2026
Merged

feat(ffi): cost estimation + file/data-map API symmetry (V2-584 A+B)#207
Nic-dorman merged 3 commits into
mainfrom
feat/ffi-cost-estimation

Conversation

@Nic-dorman

Copy link
Copy Markdown
Collaborator

Expands the mobile FFI surface within what the WithAutonomi network actually supports. Part of V2-584 (parent V2-580 mobile-SDK readiness).

Scope note: V2-584 originally also listed registers/pointers/scratchpad/vault/GraphEntry and directories. Those are Maidsafe autonomi concepts and do not exist in the WithAutonomi network (verified by grep of ant-client 7255f5b) — dropped from the ticket, not deferred. This PR is the real, achievable surface: cost estimation + symmetry gaps. Streaming was left as a docs-only concern (files already stream; only the byte APIs load full Vec<u8>).

A — Cost estimation

  • Client.estimate_file_cost(path, payment_mode) -> CostEstimate bridging ant-core's existing estimate_upload_cost (no wallet, samples chunk addresses, ~seconds).
  • New CostEstimate record with a confidence field (priced_sample / verified_all_already_stored / all_samples_already_stored_incomplete) so consumers never present a best-effort "0" as guaranteed-free.

B — API symmetry gaps

  • file_upload_private — private counterpart of file_upload_public (returns the hex data map); new FilePutPrivateResult.
  • data_map_store / data_map_fetch — publish an existing private data map as a public chunk and back, so a private upload becomes a shareable public address without re-uploading.
  • prepare_file_upload_with_progress — surfaces the encrypting/quoting phases prepare_file_upload runs silently, reusing the existing progress bridge. File-only (ant-core has no data-prepare progress variant).

Verification

  • cargo build / clippy --all-targets -D warnings / fmt --check / test all green.
  • UniFFI Swift + Kotlin bindings regenerate with all new methods/types on both platforms.
  • Both demo apps (ant-mobile-ios / ant-mobile-android) were refactored onto the file-path upload flow against a local build of this branch and build green, exercising estimate_file_cost + prepare_file_upload end-to-end at compile time.

🤖 Generated with Claude Code

Nic and others added 2 commits July 9, 2026 08:56
Bridge ant-core's existing estimate_upload_cost through the FFI so the
mobile SDK can preview upload cost before preparing/paying. No wallet
required (~seconds), safe to call ahead of prepare_file_upload in the
external-signer flow.

- New CostEstimate uniffi Record (file_size, chunk_count,
  storage_cost_atto, estimated_gas_cost_wei, payment_mode, confidence).
- Client::estimate_file_cost(path, payment_mode), mirroring
  file_upload_public's path+mode handling.
- format_cost_confidence helper with stable snake_case strings so
  callers can tell a genuinely-free "0" from a best-effort "0" guess.

Part of V2-584 (item A). Swift/Kotlin bindings regenerate cleanly;
build/clippy(-D)/fmt/test green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Fill the obvious holes in the current FFI surface so the mobile SDK is
symmetric across public/private and prepare paths:

- file_upload_private: the private counterpart of file_upload_public,
  returning the serialized data map (hex) instead of publishing it — the
  file analog of data_put_private. New FilePutPrivateResult record.
- data_map_store / data_map_fetch: publish an existing private data map
  as a public chunk (and the inverse), so a private upload can become a
  shareable public address without re-uploading the data.
- prepare_file_upload_with_progress: surfaces the "encrypting"/"quoting"
  phases that prepare_file_upload runs silently, reusing the existing
  upload_progress_bridge. File-only — ant-core has no data-prepare
  progress variant.

Part of V2-584 (item B). Swift/Kotlin bindings regenerate cleanly;
build/clippy(-D)/fmt/test green.

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

dirvine commented Jul 9, 2026

Copy link
Copy Markdown

Hermes review

I reviewed PR #207 (811ee693e8cb86be80cb52e998726ba72ca65a72) against main.

Verdict: no blocking code issues found. The new FFI methods build and regenerate into both Swift and Kotlin, and the data-map hex guard is applied consistently on the new data_map_store path.

Verified locally from ffi/rust:

  • cargo fmt -p ant-ffi -- --check — pass
  • cargo test -p ant-ffi --no-fail-fast — pass, 8/8 unit tests
  • cargo clippy -p ant-ffi --all-targets -- -D warnings — pass
  • cargo doc --locked --no-deps -p ant-ffi — pass
  • cargo build --release -p ant-ffi — pass
  • cargo build --release --bin uniffi-bindgen — pass
  • Swift/Kotlin binding generation — pass; confirmed generated APIs for estimateFileCost, fileUploadPrivate, dataMapStore, dataMapFetch, prepareFileUploadWithProgress, CostEstimate, and FilePutPrivateResult.

Non-blocking notes:

  • ffi/rust/ant-ffi/src/lib.rs:234-238 still says the external-signer FFI does not surface "encrypting"/"quoting" progress and that prepare-with-progress is a future follow-up. This PR now adds prepare_file_upload_with_progress, so that doc comment should be updated before or soon after merge.
  • data_map_store avoids re-uploading the underlying file/data chunks, but it still stores/pays for the serialized DataMap chunk unless already stored. Worth making explicit for mobile callers if this is intended outside the Rust-wallet path.
  • estimate_file_cost mirrors the current core contract: it estimates file data chunks and explicitly excludes the extra public DataMap chunk. That is fine, but callers using it before public upload should not present it as the total guaranteed public-publish cost.
  • Generated Swift/Kotlin docs preserve Rust intra-doc links / snake_case names such as [`Self::data_get_private`]. Not a binding blocker, but native mobile docs would be clearer with binding-neutral prose.
  • ffi/README.md appears stale relative to the generated API surface; it still lists old/static method names and omits these new methods. Not a blocker for this PR, but worth tidying to avoid misleading mobile consumers.

I did not approve/merge; leaving this as an advisory review/comment.

All doc-only, no behavior change:
- ProgressUpdate: the "encrypting"/"quoting" upload phases ARE now surfaced
  (via prepare_file_upload_with_progress) — corrected the stale "not
  currently surfaced / future follow-up" note.
- data_map_store: state that it stores/pays for the serialized data-map
  chunk (unless already stored) and so needs a wallet-backed client.
- estimate_file_cost: note it prices data chunks only and excludes the
  extra public data-map chunk — not the guaranteed total public-publish cost.
- Make the new methods' doc comments binding-neutral: drop Rust
  `[`Self::x`]` intra-doc links that leak verbatim into Swift/Kotlin docs.
- ffi/README.md API Surface: rewrite the stale/wrong table (it listed
  phantom dir_*/*_cost/data_get/data_put/init() methods) to the real
  surface + note the network is immutable-only.

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

Copy link
Copy Markdown
Collaborator Author

Thanks @dirvine — all five notes addressed in 5fea1e0 (doc-only, no behavior change):

  1. ProgressUpdate doc — corrected: the "encrypting"/"quoting" upload phases are now surfaced via prepare_file_upload_with_progress; dropped the stale "not surfaced / future follow-up" wording.
  2. data_map_store — now states it stores/pays for the serialized data-map chunk unless already stored, and that this needs a wallet-backed client (an unpaid chunk store fails in external-signer mode).
  3. estimate_file_cost — documents that it prices data chunks only and excludes the extra public data-map chunk, so it's not the guaranteed total public-publish cost.
  4. Binding-neutral docs — removed the Rust [Self::x] intra-doc links from the new methods so Swift/Kotlin docs don't carry Rust link syntax / snake_case identifiers.
  5. ffi/README.md — rewrote the API Surface table. It was not just stale but listed phantom methods (dir_*, *_cost, data_get/data_put, init()); replaced with the real surface + a note that the network is immutable-only (no registers/pointers/directories).

fmt --check / clippy -D / build / doc --no-deps all still green.

@Nic-dorman
Nic-dorman merged commit f699c3b into main Jul 9, 2026
1 check passed
@Nic-dorman
Nic-dorman deleted the feat/ffi-cost-estimation branch July 9, 2026 09:06
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.

2 participants