diff --git a/examples/dev/test_users.ts b/examples/dev/test_users.ts index 96740dad8..816cd2437 100644 --- a/examples/dev/test_users.ts +++ b/examples/dev/test_users.ts @@ -3,8 +3,8 @@ * @stability nearing * * When developing against a test chain, the `createUsers` utility - * provides `Sr25519` instances, which correspond to test users (pre-seeded with funds). - * This simplifies signing extrinsics for submission to the given test chain. + * provides `Sr25519` instances, which correspond to test users who are pre-seeded with + * funds. This simplifies signing extrinsics for submission to the given test chain. */ import { $, $sr25519 } from "capi" diff --git a/examples/dynamic.ts b/examples/dynamic.ts index 0b391ba6c..85b8f51f3 100644 --- a/examples/dynamic.ts +++ b/examples/dynamic.ts @@ -3,13 +3,14 @@ * @stability nearing * * You may want to write code whose target chain is unknown before runtime. A common - * example of this is block explorers. These use cases are "dynamic" and require the use - * of a subtly-different API. Compared to the chain-specific, codegened DX, the dynamic - * DX has three key difference: + * example of this is block explorers. Use cases such as this are "dynamic" in that they require + * one to read the chain's metadata at runtime in order to derive the means of interacting with + * that chain. Dynamic usage of Capi entails a subtly-different DX compared to that of chain-specific + * (codegen) usage. There are three key difference: * * 1. We manually initialize the `ChainRune`. * 2. We manually access bindings. - * 3. Chain-specifics are untyped (which makes them error-prone). + * 3. Chain-specifics are untyped (be wary to supply the correct data, as the checker is on vacation). */ import { $, ChainRune, SmoldotConnection, WsConnection } from "capi" diff --git a/examples/ink/deploy.ts b/examples/ink/deploy.ts index dff7eddac..fd61f3538 100644 --- a/examples/ink/deploy.ts +++ b/examples/ink/deploy.ts @@ -4,8 +4,7 @@ * in the near future. This work will likely entail large changes to the current ink patterns. * * Deploying an Ink contract (instantiating) to a production contracts-enabled parachain - * is much the same as any other extrinsic submission; it involves specifying the ink - * metadata, WebAssembly bytes and sender/signer. + * is much the same as any other extrinsic submission. */ import { $, alice, ss58 } from "capi" diff --git a/examples/misc/identity.ts b/examples/misc/identity.ts index c129ad6b4..75cc10a16 100644 --- a/examples/misc/identity.ts +++ b/examples/misc/identity.ts @@ -17,28 +17,27 @@ const { alexa } = await createUsers() // Initialize an `IdentityInfoTranscoders` of shape `{ stars: number }`. const transcoders = new IdentityInfoTranscoders({ stars: $.u8 }) -// Encode some identity info into the expected shape. -const info = transcoders.encode({ - display: "Chev Chelios", - additional: { stars: 5 }, -}) - -// Execute the identity-setting transaction. +// Encode some identity info into the expected shape and use it +// to execute the identity-setting transaction. await Identity - .setIdentity({ info }) + .setIdentity({ + info: transcoders.encode({ + display: "Chev Chelios", + additional: { stars: 5 }, + }), + }) .signed(signature({ sender: alexa })) .sent() .dbgStatus() .finalized() .run() -// Reference the raw identity info from the chain. -const infoRaw = Identity.IdentityOf +// Retrieve and decode the identity info. +const infoDecoded = await Identity.IdentityOf .value(alexa.publicKey) .unhandle(undefined) .access("info") - -// Retrieve and decode the identity info. -const infoDecoded = await transcoders.decode(infoRaw).run() + .pipe((raw) => transcoders.decode(raw)) + .run() $.assert($.u8, infoDecoded.additional.stars) diff --git a/examples/xcm/asset_teleportation.ts b/examples/xcm/asset_teleportation.ts index 97227b6fe..5f8835384 100644 --- a/examples/xcm/asset_teleportation.ts +++ b/examples/xcm/asset_teleportation.ts @@ -7,6 +7,7 @@ * balance of the user to whom the asset was transferred. */ +import { assert } from "asserts" import { alice, Rune } from "capi" import { signature } from "capi/patterns/signature/polkadot.ts" import { types, XcmPallet } from "zombienet/statemine.toml/alice/@latest/mod.js" @@ -34,7 +35,7 @@ const aliceBalance = System.Account .access("data", "free") // Read the initial free. -console.log("Alice balance before:", await aliceBalance.run()) +const aliceFreeInitial = await aliceBalance.run() XcmPallet .limitedTeleportAssets({ @@ -66,13 +67,14 @@ XcmPallet .run() // Iterate over the parachain events until receiving a downward message processed event, -// at which point we can read alice's balance, which should be updated. +// at which point we can read alice's free balance, which should be greater than the initial. outer: -for await (const e of System.Events.value(undefined, parachain.latestBlock.hash).iter()) { +for await (const e of System.Events.value(undefined, parachain.latestBlockHash).iter()) { if (e) { for (const { event } of e) { if (RuntimeEvent.isParachainSystem(event) && Event.isDownwardMessagesProcessed(event.value)) { - console.log("Alice balance after:", await aliceBalance.run()) + const aliceFreeFinal = await aliceBalance.run() + assert(aliceFreeFinal > aliceFreeInitial) break outer } } diff --git a/fluent/ExtrinsicsEventsRune.ts b/fluent/ExtrinsicsEventsRune.ts index 16d2f9b3b..80d16b6fc 100644 --- a/fluent/ExtrinsicsEventsRune.ts +++ b/fluent/ExtrinsicsEventsRune.ts @@ -42,7 +42,7 @@ export class ExtrinsicEventsRune extends EventsRune< } export class ExtrinsicError extends Error { - override readonly name = "DispatchError" + override readonly name = "ExtrinsicError" constructor(data: D) { super(data.type) diff --git a/patterns/identity.ts b/patterns/identity.ts index c3070c353..ef9a9c303 100644 --- a/patterns/identity.ts +++ b/patterns/identity.ts @@ -17,7 +17,7 @@ export interface NarrowIdentityInfo> { export class IdentityInfoTranscoders> { constructor(readonly additionalCodecs?: { [K in keyof A]: $.Codec }) {} - encode = (props: RunicArgs>) => { + encode(props: RunicArgs>) { const { additionalCodecs } = this const additional = additionalCodecs ? Rune @@ -52,7 +52,7 @@ export class IdentityInfoTranscoders> { })) } - decode = (...[identityInfo]: RunicArgs) => { + decode(...[identityInfo]: RunicArgs) { const { additionalCodecs } = this return Rune .resolve(identityInfo)