diff --git a/deps/polkadot/types.ts b/deps/polkadot/types.ts new file mode 100644 index 000000000..a100396eb --- /dev/null +++ b/deps/polkadot/types.ts @@ -0,0 +1 @@ +export * from "https://deno.land/x/polkadot@0.0.8/types/mod.ts"; diff --git a/effect/examples/balance.ts b/effect/examples/balance.ts deleted file mode 100644 index 7ee718412..000000000 --- a/effect/examples/balance.ts +++ /dev/null @@ -1,11 +0,0 @@ -import * as C from "../../mod.ts"; -import * as t from "../../test-util/mod.ts"; -import * as U from "../../util/mod.ts"; - -const config = await t.config(); - -const root = C.readEntry(config, "System", "Account", [t.alice.publicKey]); - -console.log(U.throwIfError(await root.run())); - -config.close(); diff --git a/effect/examples/first_ten_keys.ts b/effect/examples/first_ten_keys.ts deleted file mode 100644 index 06ef34c12..000000000 --- a/effect/examples/first_ten_keys.ts +++ /dev/null @@ -1,11 +0,0 @@ -import * as C from "../../mod.ts"; -import * as t from "../../test-util/mod.ts"; -import * as U from "../../util/mod.ts"; - -const config = await t.config(); - -const root = C.readKeyPage(config, "System", "Account", 10); - -console.log(U.throwIfError(await root.run()).keys); - -config.close(); diff --git a/effect/examples/metadata.ts b/effect/examples/metadata.ts deleted file mode 100644 index c2c389f4b..000000000 --- a/effect/examples/metadata.ts +++ /dev/null @@ -1,11 +0,0 @@ -import * as C from "../../mod.ts"; -import * as t from "../../test-util/mod.ts"; -import * as U from "../../util/mod.ts"; - -const config = await t.config(); - -const root = C.metadata(config); - -console.log(U.throwIfError(await root.run())); - -config.close(); diff --git a/effect/examples/read_block.ts b/effect/examples/read_block.ts deleted file mode 100644 index 6b58dd953..000000000 --- a/effect/examples/read_block.ts +++ /dev/null @@ -1,6 +0,0 @@ -import * as C from "../../mod.ts"; -import * as U from "../../util/mod.ts"; - -const root = C.readBlock(C.polkadot); - -console.log(U.throwIfError(await root.run())); diff --git a/effect/examples/transfer.ts b/effect/examples/transfer.ts deleted file mode 100644 index 0d1f69c4d..000000000 --- a/effect/examples/transfer.ts +++ /dev/null @@ -1,49 +0,0 @@ -import * as C from "../../mod.ts"; -import * as t from "../../test-util/mod.ts"; -import * as U from "../../util/mod.ts"; - -const config = await t.config({ altRuntime: "westend" }); - -const root = C.sendAndWatchExtrinsic({ - config, - sender: { - type: "Id", - value: t.alice.publicKey, - }, - palletName: "Balances", - methodName: "transfer", - args: { - value: 12345n, - dest: { - type: "Id", - value: t.bob.publicKey, - }, - }, - sign(message) { - return { - type: "Sr25519", - value: t.alice.sign(message), - }; - }, - createWatchHandler(stop) { - return (event) => { - if (typeof event.params.result === "string") { - console.log("Extrinsic", event.params.result); - } else { - if (event.params.result.inBlock) { - console.log("Extrinsic in block", event.params.result.inBlock); - } else if (event.params.result.finalized) { - console.log("Extrinsic finalized as of", event.params.result.finalized); - stop(); - } else { - console.log("Misc", event.params.result); - stop(); - } - } - }; - }, -}); - -U.throwIfError(await root.run()); - -config.close(); diff --git a/effect/examples/watch_blocks.ts b/effect/examples/watch_blocks.ts deleted file mode 100644 index c55b24f45..000000000 --- a/effect/examples/watch_blocks.ts +++ /dev/null @@ -1,16 +0,0 @@ -import * as C from "../../mod.ts"; -import * as U from "../../util/mod.ts"; - -const root = C.watchBlocks(C.polkadot, (stop) => { - let i = 0; - - return (event) => { - console.log(event); - if (i === 4) { - stop(); - } - i++; - }; -}); - -console.log(U.throwIfError(await root.run())); diff --git a/effect/extrinsic.test.ts b/effect/extrinsic.test.ts index f2dca9f06..6d285fef2 100644 --- a/effect/extrinsic.test.ts +++ b/effect/extrinsic.test.ts @@ -34,7 +34,7 @@ Deno.test({ fn: async () => { const root = C.readEntry(config, "System", "Account", [t.bob.publicKey]); - const state = U.throwIfError(await root.run()); + const state = await root.run(); assertObjectMatch(state, { value: { data: { free: 10000000000012345n } } }); }, diff --git a/examples/balance.ts b/examples/balance.ts old mode 100755 new mode 100644 index 7510e6abc..34d166b17 --- a/examples/balance.ts +++ b/examples/balance.ts @@ -4,11 +4,7 @@ import * as U from "../util/mod.ts"; const config = await t.config(); -const root = C - .chain(config) - .pallet("System") - .entry("Account", t.alice.publicKey) - .read(); +const root = C.readEntry(config, "System", "Account", [t.alice.publicKey]); console.log(U.throwIfError(await root.run())); diff --git a/examples/block.ts b/examples/block.ts deleted file mode 100644 index 5436db795..000000000 --- a/examples/block.ts +++ /dev/null @@ -1,14 +0,0 @@ -import * as C from "../mod.ts"; -import * as t from "../test-util/mod.ts"; -import * as U from "../util/mod.ts"; - -const config = await t.config(); - -const root = C - .chain(config) - .block() - .read(); - -console.log(U.throwIfError(await root.run())); - -config.close(); diff --git a/effect/examples/derived.ts b/examples/derived.ts similarity index 79% rename from effect/examples/derived.ts rename to examples/derived.ts index 33521033d..c39d9893e 100644 --- a/effect/examples/derived.ts +++ b/examples/derived.ts @@ -1,7 +1,8 @@ -import * as C from "../../mod.ts"; -import * as U from "../../util/mod.ts"; +import * as C from "../mod.ts"; +import * as U from "../util/mod.ts"; const ids = C.readEntry(C.polkadot, "Paras", "Parachains", []); + const root = C.into([ids], ({ value }) => { const heads = value.map((id: number) => { return C.readEntry(C.polkadot, "Paras", "Heads", [id]); diff --git a/examples/first_ten_keys.ts b/examples/first_ten_keys.ts index 5c0b7cdd9..9166fed1d 100644 --- a/examples/first_ten_keys.ts +++ b/examples/first_ten_keys.ts @@ -4,13 +4,8 @@ import * as U from "../util/mod.ts"; const config = await t.config(); -const root = C - .chain(config) - .pallet("System") - .entry("Account") - .keyPage(10) - .read(); +const root = C.readKeyPage(config, "System", "Account", 10); -console.log(U.throwIfError(await root.run())); +console.log(U.throwIfError(await root.run()).keys); config.close(); diff --git a/examples/metadata.ts b/examples/metadata.ts index 67351bfb0..99678132f 100644 --- a/examples/metadata.ts +++ b/examples/metadata.ts @@ -4,10 +4,7 @@ import * as U from "../util/mod.ts"; const config = await t.config(); -const root = C - .chain(config) - .metadata() - .read(); +const root = C.metadata(config); console.log(U.throwIfError(await root.run())); diff --git a/examples/playground.ts b/examples/playground.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/examples/polkadot_signer.ts b/examples/polkadot_signer.ts index d074c1a8c..788797af2 100644 --- a/examples/polkadot_signer.ts +++ b/examples/polkadot_signer.ts @@ -1,39 +1,37 @@ -import { TypeRegistry } from "https://deno.land/x/polkadot@0.0.8/types/mod.ts"; +import { TypeRegistry } from "../deps/polkadot/types.ts"; import * as C from "../mod.ts"; import * as t from "../test-util/mod.ts"; import * as U from "../util/mod.ts"; -const config = await t.config(); +const config = await t.config({ altRuntime: "westend" }); -const root = C - .chain(config) - .pallet("Balances") - .extrinsic("transfer") - .call({ +const root = C.sendAndWatchExtrinsic({ + config, + sender: { + type: "Id", + value: t.alice.publicKey, + }, + palletName: "Balances", + methodName: "transfer", + args: { value: 12345n, dest: { type: "Id", value: t.bob.publicKey, }, - }) - .signed( - { - type: "Id", - value: t.alice.publicKey, - }, - { - signPayload(payload: any) { - const tr = new TypeRegistry(); - tr.setSignedExtensions(payload.signedExtensions); - return Promise.resolve( - tr - .createType("ExtrinsicPayload", payload, { version: payload.version }) - .sign(t.alice), - ); - }, + }, + sign: { + signPayload(payload) { + const tr = new TypeRegistry(); + tr.setSignedExtensions(payload.signedExtensions); + return Promise.resolve( + tr + .createType("ExtrinsicPayload", payload, { version: payload.version }) + .sign(t.alice), + ); }, - ) - .sendAndWatch((stop) => { + }, + createWatchHandler(stop) { return (event) => { if (typeof event.params.result === "string") { console.log("Extrinsic", event.params.result); @@ -45,9 +43,13 @@ const root = C stop(); } else { console.log("Misc", event.params.result); + stop(); } } }; - }); + }, +}); U.throwIfError(await root.run()); + +config.close(); diff --git a/examples/raw_rpc_client/call.ts b/examples/raw_rpc_client/call.ts new file mode 100755 index 000000000..19282db3d --- /dev/null +++ b/examples/raw_rpc_client/call.ts @@ -0,0 +1,9 @@ +import * as C from "../../mod.ts"; +import * as rpc from "../../rpc/mod.ts"; +import * as U from "../../util/mod.ts"; + +const client = U.throwIfError(await rpc.stdClient(C.westend)); + +console.log(await client.call("state_getMetadata", [])); + +await client.close(); diff --git a/examples/raw_rpc_client/subscription.ts b/examples/raw_rpc_client/subscription.ts new file mode 100755 index 000000000..3d0e32b1d --- /dev/null +++ b/examples/raw_rpc_client/subscription.ts @@ -0,0 +1,20 @@ +import * as C from "../../mod.ts"; +import * as rpc from "../../rpc/mod.ts"; +import * as U from "../../util/mod.ts"; + +const client = U.throwIfError(await rpc.stdClient(C.westend)); + +const maybeError = await client.subscribe("chain_subscribeAllHeads", [], (stop) => { + let i = 1; + return async (message) => { + console.log({ [i++]: message.params.result }); + if (i > 5) { + stop(); + await client.close(); + } + }; +}); + +if (maybeError) { + console.log(maybeError); +} diff --git a/examples/events.ts b/examples/read_block.ts similarity index 57% rename from examples/events.ts rename to examples/read_block.ts index e43bc6914..a7ce5b74b 100644 --- a/examples/events.ts +++ b/examples/read_block.ts @@ -1,10 +1,6 @@ import * as C from "../mod.ts"; import * as U from "../util/mod.ts"; -const root = C - .chain(C.polkadot) - .pallet("System") - .entry("Events") - .read(); +const root = C.readBlock(C.polkadot); console.log(U.throwIfError(await root.run())); diff --git a/examples/read_events.ts b/examples/read_events.ts new file mode 100644 index 000000000..ff7a52cdd --- /dev/null +++ b/examples/read_events.ts @@ -0,0 +1,6 @@ +import * as C from "../mod.ts"; +import * as U from "../util/mod.ts"; + +const root = C.readEntry(C.westend, "System", "Events", []); + +console.log(U.throwIfError(await root.run())); diff --git a/examples/rpc/call.ts b/examples/rpc/call.ts deleted file mode 100755 index 6af761a30..000000000 --- a/examples/rpc/call.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { assert } from "../../deps/std/testing/asserts.ts"; -import { polkadot } from "../../known/mod.ts"; -import * as rpc from "../../rpc/mod.ts"; - -const client = await rpc.stdClient(polkadot); -assert(!(client instanceof Error)); - -console.log(await client.call("state_getMetadata", [])); - -await client.close(); diff --git a/examples/rpc/subscription.ts b/examples/rpc/subscription.ts deleted file mode 100755 index 0e256348a..000000000 --- a/examples/rpc/subscription.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { assert } from "../../deps/std/testing/asserts.ts"; -import { polkadot } from "../../known/mod.ts"; -import * as rpc from "../../rpc/mod.ts"; - -const client = await rpc.stdClient(polkadot); -assert(!(client instanceof Error)); - -let i = 1; - -const error = await client.subscribe("chain_subscribeAllHeads", [], (stop) => { - return async (message) => { - console.log({ [i++]: message.params.result }); - if (i > 5) { - stop(); - await client.close(); - } - }; -}); - -if (error) { - console.log(error); -} diff --git a/examples/rpc_call.ts b/examples/rpc_call.ts new file mode 100644 index 000000000..07d225ef3 --- /dev/null +++ b/examples/rpc_call.ts @@ -0,0 +1,6 @@ +import * as C from "../mod.ts"; +import * as U from "../util/mod.ts"; + +const root = C.rpcCall(C.polkadot, "rpc_methods", []); + +console.log(U.throwIfError(await root.run())); diff --git a/effect/examples/subscription.ts b/examples/rpc_subscription.ts similarity index 69% rename from effect/examples/subscription.ts rename to examples/rpc_subscription.ts index b503b47d4..d588c9841 100644 --- a/effect/examples/subscription.ts +++ b/examples/rpc_subscription.ts @@ -1,12 +1,11 @@ -import * as C from "../../mod.ts"; -import * as t from "../../test-util/mod.ts"; -import * as U from "../../util/mod.ts"; +import * as C from "../mod.ts"; +import * as t from "../test-util/mod.ts"; +import * as U from "../util/mod.ts"; const config = await t.config(); const root = C.rpcSubscription(config, "chain_subscribeNewHead", [], (stop) => { let i = 0; - return (m) => { i++; if (i > 5) { diff --git a/examples/those_of_subxt/read_bonded.ts b/examples/those_of_subxt/read_bonded.ts index 5e14e282e..6a3ae272b 100644 --- a/examples/those_of_subxt/read_bonded.ts +++ b/examples/those_of_subxt/read_bonded.ts @@ -5,6 +5,7 @@ import * as U from "../../util/mod.ts"; const config = await t.config(); const aliceStash = t.alice.derive("//stash"); + const aliceBonded = C.readEntry(config, "Staking", "Bonded", [aliceStash.publicKey]); console.log(U.throwIfError(await aliceBonded.run())); diff --git a/examples/those_of_subxt/read_era_rewards.ts b/examples/those_of_subxt/read_era_rewards.ts index e15de64bd..8ce05a802 100644 --- a/examples/those_of_subxt/read_era_rewards.ts +++ b/examples/those_of_subxt/read_era_rewards.ts @@ -1,10 +1,10 @@ import * as C from "../../mod.ts"; import * as U from "../../util/mod.ts"; -const idx = C - .readEntry(C.polkadot, "Staking", "ActiveEra", []) +const idx = C.readEntry(C.polkadot, "Staking", "ActiveEra", []) .select("value") .select("index"); + const eraRewardPoints = C.readEntry(C.polkadot, "Staking", "ErasRewardPoints", [idx]); console.log(U.throwIfError(await eraRewardPoints.run())); diff --git a/effect/examples/ticker.ts b/examples/ticker.ts similarity index 65% rename from effect/examples/ticker.ts rename to examples/ticker.ts index 025bb19e9..8033bb0f8 100644 --- a/effect/examples/ticker.ts +++ b/examples/ticker.ts @@ -1,12 +1,11 @@ -import * as C from "../../mod.ts"; -import * as t from "../../test-util/mod.ts"; -import * as U from "../../util/mod.ts"; +import * as C from "../mod.ts"; +import * as t from "../test-util/mod.ts"; +import * as U from "../util/mod.ts"; const config = await t.config(); const root = C.watchEntry(config, "Timestamp", "Now", [], () => { let i = 0; - return (m) => { console.log({ [i]: m }); i++; diff --git a/examples/transfer.ts b/examples/transfer.ts index ec87b5af9..4a85997f2 100644 --- a/examples/transfer.ts +++ b/examples/transfer.ts @@ -2,29 +2,30 @@ import * as C from "../mod.ts"; import * as t from "../test-util/mod.ts"; import * as U from "../util/mod.ts"; -const config = await t.config(); +const config = await t.config({ altRuntime: "westend" }); -const root = C - .chain(config) - .pallet("Balances") - .extrinsic("transfer") - .call({ +const root = C.sendAndWatchExtrinsic({ + config, + sender: { + type: "Id", + value: t.alice.publicKey, + }, + palletName: "Balances", + methodName: "transfer", + args: { value: 12345n, dest: { type: "Id", value: t.bob.publicKey, }, - }) - .signed({ - type: "Id", - value: t.alice.publicKey, - }, (message) => { + }, + sign(message) { return { type: "Sr25519", value: t.alice.sign(message), }; - }) - .sendAndWatch((stop) => { + }, + createWatchHandler(stop) { return (event) => { if (typeof event.params.result === "string") { console.log("Extrinsic", event.params.result); @@ -40,7 +41,8 @@ const root = C } } }; - }); + }, +}); U.throwIfError(await root.run()); diff --git a/examples/watch_blocks.ts b/examples/watch_blocks.ts index 43c991f8c..64f845563 100644 --- a/examples/watch_blocks.ts +++ b/examples/watch_blocks.ts @@ -1,14 +1,15 @@ import * as C from "../mod.ts"; +import * as U from "../util/mod.ts"; -console.log( - await C.watchBlocks(C.westend, (stop) => { - let i = 0; - return ({ block }) => { - console.log(block.header); - if (i === 2) { - stop(); - } - i++; - }; - }).run(), -); +const root = C.watchBlocks(C.westend, (stop) => { + let i = 0; + return ({ block }) => { + console.log(block.header); + if (i === 2) { + stop(); + } + i++; + }; +}); + +U.throwIfError(await root.run()); diff --git a/examples/watch_events.ts b/examples/watch_events.ts index d7a833a21..90cc042ec 100644 --- a/examples/watch_events.ts +++ b/examples/watch_events.ts @@ -1,19 +1,15 @@ import * as C from "../mod.ts"; import * as U from "../util/mod.ts"; -const root = C - .chain(C.westend) - .pallet("System") - .entry("Events") - .watch((stop) => { - let i = 0; - return (event) => { - i++; - console.log(event); - if (i === 5) { - stop(); - } - }; - }); +const root = C.watchEntry(C.rococo, "System", "Events", [], (stop) => { + let i = 0; + return (event) => { + i++; + console.log(event); + if (i === 5) { + stop(); + } + }; +}); U.throwIfError(await root.run()); diff --git a/fluent/Block.ts b/fluent/Block.ts deleted file mode 100644 index 0081974e6..000000000 --- a/fluent/Block.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as Z from "../effect/mod.ts"; -import { HashHexString } from "../util/mod.ts"; -import { Chain } from "./Chain.ts"; -import { NodeBase } from "./common.ts"; - -export class Block extends NodeBase<"Block"> { - constructor( - readonly chain: C, - readonly hash?: HashHexString, - ) { - super(); - } - - read() { - return Z.readBlock(this.chain.config as any, this.hash); - } -} diff --git a/fluent/Call.ts b/fluent/Call.ts deleted file mode 100644 index 973e8f56d..000000000 --- a/fluent/Call.ts +++ /dev/null @@ -1,37 +0,0 @@ -import * as M from "../frame_metadata/mod.ts"; -import { NodeBase } from "./common.ts"; -import { Extrinsic } from "./Extrinsic.ts"; -import { Signed } from "./Signed.ts"; - -// TODO: constraint `Props` according to metadata -export class Call< - E extends Extrinsic = Extrinsic, - Args extends Record = Record, -> extends NodeBase<"Call"> { - chain; - - constructor( - readonly extrinsic: E, - readonly args: Args, - readonly options?: CallOptions, - ) { - super(); - this.chain = extrinsic.chain; - } - - signed( - from: M.MultiAddress, - sign: M.SignExtrinsic, - ): Signed { - return new Signed(this, from, sign); - } - - declare send: () => any; -} - -export interface CallOptions { - checkpoint?: string; - mortality?: [period: bigint, phase: bigint]; - tip?: bigint; - nonce?: number; -} diff --git a/fluent/Chain.ts b/fluent/Chain.ts deleted file mode 100644 index 047414295..000000000 --- a/fluent/Chain.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Config } from "../config/mod.ts"; -import { HashHexString } from "../util/mod.ts"; -import { Block } from "./Block.ts"; -import { NodeBase } from "./common.ts"; -import { Header } from "./Header.ts"; -import { Metadata } from "./Metadata.ts"; -import { Pallet } from "./Pallet.ts"; - -export class Chain extends NodeBase<"Chain"> { - chain; - - constructor(readonly config: B) { - super(); - this.chain = this; - } - - block(hash?: HashHexString): Block { - return new Block(this, hash); - } - - metadata(): Metadata { - return new Metadata(this); - } - - pallet(name: Name): Pallet { - return new Pallet(this, name); - } - - head(): Header { - return new Header(this); - } -} -export const chain = (config: B): Chain => { - return new Chain(config); -}; diff --git a/fluent/Entry.ts b/fluent/Entry.ts deleted file mode 100644 index 6e42f2a1d..000000000 --- a/fluent/Entry.ts +++ /dev/null @@ -1,50 +0,0 @@ -import * as Z from "../effect/mod.ts"; -import * as U from "../util/mod.ts"; -import { Block } from "./Block.ts"; -import { NodeBase } from "./common.ts"; -import { KeyPage } from "./KeyPage.ts"; -import { Pallet } from "./Pallet.ts"; - -export class Entry< - P extends Pallet = Pallet, - Name extends string = string, - Keys extends unknown[] = unknown[], // TODO: constrain -> extends NodeBase<"Entry"> { - chain; - keys; - - constructor( - readonly pallet: P, - readonly name: Name, - ...keys: Keys - ) { - super(); - this.chain = pallet.chain; - this.keys = keys; - } - - keyPage(count: number, ...start: unknown[]) { - return new KeyPage(this as any, count, ...start); - } - - read(block?: Block) { - return Z.readEntry( - // TODO: better typings on `chain.config` - this.pallet.chain.config as any, - this.pallet.name, - this.name, - this.keys, - block?.hash, - ); - } - - watch(createWatchHandler: U.CreateWatchHandler) { - return Z.watchEntry( - this.chain.config as any, - this.pallet.name, - this.name, - this.keys, - createWatchHandler, - ); - } -} diff --git a/fluent/Extrinsic.ts b/fluent/Extrinsic.ts deleted file mode 100644 index 5f5f56fbf..000000000 --- a/fluent/Extrinsic.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { Call, CallOptions } from "./Call.ts"; -import { NodeBase } from "./common.ts"; -import { Pallet } from "./Pallet.ts"; - -// TODO: narrow extrinsic according to config -export class Extrinsic< - P extends Pallet = Pallet, - Name extends string = string, -> extends NodeBase<"Extrinsic"> { - chain; - - constructor( - readonly pallet: P, - readonly name: Name, - ) { - super(); - this.chain = pallet.chain; - } - - call>( - args: Args, - callOptions?: CallOptions, - ): Call { - return new Call(this, args, callOptions); - } -} diff --git a/fluent/Header.ts b/fluent/Header.ts deleted file mode 100644 index 4233b7dc1..000000000 --- a/fluent/Header.ts +++ /dev/null @@ -1,16 +0,0 @@ -import * as Z from "../effect/mod.ts"; -import { Block } from "./Block.ts"; -import { Chain } from "./Chain.ts"; -import { NodeBase } from "./common.ts"; - -export class Header extends NodeBase<"Header"> { - constructor(readonly chain: C) { - super(); - } - - read(block?: Block) { - return Z.rpcCall(this.chain.config, "chain_getHeader", [block?.hash]); - } - - declare watch: (cb: (message: unknown) => void) => any; -} diff --git a/fluent/KeyPage.ts b/fluent/KeyPage.ts deleted file mode 100644 index cac85b9ee..000000000 --- a/fluent/KeyPage.ts +++ /dev/null @@ -1,33 +0,0 @@ -import * as Z from "../effect/mod.ts"; -import { Block } from "./Block.ts"; -import { NodeBase } from "./common.ts"; -import { Entry } from "./Entry.ts"; - -// TODO: constrain to map entry / key types -export class KeyPage extends NodeBase<"KeyPage"> { - chain; - start; - - constructor( - readonly entry: E, - readonly count: number, - ...start: unknown[] - ) { - super(); - this.chain = entry.chain; - this.start = start; - } - - read(block?: Block) { - return Z.readKeyPage( - this.chain.config as any, - this.entry.pallet.name, - this.entry.name, - this.count, - this.start, - block?.hash, - ); - } - - // declare watch: (cb: (message: unknown) => void) => any; -} diff --git a/fluent/Metadata.ts b/fluent/Metadata.ts deleted file mode 100644 index 222be78b3..000000000 --- a/fluent/Metadata.ts +++ /dev/null @@ -1,14 +0,0 @@ -import * as Z from "../effect/mod.ts"; -import { Block } from "./Block.ts"; -import { Chain } from "./Chain.ts"; -import { NodeBase } from "./common.ts"; - -export class Metadata extends NodeBase<"Metadata"> { - constructor(readonly chain: C) { - super(); - } - - read(block?: Block) { - return Z.metadata(this.chain.config as any, block?.hash); - } -} diff --git a/fluent/Pallet.ts b/fluent/Pallet.ts deleted file mode 100644 index f6e611209..000000000 --- a/fluent/Pallet.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Chain } from "./Chain.ts"; -import { NodeBase } from "./common.ts"; -import { Entry } from "./Entry.ts"; -import { Extrinsic } from "./Extrinsic.ts"; - -// TODO: constrain against `Chain` upon encoding FRAME metadata -export class Pallet< - C extends Chain = Chain, - Name extends string = string, -> extends NodeBase<"Pallet"> { - constructor( - readonly chain: C, - readonly name: Name, - ) { - super(); - } - - // TODO: constrain - entry< - Name extends string, - // TODO: constrain - Keys extends unknown[], - >( - name: Name, - ...keys: Keys - ): Entry { - return new Entry(this, name, ...keys); - } - - // TODO: constrain - extrinsic(name: Name): Extrinsic { - return new Extrinsic(this, name); - } -} diff --git a/fluent/Signed.ts b/fluent/Signed.ts deleted file mode 100644 index 6d4ee25e7..000000000 --- a/fluent/Signed.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { - sendAndWatchExtrinsic, - SendAndWatchExtrinsicConfig, -} from "../effect/std/submitAndWatchExtrinsic.ts"; -import * as M from "../frame_metadata/mod.ts"; -import * as rpc from "../rpc/mod.ts"; -import * as U from "../util/mod.ts"; -import { Call } from "./Call.ts"; -import { NodeBase } from "./common.ts"; - -export class Signed extends NodeBase<"Signed"> { - chain; - - constructor( - readonly call: C, - readonly from: M.MultiAddress, - readonly sign: M.SignExtrinsic, - ) { - super(); - this.chain = call.chain; - } - - sendAndWatch( - createWatchHandler: U.CreateWatchHandler< - rpc.NotifMessage - >, - ) { - return sendAndWatchExtrinsic({ - config: this.chain.config as any, - palletName: this.call.extrinsic.pallet.name, - methodName: this.call.extrinsic.name, - args: this.call.args, - sender: this.from, - sign: this.sign, - createWatchHandler, - }); - } -} diff --git a/fluent/common.ts b/fluent/common.ts deleted file mode 100644 index 000b932ad..000000000 --- a/fluent/common.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Chain } from "./Chain.ts"; - -declare const kind_: unique symbol; - -export abstract class NodeBase { - declare readonly [kind_]: Kind; - abstract chain: Chain; -} diff --git a/fluent/mod.ts b/fluent/mod.ts deleted file mode 100644 index 17de33496..000000000 --- a/fluent/mod.ts +++ /dev/null @@ -1,10 +0,0 @@ -export * from "./Block.ts"; -export * from "./Call.ts"; -export * from "./Chain.ts"; -export * from "./Entry.ts"; -export * from "./Extrinsic.ts"; -export * from "./Header.ts"; -export * from "./KeyPage.ts"; -export * from "./Metadata.ts"; -export * from "./Pallet.ts"; -export * from "./Signed.ts"; diff --git a/frame_metadata/Codec.test.ts b/frame_metadata/Codec.test.ts index e53a86f85..d379d0556 100644 --- a/frame_metadata/Codec.test.ts +++ b/frame_metadata/Codec.test.ts @@ -42,9 +42,8 @@ Deno.test("Derive AccountInfo Codec", async () => { Deno.test("Derive Auctions AuctionInfo Storage Entry Codec", async () => { const [metadata, deriveCodec] = await setup("polkadot"); - const auctionInfoStorageEntry = U.throwIfError( - getPalletAndEntry(metadata, "Auctions", "AuctionInfo"), - )[1]; + const auctionInfoStorageEntry = + U.throwIfError(getPalletAndEntry(metadata, "Auctions", "AuctionInfo"))[1]; const codec = deriveCodec(auctionInfoStorageEntry.value); const decoded = [8, 9945400]; const encoded = codec.encode(decoded); diff --git a/frame_metadata/Key.test.ts b/frame_metadata/Key.test.ts index 99b348816..d7695f304 100644 --- a/frame_metadata/Key.test.ts +++ b/frame_metadata/Key.test.ts @@ -7,7 +7,9 @@ import { setup } from "./test-common.ts"; Deno.test("System Accounts Key", async () => { const [metadata, deriveCodec] = await setup("polkadot"); - const [pallet, storageEntry] = U.throwIfError(getPalletAndEntry(metadata, "System", "Account")); + const systemAccountPalletAndEntry = getPalletAndEntry(metadata, "System", "Account"); + if (systemAccountPalletAndEntry instanceof Error) throw systemAccountPalletAndEntry; + const [pallet, storageEntry] = systemAccountPalletAndEntry; const $key = $storageKey({ deriveCodec, pallet, diff --git a/mod.ts b/mod.ts index e0393d6f4..9ec4a92eb 100644 --- a/mod.ts +++ b/mod.ts @@ -2,8 +2,7 @@ export * from "./config/mod.ts"; export * as $ from "./deps/scale.ts"; export { BitSequence } from "./deps/scale.ts"; export * from "./effect/mod.ts"; -export * from "./fluent/mod.ts"; export * as M from "./frame_metadata/mod.ts"; export { $era, $null, ChainError, type Era } from "./frame_metadata/mod.ts"; -export { kusama, moonbeam, polkadot, rococo, westend } from "./known/mod.ts"; +export { kusama, moonbeam, polkadot, rococo, westend } from "./known/mod.ts"; // TODO: get rid of this! export { type Handle, handle, hex, Iter, mapCreateWatchHandler } from "./util/mod.ts";