Skip to content

Dart flutter client#286

Draft
leonardocustodio wants to merge 6 commits into
mainfrom
dart-flutter-client
Draft

Dart flutter client#286
leonardocustodio wants to merge 6 commits into
mainfrom
dart-flutter-client

Conversation

@leonardocustodio

@leonardocustodio leonardocustodio commented Jul 17, 2026

Copy link
Copy Markdown
Member

WIP

Introduce a Dart client for the TrUAPI protocol, generated from the same
rustdoc IR as the TypeScript client so the Rust crate stays the single
source of truth.

- truapi-codegen: new `dart.rs` emitter (sibling of `ts.rs`) wired via
  `--dart-output`; emits types/wire_table/client/index.dart (14 service
  clients, ~64 methods, ~360 types). Versioned-wrapper selection, sealed
  classes for mixed enums, Dart enums for unit-only, generic Component<P>,
  and the auto-handshake responder.
- dart/truapi: hand-written runtime — SCALE codec, sealed Result, Provider
  + transport (request correlation, Stream-based subscriptions, injectable
  handshake), and an in-memory loopback provider.
- Conformance: `truapi --example wire_vectors` emits golden vectors from
  parity_scale_codec; the Dart codecs are asserted byte-identical, and the
  generated client round-trips Ok/Err end-to-end over the loopback.
- Build/CI: `--dart-output` in scripts/codegen.sh, a `make dart` target, a
  `dart` CI job, and pubspec version sync. Design notes in
  docs/design/dart-flutter-support.md.
The Dart package now ships both sides of the protocol. Host applications
(e.g. a Flutter desktop host) implement the methods products call.

- truapi-codegen: `dart.rs` gains a host emitter behind `--dart-host-output`;
  generates host.dart with one typed handler interface per service, public
  build<Service>Entries, the TruapiHostHandlers interface, and
  createTruapiServer. Handlers receive/return the inner (selected-version)
  types and the generated entries handle versioned wire wrapping.
- dart/truapi: hand-written dispatcher runtime lib/src/host/host_server.dart
  (createHostServer, CallContext, SubscriptionFramePort, request/subscription
  entries, pending/active subscription state machine) and a host.dart barrel.
- Test: host_server_test.dart drives the generated client against the
  generated host over the loopback (request round-trip + subscription).
- Build: --dart-host-output added to scripts/codegen.sh and the CI dart job.
- Host reuses the client's generated types.dart, so it lives in the same
  package; exposed via package:truapi/host.dart.
Bootstrap a host implementation: `truapi-codegen --dart-host-scaffold-output`
(and `make dart-scaffold`) emit an editable `ScaffoldHostHandlers` that
implements every service method with `throw UnimplementedError(...)`, plus
heuristic notes on which services are backed by a light client (smoldart),
the wallet, or host-local state.

- truapi-codegen: `dart.rs` factors the host method signature into a shared
  helper and adds a scaffold emitter behind `--dart-host-scaffold-output`.
- dart/truapi/example/host_scaffold.dart: the generated starting point (all
  15 services, 64 methods), committed as an editable template.
- Makefile `dart-scaffold` target + README usage.
Products are web apps that use the TS/JS @parity/truapi client over the normal
web route, so the Dart package ships only the host.

- truapi-codegen: drop the Dart client emitter; `--dart-output` now writes only
  types.dart, wire_table.dart, and index.dart (consumed by the generated
  host.dart). Removed the now-dead `codec_version`/`arg_expr` plumbing.
- dart/truapi: remove the client runtime from transport.dart
  (createTransport/Transport/subscribeStream/Subscription/HandshakeResponder),
  keeping the shared Provider, frame codec, wire-id types, and
  SubscriptionInterrupted. `package:truapi/truapi.dart` is now the host barrel;
  `host.dart` is folded into it.
- Tests: drop the client transport + generated-client tests; rewrite the host
  dispatch test to drive the server with raw wire frames (no client).
- Docs: README/CLAUDE/design doc updated to host-only.

Verified: cargo build/test/fmt/clippy clean; dart analyze clean, 28 tests green.
`dart/truapi_smoldot` backs the host's chain-facing services with an
in-process smoldot light client, mapping the typed TrUAPI SCALE protocol
onto Polkadot JSON-RPC.

- `SmoldotChainHandlers` implements the generated `ChainHostHandlers`:
  `chainSpec_v1_*`, the `chainHead_v1_*` follow/operation engine
  (`followHeadSubscribe` streams typed events; operations correlate to
  their follow via `followSubscriptionId` == the follow call's
  `CallContext.requestId`), and `transaction_v1_*`.
- `SmoldotStatementStoreHandlers` implements `submit`/`subscribe` over a
  self-contained Substrate `sp_statement_store::Statement` SCALE codec,
  with host-side topic filtering; `createProof*` are unsupported (signing
  is the wallet's, not a light client's).
- `JsonRpcClient` correlates requests/subscriptions over a
  `smoldot_provider` `JsonRpcProvider`. `SmoldotChainBackend` adds one
  chain per genesis hash and exposes a client per chain.

Subscription streams use an explicit `StreamController` so `cancel()`
forwards cleanly to the underlying unsubscribe.

33 offline unit tests; a network-tagged integration test validates the
Chain handlers end-to-end against live Westend (`--run-skipped -t
network`). Plan/status tracked in docs/design/smoldot-provider.md.
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.

1 participant