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

chore: remove fluent api and clean up examples #254

Merged
merged 4 commits into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions deps/polkadot/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "https://deno.land/x/[email protected]/types/mod.ts";
11 changes: 0 additions & 11 deletions effect/examples/balance.ts

This file was deleted.

11 changes: 0 additions & 11 deletions effect/examples/first_ten_keys.ts

This file was deleted.

11 changes: 0 additions & 11 deletions effect/examples/metadata.ts

This file was deleted.

6 changes: 0 additions & 6 deletions effect/examples/read_block.ts

This file was deleted.

49 changes: 0 additions & 49 deletions effect/examples/transfer.ts

This file was deleted.

16 changes: 0 additions & 16 deletions effect/examples/watch_blocks.ts

This file was deleted.

2 changes: 1 addition & 1 deletion effect/extrinsic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } } });
},
Expand Down
14 changes: 7 additions & 7 deletions examples/balance.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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)
.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()));
const result = await root.run();

if (result instanceof Error) {
throw result;
}
console.log(result);

config.close();
14 changes: 0 additions & 14 deletions examples/block.ts

This file was deleted.

11 changes: 8 additions & 3 deletions effect/examples/derived.ts → examples/derived.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import * as C from "../../mod.ts";
import * as U from "../../util/mod.ts";
import * as C from "../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]);
});
return C.all(...heads);
});

console.log(U.throwIfError(await root.run()));
const result = await root.run();

if (result instanceof Error) {
throw result;
}
console.log(result);
10 changes: 0 additions & 10 deletions examples/events.ts

This file was deleted.

15 changes: 7 additions & 8 deletions examples/first_ten_keys.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
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)
.pallet("System")
.entry("Account")
.keyPage(10)
.read();
const root = C.readKeyPage(config, "System", "Account", 10);

console.log(U.throwIfError(await root.run()));
const result = await root.run();

if (result instanceof Error) {
throw result;
}
console.log(result.keys);

config.close();
13 changes: 7 additions & 6 deletions examples/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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)
.metadata()
.read();
const root = C.metadata(config);

console.log(U.throwIfError(await root.run()));
const result = await root.run();

if (result instanceof Error) {
throw result;
}
console.log(result);

config.close();
Empty file removed examples/playground.ts
Empty file.
61 changes: 33 additions & 28 deletions examples/polkadot_signer.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
import { TypeRegistry } from "https://deno.land/x/polkadot@0.0.8/types/mod.ts";
harrysolovay marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand All @@ -45,9 +42,17 @@ const root = C
stop();
} else {
console.log("Misc", event.params.result);
stop();
}
}
};
});
},
});

const maybeError = await root.run();

if (maybeError instanceof Error) {
throw maybeError;
}

U.throwIfError(await root.run());
config.close();
13 changes: 13 additions & 0 deletions examples/raw_rpc_client/call.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as C from "../../mod.ts";
import * as rpc from "../../rpc/mod.ts";

const client = await rpc.stdClient(C.westend);
if (client instanceof Error) {
throw client;
}

const result = await client.call("state_getMetadata", []);

console.log(result);

await client.close();
22 changes: 22 additions & 0 deletions examples/raw_rpc_client/subscription.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as C from "../../mod.ts";
import * as rpc from "../../rpc/mod.ts";

const client = await rpc.stdClient(C.westend);
if (client instanceof Error) {
throw client;
}

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);
}
10 changes: 10 additions & 0 deletions examples/read_block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as C from "../mod.ts";

const root = C.readBlock(C.polkadot);

const result = await root.run();

if (result instanceof Error) {
throw result;
}
console.log(result);
10 changes: 10 additions & 0 deletions examples/read_events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as C from "../mod.ts";

const root = C.readEntry(C.westend, "System", "Events", []);

const result = await root.run();

if (result instanceof Error) {
throw result;
}
console.log(result);
10 changes: 0 additions & 10 deletions examples/rpc/call.ts

This file was deleted.

Loading