Skip to content

Simplify the TrUAPI spec surface #127

Description

@filvecchiato

Problem

Adding a TrUAPI function requires touching three places:

  1. rust/crates/truapi/src/api/*.rs — trait method with &self, CallContext, async_trait
  2. rust/crates/truapi/src/v01/*.rs — concrete types
  3. rust/crates/truapi/src/versioned/*.rs — versioned_type! wrappers

The trait signatures mix protocol information with runtime concerns, and there's no way to tell request-response from subscription by reading the code.

Proposal

Simplify the spec surface to carry only protocol information:

#[wire(request_id = 12)]
fn host_derive_entropy(key: Vec) -> Result<Entropy, DeriveEntropyError>

#[wire(request_id = 120)]
fn remote_preimage_lookup_subscribe(key: PreimageKey) -> Subscription<Option, PreimageLookupError>

  • Result<T, E> = request-response
  • Subscription<T, E> = subscription (marker type for codegen)
  • No &self, CallContext, async_trait, CallError — generated by codegen for the runtime
  • Wire IDs stay explicit and manually assigned (stable across renames, required by other implementors)

Auto-generated from the spec

  • Runtime boilerplate (&self, CallContext, async_trait, CallError)
  • Versioned wrappers (versioned_type! enums)
  • TS client (SCALE codecs, Result wrapping, Observable for subscriptions)
  • Explorer/playground metadata

Migration

  1. Prototype the simplified surface for one group
  2. Extend codegen to produce the current /api traits and /versioned wrappers from it
  3. Migrate remaining groups
  4. Add contributor guide: "How to add a new TrUAPI function"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions