Dart flutter client#286
Draft
leonardocustodio wants to merge 6 commits into
Draft
Conversation
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.
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.
WIP