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

Commit

Permalink
chore: remove fluent api and clean up examples (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay authored Oct 2, 2022
1 parent d143514 commit cb8610b
Show file tree
Hide file tree
Showing 44 changed files with 133 additions and 574 deletions.
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
6 changes: 1 addition & 5 deletions examples/balance.ts
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down
14 changes: 0 additions & 14 deletions examples/block.ts

This file was deleted.

5 changes: 3 additions & 2 deletions effect/examples/derived.ts → examples/derived.ts
Original file line number Diff line number Diff line change
@@ -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]);
Expand Down
9 changes: 2 additions & 7 deletions examples/first_ten_keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
5 changes: 1 addition & 4 deletions examples/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down
Empty file removed examples/playground.ts
Empty file.
54 changes: 28 additions & 26 deletions examples/polkadot_signer.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -45,9 +43,13 @@ const root = C
stop();
} else {
console.log("Misc", event.params.result);
stop();
}
}
};
});
},
});

U.throwIfError(await root.run());

config.close();
9 changes: 9 additions & 0 deletions examples/raw_rpc_client/call.ts
Original file line number Diff line number Diff line change
@@ -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();
20 changes: 20 additions & 0 deletions examples/raw_rpc_client/subscription.ts
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 1 addition & 5 deletions examples/events.ts → examples/read_block.ts
Original file line number Diff line number Diff line change
@@ -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()));
6 changes: 6 additions & 0 deletions examples/read_events.ts
Original file line number Diff line number Diff line change
@@ -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()));
10 changes: 0 additions & 10 deletions examples/rpc/call.ts

This file was deleted.

22 changes: 0 additions & 22 deletions examples/rpc/subscription.ts

This file was deleted.

6 changes: 6 additions & 0 deletions examples/rpc_call.ts
Original file line number Diff line number Diff line change
@@ -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()));
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
1 change: 1 addition & 0 deletions examples/those_of_subxt/read_bonded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
4 changes: 2 additions & 2 deletions examples/those_of_subxt/read_era_rewards.ts
Original file line number Diff line number Diff line change
@@ -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()));
Loading

0 comments on commit cb8610b

Please sign in to comment.