capi icon indicating copy to clipboard operation
capi copied to clipboard

feat: abstract over consumption of different RPC flavors

Open harrysolovay opened this issue 2 years ago • 0 comments

Heavily WIP

Introduces Consumers, which provide a standard layer on top of different RPC APIs (the current and the experimental). This will allow us to decouple the fluent API from RPC specifics (and therefore ease the transition to Smoldot). The end DX may look as follows.

import { ParachainRune } from "@capi/parachain"
import { ExperimentalRpc, SmoldotConnection } from "capi"
import { parachainSpec, relayChainSpec } from "./chain_specs.ts"

const api = ParachainRune.from(
  new ExperimentalRpc(
    SmoldotConnection.bind({ parachainSpec, relayChainSpec }),
    signal,
  ),
)

The ExperimentalRpc (a Consumer) wraps the Connect itself. The consumer is then passed into the chain rune factory, so that the chain rune can operate with an RPC-unspecific API.


For now, the ExperimentalRpc API accepts an additional argument: a non-smoldot Connect. This is necessary for retrieving historical block info. It seems the archive-prefixed methods of the new JSON RPC spec are yet to be implemented for any chains (?). Seems a bit far-fetched... but a GitHub-wide search revealed no such clues.

harrysolovay avatar Jul 14 '23 12:07 harrysolovay