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

chore: get rid of known dir #380

Merged
merged 3 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 _tasks/download_frame_metadata.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import * as fs from "../deps/std/fs.ts";
import * as path from "../deps/std/path.ts";
import * as Z from "../deps/zones.ts";
import * as knownClients from "../known/clients.ts";
import * as C from "../mod.ts";
import * as U from "../util/mod.ts";

const outDir = path.join(Deno.cwd(), "frame_metadata", "_downloaded");
await fs.emptyDir(outDir);
U.throwIfError(await Z.ls(...Object.entries(knownClients).map(download)).run());
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],
Expand Down
7 changes: 3 additions & 4 deletions effects/blockWatch.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import * as Z from "../deps/zones.ts";
import * as known from "../known/mod.ts";
import * as rpc from "../rpc/mod.ts";
import * as U from "../util/mod.ts";
import { chain } from "./rpc_known.ts";
import { chain } from "./rpc_known_methods.ts";

const k0_ = Symbol();

export function blockWatch<Client extends Z.$<rpc.Client>>(client: Client) {
return <
Listener extends Z.$<U.Listener<known.SignedBlock, BlockWatchListenerContext>>,
Listener extends Z.$<U.Listener<rpc.known.SignedBlock, BlockWatchListenerContext>>,
>(listener: Listener) => {
const listenerMapped = Z
.ls(listener, Z.env)
.next(([listener, env]) => {
return async function(this: rpc.ClientSubscribeContext, header: known.Header) {
return async function(this: rpc.ClientSubscribeContext, header: rpc.known.Header) {
const blockHash = chain.getBlockHash(client)(header.number);
const block = await chain.getBlock(client)(blockHash).bind(env)();
// TODO: return error with `this.stop` once implemented
Expand Down
2 changes: 1 addition & 1 deletion effects/entryRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Z from "../deps/zones.ts";
import * as rpc from "../rpc/mod.ts";
import * as U from "../util/mod.ts";
import { entryMetadata, metadata, palletMetadata } from "./metadata.ts";
import { state } from "./rpc_known.ts";
import { state } from "./rpc_known_methods.ts";
import * as scale from "./scale.ts";

export function entryRead<Client extends Z.$<rpc.Client>>(client: Client) {
Expand Down
7 changes: 3 additions & 4 deletions effects/entryWatch.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as Z from "../deps/zones.ts";
import * as known from "../known/mod.ts";
import * as rpc from "../rpc/mod.ts";
import * as U from "../util/mod.ts";
import { entryMetadata, metadata, palletMetadata } from "./metadata.ts";
import { state } from "./rpc_known.ts";
import { state } from "./rpc_known_methods.ts";
import * as scale from "./scale.ts";

export type WatchEntryEvent = [key?: unknown, value?: unknown];
Expand Down Expand Up @@ -35,11 +34,11 @@ export function entryWatch<Client extends Z.$<rpc.Client>>(client: Client) {
const listenerMapped = Z.ls($entry, listener).next(([$entry, listener]) => {
return function listenerMapped(
this: rpc.ClientSubscribeContext,
changeset: known.StorageChangeSet,
changeset: rpc.known.StorageChangeSet,
) {
// TODO: in some cases there might be keys to decode
// key ? $storageKey.decode(U.hex.decode(key)) : undefined
const getKey = (key: known.Hex) => {
const getKey = (key: rpc.known.Hex) => {
return key;
};
const changes: WatchEntryEvent[] = changeset.changes.map(([key, val]) => {
Expand Down
4 changes: 2 additions & 2 deletions effects/events.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Z from "../deps/zones.ts";
import * as known from "../known/mod.ts";
import { known } from "../rpc/mod.ts";
import { entryRead } from "./entryRead.ts";
import { SignedExtrinsic } from "./extrinsic.ts";
import { chain } from "./rpc_known.ts";
import { chain } from "./rpc_known_methods.ts";

const k1_ = Symbol();
const k2_ = Symbol();
Expand Down
7 changes: 3 additions & 4 deletions effects/extrinsic.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { unimplemented } from "../deps/std/testing/asserts.ts";
import * as Z from "../deps/zones.ts";
import * as M from "../frame_metadata/mod.ts";
import * as known from "../known/mod.ts";
import * as rpc from "../rpc/mod.ts";
import * as ss58 from "../ss58/mod.ts";
import * as U from "../util/mod.ts";
import { const as const_ } from "./const.ts";
import { metadata } from "./metadata.ts";
import { author, chain, system } from "./rpc_known.ts";
import { author, chain, system } from "./rpc_known_methods.ts";
import * as scale from "./scale.ts";

const k0_ = Symbol();
Expand Down Expand Up @@ -117,7 +116,7 @@ export class SignedExtrinsic<
this.extrinsicDecoded = scale.scaleDecoded($extrinsic_, this.extrinsicBytes, "extrinsic");
}

watch<Listener extends Z.$<U.Listener<known.TransactionStatus, rpc.ClientSubscribeContext>>>(
watch<Listener extends Z.$<U.Listener<rpc.known.TransactionStatus, rpc.ClientSubscribeContext>>>(
listener: Listener,
) {
const subscriptionId = author.submitAndWatchExtrinsic(this.client)(
Expand All @@ -136,7 +135,7 @@ export class SignedExtrinsic<
// TODO: attach to extrinsics sent.finalized result once zones-level method addition implemented
export function extrinsicsDecoded<
Client extends Z.$<rpc.Client>,
Hexes extends Z.$<known.Hex[]>,
Hexes extends Z.$<rpc.known.Hex[]>,
>(
client: Client,
hexes: Hexes,
Expand Down
2 changes: 1 addition & 1 deletion effects/keyPageRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Z from "../deps/zones.ts";
import * as rpc from "../rpc/mod.ts";
import * as U from "../util/mod.ts";
import { mapMetadata, metadata, palletMetadata } from "./metadata.ts";
import { state } from "./rpc_known.ts";
import { state } from "./rpc_known_methods.ts";
import * as scale from "./scale.ts";

const k0_ = Symbol();
Expand Down
2 changes: 1 addition & 1 deletion effects/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Z from "../deps/zones.ts";
import * as M from "../frame_metadata/mod.ts";
import * as rpc from "../rpc/mod.ts";
import * as U from "../util/mod.ts";
import { state } from "./rpc_known.ts";
import { state } from "./rpc_known_methods.ts";

const k0_ = Symbol();
const k1_ = Symbol();
Expand Down
4 changes: 3 additions & 1 deletion effects/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ export * from "./extrinsic.ts";
export * from "./keyPageRead.ts";
export * from "./metadata.ts";
export * from "./rpc.ts";
export * from "./rpc_known.ts";
export * as knownClients from "./rpc_known_clients.ts";
export * from "./rpc_known_clients.ts";
export * from "./rpc_known_methods.ts";
export * from "./scale.ts";
7 changes: 4 additions & 3 deletions effects/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export function rpcSubscription<Params extends unknown[], Result>() {
this.stop();
} else if (e.error) {
error = new RpcServerError(e);
console.log(e);
this.stop();
} else {
// TODO: halt if returns `Error` | `Promise<Error>`?
Expand Down Expand Up @@ -110,9 +111,9 @@ async function discardCheck<CloseErrorData>(
}

export class RpcServerError extends Error {
override readonly name = "RpcServerError";
override readonly name = "RpcServer";

constructor(override readonly cause: rpc.msg.ErrorMessage) {
super("An error was received from the RPC server.");
constructor(readonly inner: rpc.msg.ErrorMessage) {
super();
}
}
16 changes: 16 additions & 0 deletions effects/rpc_known_clients.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as rpc from "../rpc/mod.ts";
import { rpcClient } from "./rpc.ts";

// TODO: do we care to defer effect initialization (not very costly)
function proxyClient(url: string) {
return rpcClient(rpc.proxyProvider, url);
}

export const polkadot = proxyClient("wss://rpc.polkadot.io");
export const kusama = proxyClient("wss://kusama-rpc.polkadot.io");
export const acala = proxyClient("wss://acala-polkadot.api.onfinality.io/public-ws");
export const rococo = proxyClient("wss://rococo-contracts-rpc.polkadot.io");
export const moonbeam = proxyClient("wss://wss.api.moonbeam.network");
export const statemint = proxyClient("wss://statemint-rpc.polkadot.io");
export const subsocial = proxyClient("wss://para.subsocial.network");
export const westend = proxyClient("wss://westend-rpc.polkadot.io");
2 changes: 1 addition & 1 deletion effects/rpc_known.ts → effects/rpc_known_methods.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as known from "../known/mod.ts";
import { known } from "../rpc/mod.ts";
import * as U from "../util/mod.ts";
import { rpcCall, rpcSubscription } from "./rpc.ts";

Expand Down
2 changes: 1 addition & 1 deletion examples/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const tx = C.extrinsic(T.westend)({
.signed(C.compat.signerFromKeypair(T.alice))
.watch(function(status) {
console.log(status);
if (C.TransactionStatus.isTerminal(status)) {
if (C.rpc.known.TransactionStatus.isTerminal(status)) {
this.stop();
}
});
Expand Down
4 changes: 2 additions & 2 deletions examples/multisig_transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const existentialDeposit = extrinsic({
.signed(C.compat.signerFromKeypair(T.alice))
.watch(function(status) {
console.log(`Existential deposit:`, status);
if (C.TransactionStatus.isTerminal(status)) {
if (C.rpc.known.TransactionStatus.isTerminal(status)) {
this.stop();
}
});
Expand Down Expand Up @@ -102,7 +102,7 @@ function createOrApproveMultisigProposal<
.signed(C.compat.signerFromKeypair(pair))
.watch(function(status) {
console.log(`${label}:`, status);
if (C.TransactionStatus.isTerminal(status)) {
if (C.rpc.known.TransactionStatus.isTerminal(status)) {
this.stop();
}
});
Expand Down
2 changes: 1 addition & 1 deletion examples/polkadot_js_signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const root = C.extrinsic(T.westend)({
})
.watch(function(status) {
console.log(status);
if (C.TransactionStatus.isTerminal(status)) {
if (C.rpc.known.TransactionStatus.isTerminal(status)) {
this.stop();
}
});
Expand Down
7 changes: 3 additions & 4 deletions examples/transfer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Hash } from "../known/rpc/mod.ts";
import * as C from "../mod.ts";
import * as T from "../test_util/mod.ts";
import * as U from "../util/mod.ts";

let hash: undefined | Hash;
let hash: undefined | C.rpc.known.Hash;

const env = C.Z.env();

Expand All @@ -21,9 +20,9 @@ const tx = C.extrinsic(T.westend)({
const runTx = tx
.watch(function(status) {
console.log(status);
if (C.TransactionStatus.isTerminal(status)) {
if (C.rpc.known.TransactionStatus.isTerminal(status)) {
// TODO: return this upon implementing `this.stop`
hash = (status as { finalized: Hash }).finalized;
hash = (status as { finalized: C.rpc.known.Hash }).finalized;
this.stop();
}
})
Expand Down
14 changes: 0 additions & 14 deletions known/clients.ts

This file was deleted.

3 changes: 0 additions & 3 deletions known/mod.ts

This file was deleted.

68 changes: 0 additions & 68 deletions known/rpc.ts

This file was deleted.

1 change: 0 additions & 1 deletion mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ export {
MultiAddress,
type Signer,
} from "./frame_metadata/mod.ts";
export { kusama, moonbeam, polkadot, rococo, TransactionStatus, westend } from "./known/mod.ts"; // TODO: get rid of this!
export * as rpc from "./rpc/mod.ts";
export { contramapListener, hex, type Listener } from "./util/mod.ts";
2 changes: 1 addition & 1 deletion rpc/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as A from "../deps/std/testing/asserts.ts";
import * as known from "../known/mod.ts";
import * as T from "../test_util/mod.ts";
import * as U from "../util/mod.ts";
import * as known from "./known/mod.ts";
import * as msg from "./messages.ts";

Deno.test({
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions known/rpc/contracts.ts → rpc/known/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export type StorageDeposit = SerdeEnum<{
}>;

// https://github.com/paritytech/substrate/blob/622f532/frame/contracts/common/src/lib.rs#L118
/** Flags used by a contract to customize exit behaviour. */
/** Flags used by a contract to customize exit behavior. */
export enum ReturnFlags {
REVERT = 0x0000_0001,
}
Expand Down Expand Up @@ -202,7 +202,7 @@ export interface CodeUploadRequest {
}

// https://github.com/paritytech/substrate/blob/622f532/frame/contracts/common/src/lib.rs#L164
/** The result of succesfully uploading a contract. */
/** The result of successfully uploading a contract. */
export interface CodeUploadReturnValue {
/** The key under which the new code is stored. */
codeHash: Hash;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type StateMigrationRpc = {
* Check current migration state.
*
* This call is performed locally without submitting any transactions. Thus executing this
* won't change any state. Nonetheless it is a VERY costy call that should be
* won't change any state. Nonetheless it is a VERY costly call that should be
* only exposed to trusted peers.
*/
state_trieMigrationStatus(at?: Hash): RpcResult<MigrationStatusResult>;
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions rpc/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./client.ts";
export * as known from "./known/mod.ts";
export * as msg from "./messages.ts";
export * from "./provider/base.ts";
export * from "./provider/errors.ts";
Expand Down
Loading