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

feat: add call method to SignedExtrinsicRune #952

Merged
merged 9 commits into from
May 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: 8 additions & 0 deletions fluent/SignedExtrinsicRune.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { hex } from "../crypto/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)
harrysolovay marked this conversation as resolved.
Show resolved Hide resolved

static from<C extends Chain, U, X>(
chain: ChainRune<C, U>,
...[value]: RunicArgs<X, [value: Uint8Array]>
Expand All @@ -19,6 +23,10 @@ export class SignedExtrinsicRune<out C extends Chain, out U> extends PatternRune
return this.from(chain, Rune.resolve(value).map(hex.decode))
}

extrinsic() {
return this.$extrinsic.decoded(this.as(SignedExtrinsicRune))
}

hex() {
return this.into(ValueRune).map(hex.encode)
}
Expand Down