Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions fluent/ExtrinsicRune.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
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 { Rune, ValueRune } from "../rune/mod.ts"
import { Chain, ChainRune } from "./ChainRune.ts"
Expand All @@ -22,6 +24,8 @@ export type SignatureDataFactory<C extends Chain, CU, SU> = (
) => Rune<SignatureData<C>, SU>

export class ExtrinsicRune<out C extends Chain, out U> extends PatternRune<Chain.Call<C>, C, U> {
static readonly PROTOCOL_VERSION = 4

hash = this.chain
.into(ValueRune)
.access("metadata", "extrinsic", "call")
Expand All @@ -30,7 +34,8 @@ export class ExtrinsicRune<out C extends Chain, out U> extends PatternRune<Chain
.encoded(this)

signed<SU>(signatureFactory: SignatureDataFactory<C, U, SU>) {
return Rune.fn($extrinsic)
return Rune
.fn($extrinsic)
.call(this.chain.metadata)
.into(CodecRune)
.encoded(Rune.rec({
Expand All @@ -42,24 +47,29 @@ export class ExtrinsicRune<out C extends Chain, out U> extends PatternRune<Chain
}

encoded() {
return Rune.fn($extrinsic)
.call(this.chain.into(ValueRune).access("metadata"))
return Rune
.fn($extrinsic)
.call(this.chain.metadata)
.into(CodecRune)
.encoded(Rune.rec({
protocolVersion: 4,
protocolVersion: ExtrinsicRune.PROTOCOL_VERSION,
call: this,
}))
}

feeEstimate() {
const extrinsicHex = this.encoded().map(hex.encodePrefixed)
return this.chain.connection.call("payment_queryInfo", extrinsicHex)
.map(({ weight, ...rest }) => ({
...rest,
weight: {
proofSize: BigInt(typeof weight === "number" ? 0 : weight.proof_size),
refTime: BigInt(typeof weight === "number" ? weight : weight.ref_time),
},
}))
const encoded = this.encoded()
const arg = Rune
.fn(concat)
.call(encoded, encoded.access("length").map((n) => $.u32.encode(n)))
.map(hex.encodePrefixed)
const data = this.chain.connection
.call("state_call", "TransactionPaymentApi_query_info", arg)
.map(hex.decode)
return this.chain.metadata
.access("types", "sp_weights.weight_v2.Weight")
.map(($c) => $.field("weight", $c))
.into(CodecRune)
.decoded(data)
}
}
4 changes: 1 addition & 3 deletions patterns/multisig/MultisigRune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ export class MultisigRune<out C extends Chain, out U> extends PatternRune<Multis
call,
otherSignatories: this.otherSignatories(sender),
storeCall: false,
// TODO: revert when this is merged https://github.com/paritytech/substrate/pull/13766
maxWeight: call.feeEstimate().access("weight")
.map((weight) => ({ ...weight, proofSize: 200_000_000n })),
maxWeight: call.feeEstimate().access("weight"),
maybeTimepoint: this.maybeTimepoint(call.hash),
}),
})
Expand Down