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 authored and ryanleecode committed May 4, 2023
1 parent a0f218a commit 2877080
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 12 additions & 2 deletions examples/sign/offline.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Finally, rehydrate the extrinsic and submit it.
*/

import { westendDev } from "@capi/westend-dev"
import { $runtimeCall, westendDev } from "@capi/westend-dev"
import { $, createDevUsers, SignedExtrinsicRune } from "capi"
import { signature } from "capi/patterns/signature/polkadot.ts"

Expand All @@ -25,7 +25,17 @@ const hex = await westendDev.Balances
/// writing to disk, etc.).
save(hex)

/// Hydrate the signed extrinsic, submit it and await finalization.
/// Hydrate the signed extrinsic.
const signedExtrinsic = SignedExtrinsicRune.fromHex(westendDev, hex)

/// Decode the signed extrinsic.
const decoded = await signedExtrinsic.extrinsic().run()

/// Ensure the call data is what we expect.
console.log(decoded)
$.assert($runtimeCall, decoded.call)

/// Submit it and await finalization.
const hash = await SignedExtrinsicRune
.fromHex(westendDev, hex)
.sent()
Expand Down
8 changes: 5 additions & 3 deletions fluent/SignedExtrinsicRune.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { hex } from "../crypto/mod.ts"
import { $extrinsic } from "../mod.ts"
import { $extrinsic } from "../frame_metadata/mod.ts"
import { Rune, RunicArgs, ValueRune } from "../rune/mod.ts"
import { Chain, ChainRune } from "./ChainRune.ts"
import { CodecRune } from "./CodecRune.ts"
import { ExtrinsicStatusRune } from "./ExtrinsicStatusRune.ts"
import { PatternRune } from "./PatternRune.ts"

export class SignedExtrinsicRune<out C extends Chain, out U> extends PatternRune<Uint8Array, C, U> {
$extrinsic = Rune.fn($extrinsic).call(this.chain.metadata).into(CodecRune)

static from<C extends Chain, U, X>(
chain: ChainRune<C, U>,
...[value]: RunicArgs<X, [value: Uint8Array]>
Expand All @@ -21,8 +24,7 @@ export class SignedExtrinsicRune<out C extends Chain, out U> extends PatternRune
}

extrinsic() {
return Rune.tuple([this.chain.metadata, this.into(ValueRune)])
.map(([metadata, bytes]) => $extrinsic(metadata).decode(bytes))
return this.$extrinsic.decoded(this.as(SignedExtrinsicRune))
}

hex() {
Expand Down

0 comments on commit 2877080

Please sign in to comment.