Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
chore: codegen + test ctx server refactor (#487)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Lee <[email protected]>
Co-authored-by: T6 <[email protected]>
  • Loading branch information
3 people authored Jan 28, 2023
1 parent 2d40de8 commit 3322828
Show file tree
Hide file tree
Showing 142 changed files with 103,472 additions and 238,898 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"[typescript]": {
"editor.defaultFormatter": "dprint.dprint"
},
"deno.codeLens.testArgs": ["--no-check=remote", "-A", "-L=info"],
"deno.codeLens.testArgs": ["-A", "-L=info"],
"deno.config": "./deno.jsonc",
"deno.enable": true,
"deno.lint": true,
Expand All @@ -38,5 +38,5 @@
"vadimcn.vscode-lldb",
"bungcip.better-toml"
],
"postCreateCommand": "deno task codegen && deno task star"
"postCreateCommand": "deno task star"
}
21 changes: 0 additions & 21 deletions .github/workflows/deno_deploy.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/dev-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ jobs:
steps:
- name: Checkout (GitHub)
uses: actions/checkout@v2

- name: Build and run Dev Container task
uses: devcontainers/[email protected]
51 changes: 0 additions & 51 deletions .github/workflows/example.yml

This file was deleted.

30 changes: 26 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,32 @@ jobs:
- uses: denoland/setup-deno@9db7f66e8e16b5699a514448ce994936c63f0d54 # v1.1.0
with:
deno-version: v1.x
- name: Setup polkadot
uses: ./.github/actions/setup-polkadot
- name: Cache Deno dependencies
uses: actions/cache@v3
with:
path: |
~/.deno
~/.cache/deno
key: ${{ runner.os }}-deno-${{ hashFiles('deps/**/*.ts') }}
- name: Setup Polkadot
uses: ./.github/actions/setup-binary
with:
binary-name: polkadot
binary-version: v0.9.36
binary-github: https://github.com/paritytech/polkadot
- name: Setup Cumulus
uses: ./.github/actions/setup-binary
with:
binary-name: polkadot-parachain
binary-version: v0.9.360
binary-github: https://github.com/paritytech/cumulus
- name: Setup Zombienet
uses: ./.github/actions/setup-binary
with:
binary-name: zombienet-linux
binary-version: v1.3.18
binary-github: https://github.com/paritytech/zombienet
- run: deno lint
- run: deno task codegen
- run: deno task star
- run: deno task test
- run: deno task test:examples
# - run: deno task test:examples
10 changes: 7 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
"[typescript]": {
"editor.defaultFormatter": "dprint.dprint"
},
"deno.codeLens.testArgs": ["--no-check=remote", "-A", "-L=info"],
"deno.codeLens.testArgs": ["-A", "-L=info"],
"deno.config": "./deno.jsonc",
"deno.importMap": "./import_map.json",
"deno.suggest.imports.hosts": {
"https://deno.land": true,
"https://x.nest.land": true,
"https://crux.land": true,
"http://localhost:5646": true,
"https://capi.dev": true
"https://capi.dev": true,
"http://localhost:4646": false
},
"deno.enable": true,
"deno.lint": true,
Expand All @@ -26,5 +26,9 @@
"prettier.printWidth": 100,
"ltex.disabledRules": {
"en-US": ["MORFOLOGIK_RULE_EN_US"]
},
"markdownlint.config": {
"MD013": false,
"MD033": false
}
}
33 changes: 27 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ Capi is a declarative, TypeScript-first toolkit for crafting interactions with S

## At a Glance

Run the local 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.

```ts
import { System } from "https://capi.dev/proxy/wss:rpc.polkadot.io/pallets/mod.ts"
import { System } from "http://localhost:4646/frame/wss/rpc.polkadot.io/@<chain-version>/mod.ts"

const key = System.Account.keys().first()

Expand All @@ -20,11 +28,24 @@ const value = System.Account.entry(key)
console.log(await value.run())
```

> Note: although the codegen server is hosted on https://capi.dev, we encourage you to run it locally with
>
> ```sh
> deno run -A https://deno.land/x/capi/serve.ts
> ```
### Import Mapping

For simplicity, we recommend aliasing import specifiers via import maps.

`import_map.json`

```json
{
"imports": {
"#polkadot/": "http://localhost:4646/frame/wss/rpc.polkadot.io/@<chain-version>/"
}
}
```

```diff
- import { System } from "http://localhost:4646/frame/wss/rpc.polkadot.io/@<chain-version>/mod.ts"
+ import { System } from "#polkadot/mod.ts"
```

## Examples

Expand Down
48 changes: 19 additions & 29 deletions _tasks/download_frame_metadata.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as Z from "../deps/zones.ts"
import * as C from "../mod.ts"
import * as U from "../util/mod.ts"
import { rawClient as kusama } from "kusama/mod.ts"
import { rawClient as polkadot } from "polkadot/mod.ts"
import { rawClient as rococo } from "rococo/mod.ts"
import { rawClient as westend } from "westend/mod.ts"

const names = Object.keys(C.knownClients)
const knownClients = { kusama, polkadot, westend, rococo }

const names = Object.keys(knownClients)
const outDir = new URL("../frame_metadata/_downloaded", import.meta.url)
try {
Deno.removeSync(outDir, { recursive: true })
Expand All @@ -26,30 +29,17 @@ async function download(name: string) {
)
}
`
Deno.writeTextFileSync(modFilePath, modFileContents, { create: true })

U.throwIfError(await Z.ls(...Object.entries(C.knownClients).map(download)).run())

function download<Name extends Z.$<string>, Client extends Z.$<C.rpc.Client>>(
entry: [name: Name, client: Client],
) {
return Z.ls(...entry).next(async ([name, client]) => {
try {
const metadataHex = U.throwIfError(await C.state.getMetadata(client)().run())
const outPath = new URL(`_downloaded/${name}.scale`, outDir)
console.log(`Downloading ${name} metadata to "${outPath}".`)
await Deno.writeTextFile(outPath, metadataHex)
return
} catch (cause) {
return new MetadataDownloadError(name, { cause })
}
})
}

class MetadataDownloadError extends Error {
override readonly name = "MetadataDownloadError"
Deno.writeTextFileSync(modFilePath, modFileContents, { create: true })

constructor(readonly chainName: string, options: ErrorOptions) {
super(undefined, options)
}
}
await Promise.all(
Object.entries(knownClients).map(async ([name, client]) => {
const r = await client.call(name, "state_getMetadata", [])
if (r instanceof Error) throw r
if (r.error) throw new Error(r.error.message)
const outPath = new URL(`_downloaded/${name}.scale`, outDir)
console.log(`Downloading ${name} metadata to "${outPath}".`)
await Deno.writeTextFile(outPath, r.result)
await client.discard()
}),
)
18 changes: 0 additions & 18 deletions _tasks/gen_deploy.ts

This file was deleted.

Loading

0 comments on commit 3322828

Please sign in to comment.