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

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed Mar 30, 2023
1 parent fe03b9c commit 7506d75
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions examples/dev/test_users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 5 additions & 4 deletions examples/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions examples/ink/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 12 additions & 13 deletions examples/misc/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 6 additions & 4 deletions examples/xcm/asset_teleportation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion fluent/ExtrinsicsEventsRune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ExtrinsicEventsRune<out C extends Chain, out U> extends EventsRune<
}

export class ExtrinsicError<D extends { type: string }> extends Error {
override readonly name = "DispatchError"
override readonly name = "ExtrinsicError"

constructor(data: D) {
super(data.type)
Expand Down
4 changes: 2 additions & 2 deletions patterns/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface NarrowIdentityInfo<A extends Record<string, unknown>> {
export class IdentityInfoTranscoders<A extends Record<string, any>> {
constructor(readonly additionalCodecs?: { [K in keyof A]: $.Codec<A[K]> }) {}

encode = <X>(props: RunicArgs<X, NarrowIdentityInfo<A>>) => {
encode<X>(props: RunicArgs<X, NarrowIdentityInfo<A>>) {
const { additionalCodecs } = this
const additional = additionalCodecs
? Rune
Expand Down Expand Up @@ -52,7 +52,7 @@ export class IdentityInfoTranscoders<A extends Record<string, any>> {
}))
}

decode = <X>(...[identityInfo]: RunicArgs<X, [IdentityInfo]>) => {
decode<X>(...[identityInfo]: RunicArgs<X, [IdentityInfo]>) {
const { additionalCodecs } = this
return Rune
.resolve(identityInfo)
Expand Down

0 comments on commit 7506d75

Please sign in to comment.