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

Commit

Permalink
refactor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysolovay committed May 5, 2023
1 parent 8408261 commit 5fc0645
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
8 changes: 4 additions & 4 deletions examples/sign/offline.eg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ save(hex)
/// Hydrate the signed extrinsic.
const signedExtrinsic = SignedExtrinsicRune.fromHex(westendDev, hex)

/// Decode the signed extrinsic.
const decoded = await signedExtrinsic.extrinsic().run()
/// Get an `ExtrinsicRune` (resolves to call data) from the `SignedExtrinsicRune`.
const extrinsic = await signedExtrinsic.unsigned().run()

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

/// Submit it and await finalization.
const hash = await SignedExtrinsicRune
Expand Down
7 changes: 1 addition & 6 deletions fluent/BlockRune.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { hex } from "../crypto/mod.ts"
import { $extrinsic } from "../frame_metadata/Extrinsic.ts"
import { known } from "../rpc/mod.ts"
import { ArrayRune, Rune } from "../rune/mod.ts"
import { ValueRune } from "../rune/ValueRune.ts"
import { BlockHashRune } from "./BlockHashRune.ts"
import { Chain } from "./ChainRune.ts"
import { CodecRune } from "./CodecRune.ts"
import { EventsRune } from "./EventsRune.ts"
import { PatternRune } from "./PatternRune.ts"

Expand All @@ -23,13 +21,10 @@ export class BlockRune<out C extends Chain, out U>
}

extrinsics() {
const $ext = Rune.fn($extrinsic)
.call(this.chain.metadata)
.into(CodecRune)
return this
.extrinsicsRaw()
.into(ArrayRune)
.mapArray((h) => $ext.decoded(h.map(hex.decode)))
.mapArray((h) => this.chain.$extrinsic.decoded(h.map(hex.decode)))
}

events() {
Expand Down
19 changes: 6 additions & 13 deletions fluent/ExtrinsicRune.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { blake2_256, hex } from "../crypto/mod.ts"
import * as $ from "../deps/scale.ts"
import { concat } from "../deps/std/bytes.ts"
import { $extrinsic, Signer } from "../frame_metadata/Extrinsic.ts"
import { Signer } from "../frame_metadata/Extrinsic.ts"
import { Rune, RunicArgs, ValueRune } from "../rune/mod.ts"
import { Chain, ChainRune } from "./ChainRune.ts"
import { CodecRune } from "./CodecRune.ts"
Expand Down Expand Up @@ -48,21 +48,14 @@ export class ExtrinsicRune<out C extends Chain, out U> extends PatternRune<Chain
}

encoded() {
return Rune
.fn($extrinsic)
.call(this.chain.metadata)
.into(CodecRune)
.encoded(Rune.object({
protocolVersion: ExtrinsicRune.PROTOCOL_VERSION,
call: this,
}))
return this.chain.$extrinsic.encoded(Rune.object({
protocolVersion: ExtrinsicRune.PROTOCOL_VERSION,
call: this,
}))
}

feeEstimate() {
const extrinsic = this.chain.$extrinsic.encoded(Rune.object({
protocolVersion: 4,
call: this,
}))
const extrinsic = this.encoded()
const arg = Rune
.fn(concat)
.call(extrinsic, extrinsic.access("length").map((n) => $.u32.encode(n)))
Expand Down
7 changes: 6 additions & 1 deletion fluent/SignedExtrinsicRune.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { hex } from "../crypto/mod.ts"
import { Rune, RunicArgs, ValueRune } from "../rune/mod.ts"
import { Chain, ChainRune } from "./ChainRune.ts"
import { ExtrinsicRune } from "./ExtrinsicRune.ts"
import { ExtrinsicStatusRune } from "./ExtrinsicStatusRune.ts"
import { PatternRune } from "./PatternRune.ts"

Expand All @@ -19,10 +20,14 @@ export class SignedExtrinsicRune<out C extends Chain, out U> extends PatternRune
return this.from(chain, Rune.resolve(value).map(hex.decode))
}

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

unsigned() {
return this.decoded().access("call").into(ExtrinsicRune, this.chain)
}

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

0 comments on commit 5fc0645

Please sign in to comment.