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

feat: rune #454

Merged
merged 128 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
fddf49f
initial work on rune
tjjfvi Nov 29, 2022
c50bffd
rename rune to future
tjjfvi Nov 29, 2022
d596553
add mapValue
tjjfvi Nov 29, 2022
2bd1af0
misc multi-value future combinators
tjjfvi Nov 30, 2022
d6fdb4a
a bunch more future combinators
tjjfvi Nov 30, 2022
b0b6348
fix empty error message
tjjfvi Nov 30, 2022
2a14924
add debounce
tjjfvi Nov 30, 2022
4d80f7f
add args
tjjfvi Nov 30, 2022
2811d25
fix race condition
tjjfvi Nov 30, 2022
e9256ac
add type test for args
tjjfvi Nov 30, 2022
4bdf3ee
rename mapValue to pipe, support async pipe
tjjfvi Nov 30, 2022
d0e3cd4
rename future to rune
tjjfvi Dec 1, 2022
6b325a0
initial loom
tjjfvi Dec 1, 2022
4d83c6d
add stream support
tjjfvi Dec 1, 2022
59095da
extract and simplify clock util
tjjfvi Dec 1, 2022
1af9bb7
initial linear time
tjjfvi Dec 1, 2022
ff06d9a
linear time stream support
tjjfvi Dec 1, 2022
71d7eeb
tweak tests
tjjfvi Dec 1, 2022
d8d5514
generalize error lifting
tjjfvi Dec 1, 2022
f2c8ada
reenable misc tests
tjjfvi Dec 1, 2022
2ceffa1
misc cleanup
tjjfvi Dec 1, 2022
8b294bd
add lazy
tjjfvi Dec 2, 2022
43abdf5
rename period to epoch, rework
tjjfvi Dec 2, 2022
4db2636
fix args.test.ts re unwrap
tjjfvi Dec 2, 2022
f48a52f
caching
tjjfvi Dec 2, 2022
c418f6d
remove signal argument from evaluate
tjjfvi Dec 2, 2022
471b18b
add EpochHandle, .latest()
tjjfvi Dec 2, 2022
a396238
minor reorg
tjjfvi Dec 2, 2022
4192bca
rename cast to ctx
tjjfvi Dec 2, 2022
bb0d512
make constant directly extend rune
tjjfvi Dec 2, 2022
41939fc
tweak semantics of latest, update tests
tjjfvi Dec 2, 2022
618a015
tweak lazy definition
tjjfvi Dec 3, 2022
4a86e90
misc tweaks to rune api
tjjfvi Jan 17, 2023
94302f1
rewrite timing system
tjjfvi Jan 17, 2023
e1aa236
further rework of rune
tjjfvi Jan 17, 2023
eaac0d3
initial conversion of capi to rune
tjjfvi Jan 17, 2023
f798bb3
fluent rune api
tjjfvi Jan 17, 2023
7f5ac95
update usage of rune in capi
tjjfvi Jan 17, 2023
c6f8fc5
fix nontermination in derived example
tjjfvi Jan 17, 2023
e830f3d
refactor rune
tjjfvi Jan 18, 2023
fac9816
initial rune doc
tjjfvi Jan 23, 2023
1e10518
update some examples
tjjfvi Jan 30, 2023
ab9a44f
tweak phrasing of doc
tjjfvi Jan 30, 2023
83f818a
misc fixes
harrysolovay Jan 30, 2023
f22558e
get several examples working and impl multisig pattern with rune
harrysolovay Jan 30, 2023
b4ca8e4
more refactoring, begin ink contract work
harrysolovay Jan 31, 2023
1614eb2
north star dyn contract dx
harrysolovay Jan 31, 2023
c701eee
pairing with t6
harrysolovay Jan 31, 2023
6595083
renaming Chain type param to C, misc contracts
harrysolovay Feb 1, 2023
6b5ace0
clean up multisig
harrysolovay Feb 1, 2023
4dad354
begin runify-ing xcm example
harrysolovay Feb 1, 2023
c9c6625
start modeling fluent ink contract api w rune
harrysolovay Feb 1, 2023
3e79fbd
contract type issue fix
harrysolovay Feb 1, 2023
fec8445
continued
harrysolovay Feb 2, 2023
18a6d23
remove extrinsic export from codegen
harrysolovay Feb 2, 2023
596e934
misc cleanup
harrysolovay Feb 2, 2023
22cd679
attempt remote import fix
harrysolovay Feb 2, 2023
3e409b6
bump cumulus to .370
tjjfvi Feb 2, 2023
10f260c
remove examples/mod.ts
tjjfvi Feb 2, 2023
9fea89d
continued
harrysolovay Feb 3, 2023
49dec6b
rework Rune U -- unwrap -> unhandle, various improvements
tjjfvi Feb 3, 2023
42e4ec6
more runes
harrysolovay Feb 3, 2023
669d2ad
even more runes
harrysolovay Feb 3, 2023
1d64839
fix type checking
tjjfvi Feb 4, 2023
bf10f2f
fix lint
tjjfvi Feb 4, 2023
b4e1768
tweak star task
tjjfvi Feb 4, 2023
c657105
fix star script maybe
tjjfvi Feb 4, 2023
d02ea2b
continued
harrysolovay Feb 4, 2023
71aec7d
refactor block author example, more runes
harrysolovay Feb 4, 2023
53d3366
clean up examples
harrysolovay Feb 4, 2023
b2287a6
attempt to fix star
harrysolovay Feb 4, 2023
f494f7c
fix lint error
harrysolovay Feb 4, 2023
3e38a24
re-add intos
harrysolovay Feb 4, 2023
378e4ec
cleanup fluent dir
harrysolovay Feb 4, 2023
c3d0720
fix fmt
harrysolovay Feb 4, 2023
bfa9dc6
continued
harrysolovay Feb 4, 2023
68cd566
more example cleanup
harrysolovay Feb 4, 2023
f64fc4e
add variance annotations to more runes
tjjfvi Feb 4, 2023
dea9baa
clean up contracts
harrysolovay Feb 5, 2023
89094df
clean up contracts
harrysolovay Feb 5, 2023
d755f8c
clean up pattern file locs and means of init
harrysolovay Feb 5, 2023
4d9c0bf
make instantiate accept spread list instead of rec
harrysolovay Feb 5, 2023
d7d8a6b
move babe author into patterns
harrysolovay Feb 5, 2023
4982ecd
fix batch example
harrysolovay Feb 5, 2023
05f6762
add events method to txstatus rune
harrysolovay Feb 5, 2023
12ab82c
rework transfer example
harrysolovay Feb 5, 2023
1e9fbbe
import map remote capi to local
tjjfvi Feb 5, 2023
55c9682
fix star task probably
tjjfvi Feb 5, 2023
ba21c0e
misc tweaks
tjjfvi Feb 5, 2023
f79aa69
clean up events
harrysolovay Feb 5, 2023
d8879a3
codec test cleanup
harrysolovay Feb 5, 2023
2f0ce0c
more codec test cleanup
harrysolovay Feb 5, 2023
1857736
more on contracts
harrysolovay Feb 5, 2023
27a7f16
contracts continued
harrysolovay Feb 5, 2023
0cc205b
fix self reexport
tjjfvi Feb 6, 2023
9662943
fix symbol usage in Rune
tjjfvi Feb 6, 2023
3bbd22c
contracts continued
tjjfvi Feb 6, 2023
a36f644
clean up preRuntimeDigest rune factory
harrysolovay Feb 6, 2023
082c217
refactor server; add caching
tjjfvi Feb 6, 2023
531f834
move RunicArgs into Rune.ts
tjjfvi Feb 6, 2023
a9ada67
comment out ink interact example
tjjfvi Feb 6, 2023
2c9440a
fix star
tjjfvi Feb 6, 2023
543475f
break up test workflow
tjjfvi Feb 6, 2023
560a0ae
fix path info tests
tjjfvi Feb 6, 2023
98b140e
rune typing cleanup and contracts cleanup
harrysolovay Feb 7, 2023
562e1f4
get contracts working again
harrysolovay Feb 7, 2023
717beac
increase timeout on star
tjjfvi Feb 7, 2023
7dbf9be
misc cleanup
harrysolovay Feb 7, 2023
57cb3d5
more contract cleanup
harrysolovay Feb 7, 2023
5ff755f
more contract cleanup
harrysolovay Feb 7, 2023
b01f356
fix lint error
harrysolovay Feb 7, 2023
166116b
add basic watch example, fix xcm example, get rid of zones
harrysolovay Feb 8, 2023
e9d9ec8
event and ink cleanup
harrysolovay Feb 8, 2023
20f0e5d
add chain to value rune
ryanleecode Feb 8, 2023
1aced91
fix: nonce in extrinsic rune
ryanleecode Feb 8, 2023
80ee8b5
typed events from client and misc
harrysolovay Feb 8, 2023
2c67050
Merge branch 'main' into rune
tjjfvi Feb 8, 2023
673e04d
fix ci
harrysolovay Feb 8, 2023
cdb5d0b
fix examples ignore
harrysolovay Feb 8, 2023
168145e
avoid unnecessary rpc all in block rune get header
harrysolovay Feb 8, 2023
26f1601
get rid of multiaddr rune
harrysolovay Feb 8, 2023
5e2a6a6
get rid of useless import
harrysolovay Feb 8, 2023
fc64a82
revert strange typing change in rpc types
harrysolovay Feb 8, 2023
f143976
fix modfile
harrysolovay Feb 8, 2023
fe3d3fb
remove mention of algebraic effects from rune.md
harrysolovay Feb 8, 2023
49ae3e6
fix moderate usage
harrysolovay Feb 8, 2023
f345c30
fix moderate usage
harrysolovay Feb 8, 2023
3e9e111
fix Rune circular dep error
harrysolovay Feb 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@
"streetsidesoftware.code-spell-checker",
"vadimcn.vscode-lldb",
"bungcip.better-toml"
],
"postCreateCommand": "deno task star"
]
}
17 changes: 17 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Lint
on:
pull_request:
push:
branches:
- main
jobs:
star:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@9db7f66e8e16b5699a514448ce994936c63f0d54 # v1.1.0
with:
deno-version: v1.x
- run: deno lint
42 changes: 42 additions & 0 deletions .github/workflows/star.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Star
on:
pull_request:
push:
branches:
- main
jobs:
star:
name: Star
runs-on: ubuntu-latest
timeout-minutes: 30 # :(
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@9db7f66e8e16b5699a514448ce994936c63f0d54 # v1.1.0
with:
deno-version: v1.x
- 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.370
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 task star
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ jobs:
uses: ./.github/actions/setup-binary
with:
binary-name: polkadot-parachain
binary-version: v0.9.360
binary-version: v0.9.370
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 star
- run: deno task test
# - run: deno task test:examples
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ARG VARIANT=bullseye
FROM --platform=linux/amd64 mcr.microsoft.com/devcontainers/base:0-${VARIANT} as vscode

ARG DENO_VERSION=1.30.0
ARG DENO_VERSION=1.30.3
ARG POLKADOT_VERSION=v0.9.36
ARG POLKADOT_PARACHAIN_VERSION=v0.9.360
ARG ZOMBIENET_VERSION=v1.3.30
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> 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 and [a high-level functional effect system](https://github.com/paritytech/zones) and [effects](./effects), which facilitate multistep, multichain interactions without compromising either performance or safety.
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 and a high-level functional effect system (Rune) and fluent API, which facilitate multistep, multichain interactions without compromising either performance or safety.

- [Examples &rarr;](./examples)<br />SHOW ME THE CODE
- [API Reference &rarr;](https://deno.land/x/capi/mod.ts)<br />A generated API reference, based on type signatures and in-source comments.
Expand Down
4 changes: 0 additions & 4 deletions _tasks/dnt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ await Promise.all([
name: "scale-codec",
version: "^0.10.0",
},
"https://deno.land/x/[email protected]/mod.ts": {
name: "zones",
version: "0.1.0-beta.13",
},
"https://deno.land/x/[email protected]/index-deno.js": {
name: "@substrate/smoldot-light",
version: "0.7.6",
Expand Down
8 changes: 4 additions & 4 deletions _tasks/download_frame_metadata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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"
import { rawClient as kusama } from "kusama/client.ts"
import { rawClient as polkadot } from "polkadot/client.ts"
import { rawClient as rococo } from "rococo/client.ts"
import { rawClient as westend } from "westend/client.ts"

const knownClients = { kusama, polkadot, westend, rococo }

Expand Down
69 changes: 68 additions & 1 deletion _tasks/star.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { parse } from "../deps/std/flags.ts"
import * as fs from "../deps/std/fs.ts"
import * as path from "../deps/std/path.ts"
import { getOrInit } from "../util/state.ts"

const { ignore } = parse(Deno.args, { string: ["ignore"] })
let generated = ""
Expand All @@ -16,5 +17,71 @@ for await (
const dir = path.join(Deno.cwd(), "target")
await fs.ensureDir(dir)
const dest = path.join(dir, "star.ts")
console.log(`Writing "${dest}".`)
await Deno.writeTextFile(dest, generated)

const data: Data = JSON.parse(
new TextDecoder().decode(
await Deno.run({ cmd: ["deno", "info", "--json", "target/star.ts"], stdout: "piped" }).output(),
),
)

interface Data {
redirects: Record<string, string>
modules: Array<{
specifier: string
dependencies?: Array<{
type?: {
specifier: string
}
code?: {
specifier: string
}
}>
}>
}

const dependencies = new Map<string, Set<string>>()

function visit(specifier: string) {
while (specifier in data.redirects) specifier = data.redirects[specifier]!
if (specifier.startsWith("npm:")) return new Set<string>()
return getOrInit(dependencies, specifier, () => {
const module = data.modules.find((x) => x.specifier === specifier)
if (!module) throw new Error("module not found " + specifier)
const set = new Set<string>([specifier])
dependencies.set(specifier, set)
for (const dep of module.dependencies ?? []) {
if (dep.code) {
for (const s of visit(dep.code.specifier)) {
set.add(s)
}
}
if (dep.type) {
for (const s of visit(dep.type.specifier)) {
set.add(s)
}
}
}
return set
})
}

for (const mod of data.modules) {
visit(mod.specifier)
}

const entries = [...dependencies.entries()].sort((a, b) => b[1].size - a[1].size)

const done = new Set()
for (const [file, deps] of entries.slice(1)) {
if (done.has(file)) continue
console.log(file)
const status = await Deno.run({ cmd: ["deno", "cache", "--check", file] })
.status()
if (!status.success) Deno.exit(status.code)
for (const d of deps) {
done.add(d)
}
}

console.log("Checked successfully")
5 changes: 0 additions & 5 deletions codegen/Codegen.ts

This file was deleted.

2 changes: 1 addition & 1 deletion codegen/File.ts → codegen/frame/File.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { tsFormatter } from "../deps/dprint.ts"
import { tsFormatter } from "../../deps/dprint.ts"

export class File {
constructor(public codeRaw = "") {}
Expand Down
82 changes: 82 additions & 0 deletions codegen/frame/FrameCodegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Metadata } from "../../frame_metadata/mod.ts"
import { SequenceTyDef, Ty } from "../../scale_info/mod.ts"
import { codecs } from "./codecs.ts"
import { File } from "./File.ts"
import { pallet } from "./pallet.ts"
import { type } from "./type.ts"
import { typeVisitor } from "./typeVisitor.ts"

export interface FrameCodegenProps {
metadata: Metadata
clientFile: File
}

export class FrameCodegen {
files = new Map<string, File>()

metadata
clientFile

typeVisitor
typeFiles = new Map<string, TypeFile>()

constructor({ metadata, clientFile }: FrameCodegenProps) {
this.metadata = metadata
this.clientFile = clientFile

this.typeVisitor = typeVisitor(this)

for (const [path, typeFile] of this.typeFiles) {
const filePath = path + typeFile.ext
this.files.set(filePath, type(this, path, filePath, typeFile))
}

this.files.set("codecs.ts", codecs(this))

this.files.set("client.ts", clientFile)

const callTy = Object
.fromEntries(this.metadata.extrinsic.ty.params.map((x) => [x.name.toLowerCase(), x.ty]))
.call!

const eventTy = (this.metadata
.pallets.find((x) => x.name === "System")
?.storage?.entries.find((x) => x.name === "Events")
?.value! as SequenceTyDef).typeParam

let palletNamespaceExports = ""
for (const p of this.metadata.pallets) {
if (!p.calls && !p.constants.length && !p.storage?.entries.length) continue
this.files.set(`${p.name}.ts`, pallet(this, p))
palletNamespaceExports += `export * as ${p.name} from "./${p.name}.ts"\n`
}

this.files.set(
"mod.ts",
new File(`
import * as C from "./capi.ts"
import * as types from "./types/mod.ts"
export type Chain = C.Chain<${this.typeVisitor.visit(callTy)}, ${
this.typeVisitor.visit(eventTy)
}>

export * from "./client.ts"
export * as types from "./types/mod.ts"

${palletNamespaceExports}
`),
)
}

[Symbol.iterator]() {
return Object.entries(this.files)[Symbol.iterator]()
}
}

export class TypeFile {
reexports = new Set<string>()
types = new Map<string, Ty>()
get ext() {
return this.reexports.size ? "/mod.ts" : ".ts"
}
}
6 changes: 3 additions & 3 deletions codegen/frame/codecs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Ty, TyVisitor } from "../../scale_info/mod.ts"
import { normalizeIdent } from "../../util/case.ts"
import { File } from "../File.ts"
import { S } from "../util.ts"
import { FrameCodegen } from "./mod.ts"
import { File } from "./File.ts"
import { FrameCodegen } from "./FrameCodegen.ts"
import { S } from "./util.ts"

export function codecs(ctx: FrameCodegen) {
const { tys } = ctx.metadata
Expand Down
27 changes: 0 additions & 27 deletions codegen/frame/extrinsic.ts

This file was deleted.

Loading