From 1eed72bac4d9f5a900c56fdab44b9f32cfd49c00 Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Wed, 8 Mar 2023 12:52:14 -0300 Subject: [PATCH 01/23] feat: add custom chain spec --- crypto/test_pairs.ts | 7 ++++ providers/frame/polkadot_dev.ts | 67 +++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/crypto/test_pairs.ts b/crypto/test_pairs.ts index 02e0a0437..06ce754c9 100644 --- a/crypto/test_pairs.ts +++ b/crypto/test_pairs.ts @@ -1,3 +1,4 @@ +import { Blake2_256 } from "./hashers.ts" import { decode } from "./hex.ts" import { Sr25519 } from "./Sr25519.ts" @@ -30,3 +31,9 @@ export const bobStash = pair( function pair(secret: string) { return Sr25519.fromSecret(decode(secret)) } + +export function testPair(userId: number) { + return Sr25519.fromSeed( + Blake2_256.hash(new TextEncoder().encode(`capi-test-user-${userId}`)), + ) +} diff --git a/providers/frame/polkadot_dev.ts b/providers/frame/polkadot_dev.ts index ca2cb47e0..989034686 100644 --- a/providers/frame/polkadot_dev.ts +++ b/providers/frame/polkadot_dev.ts @@ -1,3 +1,4 @@ +import { ss58, testPair } from "../../crypto/mod.ts" import * as $ from "../../deps/scale.ts" import { Env, PathInfo } from "../../server/mod.ts" import { getAvailable } from "../../util/port.ts" @@ -7,6 +8,15 @@ export interface PolkadotDevProviderProps { polkadotPath?: string } +const TEST_USER_COUNT = 1000 +const TEST_USER_INITIAL_FUNDS = 1000000000000000000 +const DEV_RUNTIME_PREFIXES = { + polkadot: 0, + kusama: 2, + westend: 42, + rococo: 42, +} as const + export class PolkadotDevProvider extends FrameBinProvider { constructor(env: Env, { polkadotPath }: PolkadotDevProviderProps = {}) { super(env, { @@ -17,14 +27,65 @@ export class PolkadotDevProvider extends FrameBinProvider { } async launch(pathInfo: PathInfo) { - const runtimeName = pathInfo.target + const runtimeName = pathInfo.target || "polkadot" $.assert($devRuntimeName, runtimeName) const port = getAvailable() - const args: string[] = ["--dev", "--ws-port", port.toString()] - if (runtimeName !== "polkadot") args.push(`--force-${runtimeName}`) + const chainSpec = await this.#getCustomChainSpec(runtimeName) + const args: string[] = ["--tmp", "--alice", "--ws-port", port.toString(), "--chain", chainSpec] + console.log({ args }) await this.runBin(args) return port } + + async #getCustomChainSpec( + runtimeName: "polkadot" | "kusama" | "westend" | "rococo", + ): Promise { + const buildSpecCmd = new Deno.Command( + this.bin, + { + args: [ + "build-spec", + "--disable-default-bootnode", + "--chain", + `${runtimeName}-dev`, + ], + }, + ) + const chainSpec = JSON.parse(new TextDecoder().decode((await buildSpecCmd.output()).stdout)) + const balances: any[] = chainSpec.genesis.runtime.balances.balances + for (let i = 0; i < TEST_USER_COUNT; i++) { + balances.push([ + ss58.encode(DEV_RUNTIME_PREFIXES[runtimeName], testPair(i).publicKey), + TEST_USER_INITIAL_FUNDS, + ]) + } + const customChainSpecPath = await Deno.makeTempFile({ + prefix: `custom-${runtimeName}-chain-spec`, + suffix: ".json", + }) + await Deno.writeTextFile(customChainSpecPath, JSON.stringify(chainSpec, undefined, 2)) + const buildSpecRawCmd = new Deno.Command( + this.bin, + { + args: [ + "build-spec", + "--disable-default-bootnode", + "--chain", + customChainSpecPath, + "--raw", + ], + }, + ) + const chainSpecRaw = JSON.parse( + new TextDecoder().decode((await buildSpecRawCmd.output()).stdout), + ) + const customChainSpecRawPath = await Deno.makeTempFile({ + prefix: `custom-${runtimeName}-chain-spec-raw`, + suffix: ".json", + }) + await Deno.writeTextFile(customChainSpecRawPath, JSON.stringify(chainSpecRaw, undefined, 2)) + return customChainSpecRawPath + } } const $devRuntimeName = $.literalUnion(["polkadot", "kusama", "westend", "rococo"]) From 96c726c467774d0f4e7bbfa4bceb2bf82a909c06 Mon Sep 17 00:00:00 2001 From: Matias Volpe Date: Wed, 8 Mar 2023 15:35:45 -0300 Subject: [PATCH 02/23] chore: remove console.log --- providers/frame/polkadot_dev.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/providers/frame/polkadot_dev.ts b/providers/frame/polkadot_dev.ts index 989034686..f80a7d825 100644 --- a/providers/frame/polkadot_dev.ts +++ b/providers/frame/polkadot_dev.ts @@ -32,7 +32,6 @@ export class PolkadotDevProvider extends FrameBinProvider { const port = getAvailable() const chainSpec = await this.#getCustomChainSpec(runtimeName) const args: string[] = ["--tmp", "--alice", "--ws-port", port.toString(), "--chain", chainSpec] - console.log({ args }) await this.runBin(args) return port } From 057f27a79799b127ed98f1ee292d82c9cf3554c8 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 15:53:41 -0500 Subject: [PATCH 03/23] update readme and update dprint md config --- CODE_OF_CONDUCT.md | 4 +- CONTRIBUTING.md | 74 ++++++++++++++++------- Readme.md | 93 +++++++++++++++++------------ docs/Types.md | 84 +++++++++++++++++++------- dprint.json | 4 ++ providers/frame/FrameBinProvider.ts | 1 + providers/frame/polkadot_dev.ts | 25 ++++---- rune/rune.md | 3 +- 8 files changed, 191 insertions(+), 97 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 420a0d6e9..a05b69125 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -60,8 +60,8 @@ representative at an online or offline event. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at -. -All complaints will be reviewed and investigated promptly and fairly. +. All complaints will be reviewed and investigated promptly and +fairly. All community leaders are obligated to respect the privacy and security of the reporter of any incident. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8528c37ae..dce5810e8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,30 +1,41 @@ # Contributing -When contributing to this repository, please check our open issues and whether there is already an issue related to your idea. Please first discuss the change you wish to make in a GitHub issue and wait for a reply from the maintainers of this repository before making a change. +When contributing to this repository, please check our open issues and whether +there is already an issue related to your idea. Please first discuss the change +you wish to make in a GitHub issue and wait for a reply from the maintainers of +this repository before making a change. -We have a [code of conduct](CODE_OF_CONDUCT.md); please follow it in all your interactions relating to the project. +We have a [code of conduct](CODE_OF_CONDUCT.md); please follow it in all your +interactions relating to the project. ## Environment setup ### Container environment setup -Develop locally using the [VSCode Remote Container](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension and [Docker](https://docs.docker.com/get-docker/). [![Open in Remote - Containers](https://img.shields.io/badge/Remote_--_Container-Open-blue?logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/paritytech/capi) +Develop locally using the +[VSCode Remote Container](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) +extension and [Docker](https://docs.docker.com/get-docker/). +[![Open in Remote - Containers](https://img.shields.io/badge/Remote_--_Container-Open-blue?logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/paritytech/capi) ### Local environment setup -To develop on your machine, install the following (and please submit issues if errors crop up) +To develop on your machine, install the following (and please submit issues if +errors crop up) - [Deno](https://deno.land/manual@v1.19.3/getting_started/installation) - [Docker](https://docs.docker.com/get-docker/) -- [NodeJS](https://nodejs.org/) (only necessary if you're going to run [the dnt task](./_/tasks/dnt.ts)) +- [NodeJS](https://nodejs.org/) (only necessary if you're going to run + [the dnt task](./_/tasks/dnt.ts)) - [dprint](https://dprint.dev/) ## Rules There are a few basic ground-rules for contributors: -1. **All modifications** must be made in a **pull-request** to solicit feedback from other contributors -2. Contributors should attempt to adhere to the prevailing [code-style](#code-style) +1. **All modifications** must be made in a **pull-request** to solicit feedback + from other contributors +2. Contributors should attempt to adhere to the prevailing + [code-style](#code-style) ## Pull requests @@ -34,25 +45,35 @@ There are a few basic ground-rules for contributors: :white_check_mark:   Have one approving review -:white_check_mark:   Have the PR title follow [conventional commit](https://www.conventionalcommits.org/) +:white_check_mark:   Have the PR title follow +[conventional commit](https://www.conventionalcommits.org/) **Ideally, a good pull request should:** :clock3:   Take less than 15 minutes to review -:open_book:   Have a meaningful description (describes the problem being solved) +:open_book:   Have a meaningful description (describes the problem being +solved) -:one:   Introduce one feature or solve one bug at a time, for which an open issue already exists. In case of a project wide refactoring, a larger PR is to be expected, but the reviewer should be more carefully guided through it +:one:   Introduce one feature or solve one bug at a time, for which an open +issue already exists. In case of a project wide refactoring, a larger PR is to +be expected, but the reviewer should be more carefully guided through it -:jigsaw:   Issues that seem too big for a PR that can be reviewed in 15 minutes or PRs that need to touch other issues should be discussed and probably split differently before starting any development +:jigsaw:   Issues that seem too big for a PR that can be reviewed in 15 +minutes or PRs that need to touch other issues should be discussed and probably +split differently before starting any development -:dart:   Handle renaming, moving files, linting and formatting separately (not alongside features or bug fixes) +:dart:   Handle renaming, moving files, linting and formatting separately +(not alongside features or bug fixes) :test_tube:   Add tests for new functionality -**Draft pull requests for early feedback are welcome and do not need to adhere to any guidelines.** +**Draft pull requests for early feedback are welcome and do not need to adhere +to any guidelines.** -When reviewing a pull request, the end-goal is to suggest useful changes to the author. Reviews should finish with approval unless there are issues that would result in: +When reviewing a pull request, the end-goal is to suggest useful changes to the +author. Reviews should finish with approval unless there are issues that would +result in: :x:   Buggy behavior @@ -60,21 +81,25 @@ When reviewing a pull request, the end-goal is to suggest useful changes to the :x:   Measurable performance issues -:x:   Feature reduction (i.e. it removes some aspect of functionality that a significant minority of users rely on) +:x:   Feature reduction (i.e. it removes some aspect of functionality that +a significant minority of users rely on) -:x:   Uselessness (i.e. it does not strictly add a feature or fix a known issue) +:x:   Uselessness (i.e. it does not strictly add a feature or fix a known +issue) :x:   Disabling a compiler feature to introduce code that wouldn't compile ## Code style -We use the following tools to enforce linting rules, formatting and spell checking +We use the following tools to enforce linting rules, formatting and spell +checking - [`deno lint`](https://deno.land/manual/tools/linter) - [`dprint`](https://dprint.dev/) - [`cspell`](https://cspell.org/) -We encourage adding the [recommended](.vscode/extensions.json) (or similar) extensions to your IDE. +We encourage adding the [recommended](.vscode/extensions.json) (or similar) +extensions to your IDE. To run a project wide check you can use: @@ -90,15 +115,20 @@ Declaring formal releases remains the prerogative of the project maintainer(s). ## License -By contributing to project, you agree that your contributions will be licensed under its [Apache license](LICENSE). +By contributing to project, you agree that your contributions will be licensed +under its [Apache license](LICENSE). ## Changes to this arrangement -This is an experiment and feedback is welcome! This document may also be subject to pull-requests or changes by contributors where you believe you have something valuable to add or change. +This is an experiment and feedback is welcome! This document may also be subject +to pull-requests or changes by contributors where you believe you have something +valuable to add or change. ## Heritage These contributing guidelines are modified from -- the "Substrate Project" guidelines https://github.com/paritytech/substrate/blob/master/docs/CONTRIBUTING.adoc -- the "Substrate Contracts UI" guidelines https://github.com/paritytech/contracts-ui/blob/master/CONTRIBUTING.md +- the "Substrate Project" guidelines + https://github.com/paritytech/substrate/blob/master/docs/CONTRIBUTING.adoc +- the "Substrate Contracts UI" guidelines + https://github.com/paritytech/contracts-ui/blob/master/CONTRIBUTING.md diff --git a/Readme.md b/Readme.md index cac749cf6..022c277a1 100644 --- a/Readme.md +++ b/Readme.md @@ -1,77 +1,94 @@ # Capi -> Capi is a work in progress. The documentation may not reflect the current implementation. **Expect a stable release and proper documentation in early 2023**. +> Capi is a work in progress. The documentation may not reflect the current +> implementation. **Expect a stable release and proper documentation in early +> 2023**. -Capi is a declarative, TypeScript-first toolkit for crafting interactions with Substrate-based chains. It consists of [FRAME](https://docs.substrate.io/reference/glossary/#frame) utilities, a functional effect system (Rune) and a fluent API, which facilitates multistep, multichain interactions without compromising either performance or safety. +Capi is a framework for crafting interactions with Substrate chains. It consists +of a development server and fluent API, which facilitates multistep, multichain +interactions without compromising either performance or ease of use. - [Examples →](./examples)
SHOW ME THE CODE -- [API Reference →](https://deno.land/x/capi/mod.ts)
A generated API reference, based on type signatures and in-source comments. -- [Type Conversion Guide →](./docs/Types.md)
Guide for Capi's conversion of types from Rust to TypeScript +- [Docs →](https://docs.capi.dev)
Guides for Capi developers and + pattern library developers +- [API Reference →](https://deno.land/x/capi/mod.ts)
A generated API + reference, based on type signatures and TSDocs. ## At a Glance -Run the local server. +Create an import map with the specifier(s) corresponding to your provider and +chain discovery value (in this case a WebSocket URL). + +`import_map.json` + +```json +{ + "imports": { + "polkadot/": "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/" + } +} +``` + +Run the Capi development server. ```sh deno run -A https://deno.land/x/capi/main.ts ``` -Then, open your IDE and import pallet-corresponding modules from the local server. +Then, open your editor and import bindings from the local server. ```ts -import { System } from "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/mod.ts" +import { System } from "polkadot/mod.ts" -const key = System.Account.keys().first() +const key = System.Account + .keyPage(1) + .access(0) + .unhandle(undefined) -const value = System.Account.entry(key) +const value = System.Account.value(key) console.log(await value.run()) ``` -### Import Mapping +## Running Examples -For simplicity, we recommend aliasing import specifiers via import maps. +Within a fresh clone of the repository... -`import_map.json` - -```json -{ - "imports": { - "#polkadot/": "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/" - } -} -``` - -```diff -- import { System } from "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/mod.ts" -+ import { System } from "#polkadot/mod.ts" -``` - -## Examples - -See [the `examples/` directory](./examples). + ```sh -git clone https://github.com/partitytech/capi -cd capi -deno task run codegen # host the server locally and cache all codegen -deno task run examples/.ts +deno task capi -- examples/.ts ``` -## The Thesis +## Rationale -In a likely future of specialized, interoperable chains, developers will need to make use of on-chain programs to satisfy varying use cases; the expertise required to interact with these on-chain programs is currently greater than that which _should_ be expected of app developers. Does this mean that app developers must forgo integrating with this blossoming infrastructure? We think not; **the open source community can use Capi to abstract over the atomics of the on-chain world**. An interaction spanning several chains and dozens of methods can be described with a single effect. +In a likely future of specialized, interoperable chains, developers will need to +make use of on-chain programs to satisfy varying use cases; the expertise +required to interact with these on-chain programs is currently greater than that +which _should_ be expected of app developers. Does this mean that app developers +must forgo integrating with this blossoming infrastructure? We think not; **the +open source community can use Capi to abstract over the atomics of the on-chain +world**. An interaction spanning several chains and dozens of methods can be +described with a single Rune[^1]. -As you read through this documentation, please consider use cases over which you might like to abstract; if you wish to add your use case to [Capi's standard library](effects), please [submit an issue](https://github.com/paritytech/capi/issues/new). +As you read through this documentation, please consider use cases over which you +might like to abstract; if you wish to add your use case to +[Capi's standard library](patterns), please +[submit an issue](https://github.com/paritytech/capi/issues/new?title=pattern%20idea:%20). ## Code of Conduct -Everyone interacting in this repo is expected to follow the [code of conduct](CODE_OF_CONDUCT.md). +Everyone interacting in this repo is expected to follow the +[code of conduct](CODE_OF_CONDUCT.md). ## Contributing -Contributions are welcome and appreciated! Check out the [contributing guide](CONTRIBUTING.md) before you dive in. +Contributions are welcome and appreciated! Check out the +[contributing guide](CONTRIBUTING.md) before you dive in. ## License Capi is [Apache licensed](LICENSE). + +[^1]: Rune is the unit of composition with which we model Capi programs. See +[docs/basics/rune.md](docs/basics/rune.md). diff --git a/docs/Types.md b/docs/Types.md index 68618146a..5133ed6b8 100644 --- a/docs/Types.md +++ b/docs/Types.md @@ -1,8 +1,26 @@ # Types -The types of the on-chain world are declared in a given [Substrate](https://substrate.io/)-based chain's (Rust) source code. While many types may remain consistent across chains, many may differ. On one chain, `AccountData` may be defined with fields describing fungible assets; on another (hypothetical) chain, perhaps `AccountData` references non-fungible assets, reputation, linked accounts or something else entirely. Although [FRAME](https://docs.substrate.io/reference/glossary/#frame) certainly helps to standardize chain properties, those properties can be customized to the extent that we cannot make assumptions regarding shapes of data across chains. Additionally, types can change upon [runtime upgrades](https://docs.substrate.io/build/upgrade-the-runtime/); your assumptions about the shape of a type may become invalid; to interact with these highly-dynamic on-chain environments––and to do so from a JavaScript environment––poses inherent difficulty. We JS developers must (A) think in terms of Rust data types and (B) keep a lookout for breaking changes to chain runtimes. This document does not provide a silver-bullet solution to this complexity, but it should provide the background necessary for you to address types for your specific use cases. - -If you just want to see how Rust types are transformed by Capi, [skip to the conversion table](#rust-⬌-typescript). +The types of the on-chain world are declared in a given +[Substrate](https://substrate.io/)-based chain's (Rust) source code. While many +types may remain consistent across chains, many may differ. On one chain, +`AccountData` may be defined with fields describing fungible assets; on another +(hypothetical) chain, perhaps `AccountData` references non-fungible assets, +reputation, linked accounts or something else entirely. Although +[FRAME](https://docs.substrate.io/reference/glossary/#frame) certainly helps to +standardize chain properties, those properties can be customized to the extent +that we cannot make assumptions regarding shapes of data across chains. +Additionally, types can change upon +[runtime upgrades](https://docs.substrate.io/build/upgrade-the-runtime/); your +assumptions about the shape of a type may become invalid; to interact with these +highly-dynamic on-chain environments––and to do so from a JavaScript +environment––poses inherent difficulty. We JS developers must (A) think in terms +of Rust data types and (B) keep a lookout for breaking changes to chain +runtimes. This document does not provide a silver-bullet solution to this +complexity, but it should provide the background necessary for you to address +types for your specific use cases. + +If you just want to see how Rust types are transformed by Capi, +[skip to the conversion table](#rust-⬌-typescript). ## Learning About Types @@ -12,7 +30,8 @@ Let's cover how to learn about a chain's types/properties. ### FRAME Metadata -Every FRAME chain exposes metadata about its types and capabilities. This metadata is called the "FRAME Metadata." Let's retrieve and inspect it. +Every FRAME chain exposes metadata about its types and capabilities. This +metadata is called the "FRAME Metadata." Let's retrieve and inspect it. ```ts import { client } from "http://localhost:4646/frame/wss/rpc.polkadot.io/@v0.9.36/mod.ts" @@ -20,7 +39,8 @@ import { client } from "http://localhost:4646/frame/wss/rpc.polkadot.io/@v0.9.36 > To run the Capi dev server, run `deno run -A https://deno.land/x/capi/main.ts` -Let's connect to Polkadot and fetch the chain's metadata for the present highest block. +Let's connect to Polkadot and fetch the chain's metadata for the present highest +block. ```ts // ... @@ -30,9 +50,15 @@ const metadata = await C.metadata(client)() console.log(await metadata.run()) ``` -If we index into `metadata.pallets`, we'll see a list of all pallet metadata. Each element of this list contains a complete description of the given pallet's storage entries, as well as constants, callables (for creating extrinsics), errors and events. Some fields––such as a pallet's `call` field––point to an index in `metadata.tys`, which contains a complete description of the chain's type-level context. +If we index into `metadata.pallets`, we'll see a list of all pallet metadata. +Each element of this list contains a complete description of the given pallet's +storage entries, as well as constants, callables (for creating extrinsics), +errors and events. Some fields––such as a pallet's `call` field––point to an +index in `metadata.tys`, which contains a complete description of the chain's +type-level context. -Let's say we want to learn about the types associated with the `Balances` pallet's `Account` storage. +Let's say we want to learn about the types associated with the `Balances` +pallet's `Account` storage. ```ts // ... @@ -44,7 +70,8 @@ const accountsStorage = C.entryMetadata(balancesPallet, "Account") console.log(await accountsStorage.run()) ``` -On chains using the `Balances` pallet, `accountsStorage` will look _similar_ to the following. +On chains using the `Balances` pallet, `accountsStorage` will look _similar_ to +the following. ```ts { @@ -78,11 +105,14 @@ On chains using the `Balances` pallet, `accountsStorage` will look _similar_ to } ``` -- `type` tells us that this storage is that of a map, not a plain entry (standalone value) -- `key` tells us what type of value(s) we need to use in order to index into the map +- `type` tells us that this storage is that of a map, not a plain entry + (standalone value) +- `key` tells us what type of value(s) we need to use in order to index into the + map - `value` tells us what type of value we can expect to retrieve from the map -In this example, the `key`'s `id` is `0`. Let's take a look at this type (within the top-level `metadata`'s `tys`). +In this example, the `key`'s `id` is `0`. Let's take a look at this type (within +the top-level `metadata`'s `tys`). ```ts const keyType = metadata.tys[accountsStorage.key] @@ -101,7 +131,9 @@ const keyType = metadata.tys[accountsStorage.key] }; ``` -If we index again into `metadata.tys` with `1` (as specified in the first field), we'll see the inner types (in this case a 32-element tuple of `u8`s). From these descriptions, we can roughly deduce the JS equivalent. +If we index again into `metadata.tys` with `1` (as specified in the first +field), we'll see the inner types (in this case a 32-element tuple of `u8`s). +From these descriptions, we can roughly deduce the JS equivalent. ```ts namespace sp_core { @@ -117,7 +149,8 @@ We can instantiate this as we would any other JS-land value. const accountId32 = new Uint8Array(RAW_ADDR_BYTES) ``` -We'll cover the TypeScript <-> Rust conversions more in depth [in a later section](#typescript---rust). +We'll cover the TypeScript <-> Rust conversions more in depth +[in a later section](#typescript---rust). Let's now utilize our `accountId32` definition to read a balance. @@ -135,7 +168,8 @@ const account = await account.run() What value does this retrieve? How can we deduce this from the FRAME metadata? -We can do the same as before, but this time index into `metadata.tys` with the `accountsStorage.value`. +We can do the same as before, but this time index into `metadata.tys` with the +`accountsStorage.value`. ```ts const valueType = metadata.tys[accountsStorage.value] @@ -159,7 +193,9 @@ This should give us something along the following lines: }; ``` -When we follow type `6` (metadata.tys[6]), we see that it represents a `u128`. In TypeScript, this translates to a `bigint`. Therefore, the complete JS-land structure looks as follows. +When we follow type `6` (metadata.tys[6]), we see that it represents a `u128`. +In TypeScript, this translates to a `bigint`. Therefore, the complete JS-land +structure looks as follows. ```ts namespace pallet_balances { @@ -172,7 +208,8 @@ namespace pallet_balances { } ``` -> Note: we can ignore the `params` field of the `AccountData` metadata, as the type param is already applied to the field metadata. +> Note: we can ignore the `params` field of the `AccountData` metadata, as the +> type param is already applied to the field metadata. ## Rust ⬌ TypeScript @@ -249,9 +286,12 @@ type E1 = ## Runtime Validation -What happens if we ever specify an invalid value to an untyped effect? Capi will return a validation error with a detailed description of the type incompatibility. +What happens if we ever specify an invalid value to an untyped effect? Capi will +return a validation error with a detailed description of the type +incompatibility. -For instance, the aforementioned system accounts map is keyed with a `Uint8Array`. What happens if we try to key into it with `"HELLO T6"`? +For instance, the aforementioned system accounts map is keyed with a +`Uint8Array`. What happens if we try to key into it with `"HELLO T6"`? ```ts const account = C.entryRead(client)("System", "Account", ["HELLO T6"]) @@ -276,9 +316,13 @@ Let's look at the same example from before: reading some `AccountData`. const result = await C.entryRead(client)("System", "Account", [key]).run() ``` -In this storage read example, `result` is typed as the successfully-retrieved value (container) unioned with all possible errors. +In this storage read example, `result` is typed as the successfully-retrieved +value (container) unioned with all possible errors. -There are several ways to "unwrap" the inner `value`. The recommended path is to first check for and handle all possible errors, which may encapsulate error specific data (as do [SCALE](https://github.com/paritytech/scale-ts) validation errors). +There are several ways to "unwrap" the inner `value`. The recommended path is to +first check for and handle all possible errors, which may encapsulate error +specific data (as do [SCALE](https://github.com/paritytech/scale-ts) validation +errors). ```ts if (account instanceof Error) { diff --git a/dprint.json b/dprint.json index 425c343f6..873ecb8dc 100644 --- a/dprint.json +++ b/dprint.json @@ -7,6 +7,10 @@ "arrowFunction.useParentheses": "force", "semiColons": "asi" }, + "markdown": { + "lineWidth": 80, + "textWrap": "always" + }, "includes": ["**.{dockerfile,json,md,toml,ts,tsx}"], "excludes": ["target", "util/tsFormatter.ts"], "plugins": [ diff --git a/providers/frame/FrameBinProvider.ts b/providers/frame/FrameBinProvider.ts index 46c6c7648..11ebfb356 100644 --- a/providers/frame/FrameBinProvider.ts +++ b/providers/frame/FrameBinProvider.ts @@ -1,3 +1,4 @@ +import { RequestStatus } from "http://localhost:4646/frame/dev/polkadot/@v0.9.36/types/pallet_preimage/mod" import { deadline } from "../../deps/std/async.ts" import { Env, PathInfo } from "../../server/mod.ts" import { PermanentMemo } from "../../util/mod.ts" diff --git a/providers/frame/polkadot_dev.ts b/providers/frame/polkadot_dev.ts index f80a7d825..868d4891b 100644 --- a/providers/frame/polkadot_dev.ts +++ b/providers/frame/polkadot_dev.ts @@ -9,7 +9,7 @@ export interface PolkadotDevProviderProps { } const TEST_USER_COUNT = 1000 -const TEST_USER_INITIAL_FUNDS = 1000000000000000000 +const TEST_USER_INITIAL_FUNDS = 1000000000000000000n const DEV_RUNTIME_PREFIXES = { polkadot: 0, kusama: 2, @@ -55,7 +55,7 @@ export class PolkadotDevProvider extends FrameBinProvider { for (let i = 0; i < TEST_USER_COUNT; i++) { balances.push([ ss58.encode(DEV_RUNTIME_PREFIXES[runtimeName], testPair(i).publicKey), - TEST_USER_INITIAL_FUNDS, + Number(TEST_USER_INITIAL_FUNDS), ]) } const customChainSpecPath = await Deno.makeTempFile({ @@ -63,18 +63,15 @@ export class PolkadotDevProvider extends FrameBinProvider { suffix: ".json", }) await Deno.writeTextFile(customChainSpecPath, JSON.stringify(chainSpec, undefined, 2)) - const buildSpecRawCmd = new Deno.Command( - this.bin, - { - args: [ - "build-spec", - "--disable-default-bootnode", - "--chain", - customChainSpecPath, - "--raw", - ], - }, - ) + const buildSpecRawCmd = new Deno.Command(this.bin, { + args: [ + "build-spec", + "--disable-default-bootnode", + "--chain", + customChainSpecPath, + "--raw", + ], + }) const chainSpecRaw = JSON.parse( new TextDecoder().decode((await buildSpecRawCmd.output()).stdout), ) diff --git a/rune/rune.md b/rune/rune.md index 5bc4e7e68..b1e226d99 100644 --- a/rune/rune.md +++ b/rune/rune.md @@ -211,7 +211,8 @@ We can still achieve the same behavior in both, but in RxJS, we had to use a different combinator. (`combineLatest` wouldn't have worked in the first example as it would've given `a` inconsistent values). -As the timing gets even more complex, though, it becomes infeasible to handle correctly in RxJS: +As the timing gets even more complex, though, it becomes infeasible to handle +correctly in RxJS: ```ts import { combineLatest, map, timer, zip } from "npm:rxjs" From 22a0999097d0267186d214c66a389fc242e7d3ae Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 15:56:18 -0500 Subject: [PATCH 04/23] revert accidentally-included changes from matias pr --- crypto/test_pairs.ts | 7 ---- providers/frame/polkadot_dev.ts | 63 ++------------------------------- 2 files changed, 3 insertions(+), 67 deletions(-) diff --git a/crypto/test_pairs.ts b/crypto/test_pairs.ts index 06ce754c9..02e0a0437 100644 --- a/crypto/test_pairs.ts +++ b/crypto/test_pairs.ts @@ -1,4 +1,3 @@ -import { Blake2_256 } from "./hashers.ts" import { decode } from "./hex.ts" import { Sr25519 } from "./Sr25519.ts" @@ -31,9 +30,3 @@ export const bobStash = pair( function pair(secret: string) { return Sr25519.fromSecret(decode(secret)) } - -export function testPair(userId: number) { - return Sr25519.fromSeed( - Blake2_256.hash(new TextEncoder().encode(`capi-test-user-${userId}`)), - ) -} diff --git a/providers/frame/polkadot_dev.ts b/providers/frame/polkadot_dev.ts index 868d4891b..ca2cb47e0 100644 --- a/providers/frame/polkadot_dev.ts +++ b/providers/frame/polkadot_dev.ts @@ -1,4 +1,3 @@ -import { ss58, testPair } from "../../crypto/mod.ts" import * as $ from "../../deps/scale.ts" import { Env, PathInfo } from "../../server/mod.ts" import { getAvailable } from "../../util/port.ts" @@ -8,15 +7,6 @@ export interface PolkadotDevProviderProps { polkadotPath?: string } -const TEST_USER_COUNT = 1000 -const TEST_USER_INITIAL_FUNDS = 1000000000000000000n -const DEV_RUNTIME_PREFIXES = { - polkadot: 0, - kusama: 2, - westend: 42, - rococo: 42, -} as const - export class PolkadotDevProvider extends FrameBinProvider { constructor(env: Env, { polkadotPath }: PolkadotDevProviderProps = {}) { super(env, { @@ -27,61 +17,14 @@ export class PolkadotDevProvider extends FrameBinProvider { } async launch(pathInfo: PathInfo) { - const runtimeName = pathInfo.target || "polkadot" + const runtimeName = pathInfo.target $.assert($devRuntimeName, runtimeName) const port = getAvailable() - const chainSpec = await this.#getCustomChainSpec(runtimeName) - const args: string[] = ["--tmp", "--alice", "--ws-port", port.toString(), "--chain", chainSpec] + const args: string[] = ["--dev", "--ws-port", port.toString()] + if (runtimeName !== "polkadot") args.push(`--force-${runtimeName}`) await this.runBin(args) return port } - - async #getCustomChainSpec( - runtimeName: "polkadot" | "kusama" | "westend" | "rococo", - ): Promise { - const buildSpecCmd = new Deno.Command( - this.bin, - { - args: [ - "build-spec", - "--disable-default-bootnode", - "--chain", - `${runtimeName}-dev`, - ], - }, - ) - const chainSpec = JSON.parse(new TextDecoder().decode((await buildSpecCmd.output()).stdout)) - const balances: any[] = chainSpec.genesis.runtime.balances.balances - for (let i = 0; i < TEST_USER_COUNT; i++) { - balances.push([ - ss58.encode(DEV_RUNTIME_PREFIXES[runtimeName], testPair(i).publicKey), - Number(TEST_USER_INITIAL_FUNDS), - ]) - } - const customChainSpecPath = await Deno.makeTempFile({ - prefix: `custom-${runtimeName}-chain-spec`, - suffix: ".json", - }) - await Deno.writeTextFile(customChainSpecPath, JSON.stringify(chainSpec, undefined, 2)) - const buildSpecRawCmd = new Deno.Command(this.bin, { - args: [ - "build-spec", - "--disable-default-bootnode", - "--chain", - customChainSpecPath, - "--raw", - ], - }) - const chainSpecRaw = JSON.parse( - new TextDecoder().decode((await buildSpecRawCmd.output()).stdout), - ) - const customChainSpecRawPath = await Deno.makeTempFile({ - prefix: `custom-${runtimeName}-chain-spec-raw`, - suffix: ".json", - }) - await Deno.writeTextFile(customChainSpecRawPath, JSON.stringify(chainSpecRaw, undefined, 2)) - return customChainSpecRawPath - } } const $devRuntimeName = $.literalUnion(["polkadot", "kusama", "westend", "rococo"]) From bcaf602b9d8db72caabb8f7b3eac65fc72d3e133 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 15:57:46 -0500 Subject: [PATCH 05/23] revert accidentally-included changes from matias pr --- providers/frame/FrameBinProvider.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/providers/frame/FrameBinProvider.ts b/providers/frame/FrameBinProvider.ts index 11ebfb356..46c6c7648 100644 --- a/providers/frame/FrameBinProvider.ts +++ b/providers/frame/FrameBinProvider.ts @@ -1,4 +1,3 @@ -import { RequestStatus } from "http://localhost:4646/frame/dev/polkadot/@v0.9.36/types/pallet_preimage/mod" import { deadline } from "../../deps/std/async.ts" import { Env, PathInfo } from "../../server/mod.ts" import { PermanentMemo } from "../../util/mod.ts" From 6f346618ae406a48f03b33cc3acbe467f1e1b998 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 15:59:23 -0500 Subject: [PATCH 06/23] tweak --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 022c277a1..54dfe6e70 100644 --- a/Readme.md +++ b/Readme.md @@ -8,9 +8,9 @@ Capi is a framework for crafting interactions with Substrate chains. It consists of a development server and fluent API, which facilitates multistep, multichain interactions without compromising either performance or ease of use. -- [Examples →](./examples)
SHOW ME THE CODE - [Docs →](https://docs.capi.dev)
Guides for Capi developers and pattern library developers +- [Examples →](./examples)
SHOW ME THE CODE - [API Reference →](https://deno.land/x/capi/mod.ts)
A generated API reference, based on type signatures and TSDocs. From 0db344a756d0e2b99a4b5f3e1169ca3cc46caa30 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:08:01 -0500 Subject: [PATCH 07/23] make node friendly --- Readme.md | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/Readme.md b/Readme.md index 54dfe6e70..7fe02e56b 100644 --- a/Readme.md +++ b/Readme.md @@ -16,29 +16,18 @@ interactions without compromising either performance or ease of use. ## At a Glance -Create an import map with the specifier(s) corresponding to your provider and -chain discovery value (in this case a WebSocket URL). - -`import_map.json` - -```json -{ - "imports": { - "polkadot/": "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/" - } -} -``` - Run the Capi development server. ```sh deno run -A https://deno.land/x/capi/main.ts ``` +> Node.js users can run `npx capi` + Then, open your editor and import bindings from the local server. ```ts -import { System } from "polkadot/mod.ts" +import { System } from "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/mod.ts" const key = System.Account .keyPage(1) @@ -50,6 +39,9 @@ const value = System.Account.value(key) console.log(await value.run()) ``` +> Node.js users can `npm i` from a similar endpoint: +> `http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/pkg.tgz` + ## Running Examples Within a fresh clone of the repository... @@ -91,4 +83,4 @@ Contributions are welcome and appreciated! Check out the Capi is [Apache licensed](LICENSE). [^1]: Rune is the unit of composition with which we model Capi programs. See -[docs/basics/rune.md](docs/basics/rune.md). +[docs/basics/rune.md](https://docs.capi.dev/rune.md). From aad0f55a5870489c3e3cbc20683cca3914544616 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:11:37 -0500 Subject: [PATCH 08/23] make node friendly --- Readme.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 7fe02e56b..059c0faaf 100644 --- a/Readme.md +++ b/Readme.md @@ -18,11 +18,17 @@ interactions without compromising either performance or ease of use. Run the Capi development server. +### Deno + ```sh deno run -A https://deno.land/x/capi/main.ts ``` -> Node.js users can run `npx capi` +### Node + +```sh +npx capi +``` Then, open your editor and import bindings from the local server. From 1e73bc87b6611fec4f2d6f35b16cac7ea6429c65 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:31:36 -0500 Subject: [PATCH 09/23] continued --- Readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index 059c0faaf..374347a2a 100644 --- a/Readme.md +++ b/Readme.md @@ -16,21 +16,21 @@ interactions without compromising either performance or ease of use. ## At a Glance -Run the Capi development server. +### Run The Capi Server -### Deno +#### Deno ```sh deno run -A https://deno.land/x/capi/main.ts ``` -### Node +#### Node ```sh npx capi ``` -Then, open your editor and import bindings from the local server. +### Import From The Server ```ts import { System } from "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/mod.ts" From d6db15a193ec1fa20b54c5810ce90d66448dbe72 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:33:21 -0500 Subject: [PATCH 10/23] continued --- Readme.md | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Readme.md b/Readme.md index 374347a2a..a9a542934 100644 --- a/Readme.md +++ b/Readme.md @@ -16,19 +16,31 @@ interactions without compromising either performance or ease of use. ## At a Glance -### Run The Capi Server +Create an import map (a web platform standard) with the specifier(s) +corresponding to your provider and chain discovery value (in this case a +WebSocket URL). + +`import_map.json` + +```json +{ + "imports": { + "polkadot/": "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/" + } +} +``` -#### Deno +Run The Capi Server ```sh deno run -A https://deno.land/x/capi/main.ts ``` -#### Node - -```sh -npx capi -``` +> Node.js users can use the CLI from NPM +> +> ```sh +> npx capi +> ``` ### Import From The Server From 783b28a74f007517421e495ec725e4f2d892928f Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:34:09 -0500 Subject: [PATCH 11/23] continued --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index a9a542934..e434e32f4 100644 --- a/Readme.md +++ b/Readme.md @@ -36,7 +36,7 @@ Run The Capi Server deno run -A https://deno.land/x/capi/main.ts ``` -> Node.js users can use the CLI from NPM +> Or use the Node.js equivalent > > ```sh > npx capi From 8b6052e09365c6e5c898646f58337e3b2dd25111 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:35:17 -0500 Subject: [PATCH 12/23] continued --- Readme.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index e434e32f4..6ec2a4c8d 100644 --- a/Readme.md +++ b/Readme.md @@ -16,9 +16,7 @@ interactions without compromising either performance or ease of use. ## At a Glance -Create an import map (a web platform standard) with the specifier(s) -corresponding to your provider and chain discovery value (in this case a -WebSocket URL). +Create an import map with the specifier corresponding to your target. `import_map.json` @@ -30,19 +28,19 @@ WebSocket URL). } ``` -Run The Capi Server +Run The Capi Server. ```sh deno run -A https://deno.land/x/capi/main.ts ``` -> Or use the Node.js equivalent +> Or use the Node.js equivalent: > > ```sh > npx capi > ``` -### Import From The Server +Then, open your editor and import bindings from the local server. ```ts import { System } from "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/mod.ts" From 86b2f097b8b994eafe3753199af8e6d30ff6e04d Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:36:05 -0500 Subject: [PATCH 13/23] continued --- Readme.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 6ec2a4c8d..f99e432b8 100644 --- a/Readme.md +++ b/Readme.md @@ -56,7 +56,10 @@ console.log(await value.run()) ``` > Node.js users can `npm i` from a similar endpoint: -> `http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/pkg.tgz` +> +> ```sh +> npm i http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/pkg.tgz +> ``` ## Running Examples From 66321c01e4350828315316ab0455846c137f9f35 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:41:27 -0500 Subject: [PATCH 14/23] continued --- Readme.md | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/Readme.md b/Readme.md index f99e432b8..4601d0ea1 100644 --- a/Readme.md +++ b/Readme.md @@ -14,7 +14,42 @@ interactions without compromising either performance or ease of use. - [API Reference →](https://deno.land/x/capi/mod.ts)
A generated API reference, based on type signatures and TSDocs. -## At a Glance +## At a Glance (Node.js) + +Run the Capi server. + +```sh +npx capi +``` + +NPM-install chain-specific APIs from the Capi server. + +`package.json` + +```json +{ + "dependencies": { + "polkadot": "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/pkg.tgz" + } +} +``` + +Then, open your editor and import from the generated package. + +```ts +import { System } from "polkadot" + +const key = System.Account + .keyPage(1) + .access(0) + .unhandle(undefined) + +const value = System.Account.value(key) + +console.log(await value.run()) +``` + +## At a Glance (Deno) Create an import map with the specifier corresponding to your target. @@ -28,18 +63,12 @@ Create an import map with the specifier corresponding to your target. } ``` -Run The Capi Server. +Run the Capi server. ```sh deno run -A https://deno.land/x/capi/main.ts ``` -> Or use the Node.js equivalent: -> -> ```sh -> npx capi -> ``` - Then, open your editor and import bindings from the local server. ```ts @@ -55,12 +84,6 @@ const value = System.Account.value(key) console.log(await value.run()) ``` -> Node.js users can `npm i` from a similar endpoint: -> -> ```sh -> npm i http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/pkg.tgz -> ``` - ## Running Examples Within a fresh clone of the repository... From 30c0bb5c38ab21001d91a1854fdfb00776e486d0 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:42:12 -0500 Subject: [PATCH 15/23] continued --- Readme.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 4601d0ea1..9983f586c 100644 --- a/Readme.md +++ b/Readme.md @@ -14,7 +14,9 @@ interactions without compromising either performance or ease of use. - [API Reference →](https://deno.land/x/capi/mod.ts)
A generated API reference, based on type signatures and TSDocs. -## At a Glance (Node.js) +## At a Glance + +### Node.js Usage Run the Capi server. @@ -49,7 +51,7 @@ const value = System.Account.value(key) console.log(await value.run()) ``` -## At a Glance (Deno) +### Deno Usage Create an import map with the specifier corresponding to your target. From bb97fad461ae78138024be6f74ea6262090f6956 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:43:55 -0500 Subject: [PATCH 16/23] continued --- Readme.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Readme.md b/Readme.md index 9983f586c..a22613958 100644 --- a/Readme.md +++ b/Readme.md @@ -36,7 +36,7 @@ NPM-install chain-specific APIs from the Capi server. } ``` -Then, open your editor and import from the generated package. +Then, open your editor and import from the installed package. ```ts import { System } from "polkadot" @@ -53,6 +53,12 @@ console.log(await value.run()) ### Deno Usage +Run the Capi server. + +```sh +deno run -A https://deno.land/x/capi/main.ts +``` + Create an import map with the specifier corresponding to your target. `import_map.json` @@ -65,16 +71,10 @@ Create an import map with the specifier corresponding to your target. } ``` -Run the Capi server. - -```sh -deno run -A https://deno.land/x/capi/main.ts -``` - -Then, open your editor and import bindings from the local server. +Then, open your editor and import from the local server. ```ts -import { System } from "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/mod.ts" +import { System } from "polkadot/mod.ts" const key = System.Account .keyPage(1) From dc6c4fbeaaa494b04b749816fe1ea2e5c3f8e56f Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:49:44 -0500 Subject: [PATCH 17/23] Update Readme.md Co-authored-by: T6 --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index a22613958..617c2ce8a 100644 --- a/Readme.md +++ b/Readme.md @@ -93,7 +93,7 @@ Within a fresh clone of the repository... ```sh -deno task capi -- examples/.ts +deno task run examples/.ts ``` ## Rationale From b23d7c73244bf11ce1d97bda13fbdb66c5c061d4 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:52:16 -0500 Subject: [PATCH 18/23] continued --- Readme.md | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/Readme.md b/Readme.md index 617c2ce8a..bae163714 100644 --- a/Readme.md +++ b/Readme.md @@ -18,12 +18,6 @@ interactions without compromising either performance or ease of use. ### Node.js Usage -Run the Capi server. - -```sh -npx capi -``` - NPM-install chain-specific APIs from the Capi server. `package.json` @@ -31,7 +25,7 @@ NPM-install chain-specific APIs from the Capi server. ```json { "dependencies": { - "polkadot": "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/pkg.tgz" + "polkadot": "https://capi.dev/frame/wss/rpc.polkadot.io/@latest/pkg.tgz" } } ``` @@ -53,12 +47,6 @@ console.log(await value.run()) ### Deno Usage -Run the Capi server. - -```sh -deno run -A https://deno.land/x/capi/main.ts -``` - Create an import map with the specifier corresponding to your target. `import_map.json` @@ -66,7 +54,7 @@ Create an import map with the specifier corresponding to your target. ```json { "imports": { - "polkadot/": "http://localhost:4646/frame/wss/rpc.polkadot.io/@latest/" + "polkadot/": "https://capi.dev/frame/wss/rpc.polkadot.io/@latest/" } } ``` From eb8e4ef3cd7c2638a2e456439e5d2ed7e3cf08ef Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:55:19 -0500 Subject: [PATCH 19/23] continued --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index bae163714..a16bb6460 100644 --- a/Readme.md +++ b/Readme.md @@ -18,7 +18,7 @@ interactions without compromising either performance or ease of use. ### Node.js Usage -NPM-install chain-specific APIs from the Capi server. +NPM-install chain-specific APIs from [capi.dev](https://capi.dev/). `package.json` @@ -59,7 +59,7 @@ Create an import map with the specifier corresponding to your target. } ``` -Then, open your editor and import from the local server. +Then, open your editor and import from [capi.dev](https://capi.dev/). ```ts import { System } from "polkadot/mod.ts" From 823eea0bea3f0f52ccb9163fe8afcf2d49bfb020 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:56:15 -0500 Subject: [PATCH 20/23] continued --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index a16bb6460..bd69d3dc8 100644 --- a/Readme.md +++ b/Readme.md @@ -59,7 +59,7 @@ Create an import map with the specifier corresponding to your target. } ``` -Then, open your editor and import from [capi.dev](https://capi.dev/). +Then, open your editor and import from the to-be-mapped chain module. ```ts import { System } from "polkadot/mod.ts" From 1d6d2062ad74f720644b1135df8148fdb7e32a76 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Wed, 8 Mar 2023 16:58:44 -0500 Subject: [PATCH 21/23] continued --- Readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index bd69d3dc8..f7ab71c63 100644 --- a/Readme.md +++ b/Readme.md @@ -25,7 +25,7 @@ NPM-install chain-specific APIs from [capi.dev](https://capi.dev/). ```json { "dependencies": { - "polkadot": "https://capi.dev/frame/wss/rpc.polkadot.io/@latest/pkg.tgz" + "@capi/polkadot": "https://capi.dev/frame/wss/rpc.polkadot.io/@latest/pkg.tgz" } } ``` @@ -33,7 +33,7 @@ NPM-install chain-specific APIs from [capi.dev](https://capi.dev/). Then, open your editor and import from the installed package. ```ts -import { System } from "polkadot" +import { System } from "@capi/polkadot" const key = System.Account .keyPage(1) @@ -54,7 +54,7 @@ Create an import map with the specifier corresponding to your target. ```json { "imports": { - "polkadot/": "https://capi.dev/frame/wss/rpc.polkadot.io/@latest/" + "@capi/polkadot/": "https://capi.dev/frame/wss/rpc.polkadot.io/@latest/" } } ``` @@ -62,7 +62,7 @@ Create an import map with the specifier corresponding to your target. Then, open your editor and import from the to-be-mapped chain module. ```ts -import { System } from "polkadot/mod.ts" +import { System } from "@capi/polkadot/mod.ts" const key = System.Account .keyPage(1) From f7cc186094a9388c880ff3d810af6fa133aec2c0 Mon Sep 17 00:00:00 2001 From: Harry Solovay Date: Thu, 9 Mar 2023 09:57:26 -0500 Subject: [PATCH 22/23] continued --- Readme.md | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/Readme.md b/Readme.md index f7ab71c63..d06cfba6d 100644 --- a/Readme.md +++ b/Readme.md @@ -16,37 +16,6 @@ interactions without compromising either performance or ease of use. ## At a Glance -### Node.js Usage - -NPM-install chain-specific APIs from [capi.dev](https://capi.dev/). - -`package.json` - -```json -{ - "dependencies": { - "@capi/polkadot": "https://capi.dev/frame/wss/rpc.polkadot.io/@latest/pkg.tgz" - } -} -``` - -Then, open your editor and import from the installed package. - -```ts -import { System } from "@capi/polkadot" - -const key = System.Account - .keyPage(1) - .access(0) - .unhandle(undefined) - -const value = System.Account.value(key) - -console.log(await value.run()) -``` - -### Deno Usage - Create an import map with the specifier corresponding to your target. `import_map.json` @@ -114,5 +83,4 @@ Contributions are welcome and appreciated! Check out the Capi is [Apache licensed](LICENSE). -[^1]: Rune is the unit of composition with which we model Capi programs. See -[docs/basics/rune.md](https://docs.capi.dev/rune.md). +[^1]: Rune is the unit of composition with which we model Capi programs. From 4c54cc83de2db3eb4dd7f27a39591de059d0a689 Mon Sep 17 00:00:00 2001 From: T6 Date: Thu, 9 Mar 2023 10:01:47 -0500 Subject: [PATCH 23/23] tweak readme --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index d06cfba6d..3618d8ec1 100644 --- a/Readme.md +++ b/Readme.md @@ -28,7 +28,7 @@ Create an import map with the specifier corresponding to your target. } ``` -Then, open your editor and import from the to-be-mapped chain module. +Then, open your editor and import from the mapped chain module. ```ts import { System } from "@capi/polkadot/mod.ts"