paritytech / capi

[WIP] A framework for crafting interactions with Substrate chains
https://docs.capi.dev
Apache License 2.0
105 stars 10 forks source link

feat: abstract over consumption of different RPC flavors #1177

Open harrysolovay opened 1 year ago

harrysolovay commented 1 year ago

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.