break down analyzer into separate files
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "0.1.0-autogenerated.403250971526209557",
|
||||
"version": "0.1.0-autogenerated.11438231719699111413",
|
||||
"name": "@polkadot-api/descriptors",
|
||||
"files": [
|
||||
"dist"
|
||||
|
||||
Binary file not shown.
@@ -6,7 +6,7 @@
|
||||
"chain": "polkadot_people",
|
||||
"metadata": ".papi/metadata/polkadot_people.scale",
|
||||
"genesis": "0x67fa177a097bfa18f77ea95ab56e9bcdfeb0e5b8a40e46298bb93e16b6fc5008",
|
||||
"codeHash": "0x19d152fef983bf5be332cd07dc6f5c7291d842a4e2d5501eca02a86c10df211d"
|
||||
"codeHash": "0x3f0652ba1159157eff567b8e0e5987c8fc67a614f0909ce0f65f0d8a2b532864"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { TextInputField } from "@/components/TextInputField"
|
||||
import { useHashParamState } from "@/hashParams"
|
||||
import { Subscribe } from "@react-rxjs/core"
|
||||
import { FC } from "react"
|
||||
import { BlockPicker } from "../../Storage/BlockPicker"
|
||||
import { ExtrinsicDecoder, extrinsicDecoder$ } from "./ExtrinsicDecoder"
|
||||
|
||||
export const ExtrinsicAnalyzer: FC = () => {
|
||||
const [extrinsicHex, setExtrinsicHex] = useHashParamState(
|
||||
"extrinsic",
|
||||
() => "",
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="p-2 space-y-2">
|
||||
<h2 className="text-lg font-bold">Analyze Extrinsic</h2>
|
||||
<div className="flex items-center gap-1 flex-wrap">
|
||||
<div>
|
||||
<label>
|
||||
Block
|
||||
<BlockPicker />
|
||||
</label>
|
||||
</div>
|
||||
<div className="grow">
|
||||
<label>
|
||||
Extrinsic
|
||||
<TextInputField
|
||||
className="w-full"
|
||||
value={extrinsicHex}
|
||||
onChange={setExtrinsicHex}
|
||||
placeholder="Extrinsic Hex"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<Subscribe source$={extrinsicDecoder$} fallback={null}>
|
||||
{extrinsicHex ? <ExtrinsicDecoder extrinsic={extrinsicHex} /> : null}
|
||||
</Subscribe>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import { CopyBinary } from "@/codec-components/ViewCodec/CopyBinary"
|
||||
import { JsonDisplay } from "@/components/JsonDisplay"
|
||||
import { DecodedExtrinsic, getExtrinsicDecoder } from "@polkadot-api/tx-utils"
|
||||
import { state, useStateObservable } from "@react-rxjs/core"
|
||||
import { HexString, TxCallData } from "polkadot-api"
|
||||
import { toHex } from "polkadot-api/utils"
|
||||
import { FC, useMemo } from "react"
|
||||
import { map, merge } from "rxjs"
|
||||
import { Sender, SignedExtensions } from "../../Explorer/Detail/Extrinsic"
|
||||
import { AnalyzeMortality, analyzeMortality$ } from "./Mortality"
|
||||
import { AnalyzePriority, analyzePriority$ } from "./Priority"
|
||||
import { selectedBlock$ } from "./selectedBlock"
|
||||
|
||||
export const extDecoder$ = state(
|
||||
selectedBlock$.pipe(
|
||||
map((block) => getExtrinsicDecoder(block.ctx.metadataRaw)),
|
||||
),
|
||||
)
|
||||
|
||||
export const ExtrinsicDecoder: FC<{
|
||||
extrinsic: HexString
|
||||
}> = ({ extrinsic }) => {
|
||||
const extrinsicDecoder = useStateObservable(extDecoder$)
|
||||
const decodeResult = useMemo(() => {
|
||||
try {
|
||||
return {
|
||||
type: "success" as const,
|
||||
value: extrinsicDecoder(extrinsic),
|
||||
}
|
||||
} catch (ex) {
|
||||
console.error(ex)
|
||||
return {
|
||||
type: "error" as const,
|
||||
value: ex as Error,
|
||||
}
|
||||
}
|
||||
}, [extrinsicDecoder, extrinsic])
|
||||
|
||||
if (decodeResult.type === "error") {
|
||||
return <div>Can't decode: {decodeResult.value.message}</div>
|
||||
}
|
||||
|
||||
const decoded = decodeResult.value
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2 className="capitalize text-xl font-bold">
|
||||
{decoded.type} Transaction v{decoded.version}
|
||||
</h2>
|
||||
{decoded.type === "signed" ? (
|
||||
<SignedInfo extrinsic={extrinsic} decoded={decoded} />
|
||||
) : decoded.type === "general" ? (
|
||||
<div>TODO</div>
|
||||
) : (
|
||||
<AnalyzePriority extrinsic={extrinsic} />
|
||||
)}
|
||||
<CallData call={decoded.call as TxCallData} callData={decoded.callData} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const SignedInfo: FC<{
|
||||
extrinsic: HexString
|
||||
decoded: DecodedExtrinsic & { type: "signed" }
|
||||
}> = ({ extrinsic, decoded }) => {
|
||||
const mortality = decoded.extra.CheckMortality
|
||||
const txPayment =
|
||||
decoded.extra.ChargeAssetTxPayment ?? decoded.extra.ChargeTxPayment
|
||||
|
||||
return (
|
||||
<div className="space-y-2 mb-4">
|
||||
<Sender sender={decoded.address} />
|
||||
<SignedExtensions extra={decoded.extra} />
|
||||
{mortality ? <AnalyzeMortality mortality={mortality} /> : null}
|
||||
<AnalyzePriority extrinsic={extrinsic} txPayment={txPayment ?? {}} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const CallData: FC<{ call: TxCallData; callData: Uint8Array }> = ({
|
||||
call,
|
||||
callData,
|
||||
}) => (
|
||||
<div>
|
||||
<div className="flex gap-2 items-baseline">
|
||||
<div className="text-lg">
|
||||
{call.type}.{call.value.type}
|
||||
</div>
|
||||
<div className="flex gap-1 items-center overflow-hidden">
|
||||
<div className="shrink overflow-hidden text-ellipsis text-muted-foreground">
|
||||
{toHex(callData)}
|
||||
</div>
|
||||
<CopyBinary value={callData} />
|
||||
</div>
|
||||
</div>
|
||||
<JsonDisplay src={call.value.value} />
|
||||
</div>
|
||||
)
|
||||
|
||||
export const extrinsicDecoder$ = merge(
|
||||
extDecoder$,
|
||||
analyzeMortality$,
|
||||
analyzePriority$,
|
||||
)
|
||||
@@ -0,0 +1,66 @@
|
||||
import { client$ } from "@/state/chains/chain.state"
|
||||
import { polkadot_people } from "@polkadot-api/descriptors"
|
||||
import { state, useStateObservable } from "@react-rxjs/core"
|
||||
import { FC } from "react"
|
||||
import { combineLatest, map, switchMap } from "rxjs"
|
||||
import { selectedBlockHex$ } from "./selectedBlock"
|
||||
|
||||
const selectedBlockNumber$ = state(
|
||||
combineLatest([selectedBlockHex$, client$]).pipe(
|
||||
switchMap(([selectedBlock, client]) =>
|
||||
selectedBlock
|
||||
? (client
|
||||
.getTypedApi(polkadot_people)
|
||||
.query.System.Number.getValue({
|
||||
at: selectedBlock,
|
||||
})
|
||||
.catch(() => null) as Promise<number | null>)
|
||||
: client.finalizedBlock$.pipe(map((block) => block.number)),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
export const AnalyzeMortality: FC<{
|
||||
mortality: { type: string; value: number }
|
||||
}> = ({ mortality }) => {
|
||||
const selectedBlockNumber = useStateObservable(selectedBlockNumber$)
|
||||
|
||||
if (mortality.type === "Immortal") return null
|
||||
const parseResult = /^Mortal(\d+)$/.exec(mortality.type)
|
||||
if (parseResult === null) return null
|
||||
const first = BigInt(parseResult[1])
|
||||
const second = BigInt(mortality.value)
|
||||
// from polkadot-sdk primitives runtime generic era fn decode
|
||||
const encoded = first + (second << 8n)
|
||||
const period = Number(2n << (encoded % (1n << 4n)))
|
||||
const factor = period >> 12 || 1
|
||||
const phase = Number(encoded >> 4n) * factor
|
||||
|
||||
// From fn birth
|
||||
const birthBlock = selectedBlockNumber
|
||||
? Math.floor((Math.max(selectedBlockNumber, phase) - phase) / period) *
|
||||
period +
|
||||
phase
|
||||
: null
|
||||
|
||||
const referencedBlocks = birthBlock
|
||||
? new Array(5)
|
||||
.fill(0)
|
||||
.map((_, i) => (birthBlock - period * i).toLocaleString())
|
||||
: null
|
||||
|
||||
return (
|
||||
<div>
|
||||
<b>Mortality:</b> period={period} phase={phase}{" "}
|
||||
{referencedBlocks ? (
|
||||
<>
|
||||
currentBlock={selectedBlockNumber?.toLocaleString()} nextPeriod=
|
||||
{(birthBlock! + period).toLocaleString()} oldPeriods=
|
||||
{referencedBlocks.join(" ")}
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const analyzeMortality$ = selectedBlockNumber$
|
||||
@@ -0,0 +1,116 @@
|
||||
import { client$ } from "@/state/chains/chain.state"
|
||||
import { polkadot_people } from "@polkadot-api/descriptors"
|
||||
import { state, useStateObservable } from "@react-rxjs/core"
|
||||
import { Binary, HexString } from "polkadot-api"
|
||||
import { FC, useEffect, useState } from "react"
|
||||
import { combineLatest, firstValueFrom, switchMap } from "rxjs"
|
||||
import { selectedBlockHex$ } from "./selectedBlock"
|
||||
|
||||
const maxBlockSize$ = state(
|
||||
combineLatest([selectedBlockHex$, client$]).pipe(
|
||||
switchMap(([selectedBlock, client]) =>
|
||||
Promise.all([
|
||||
client.getTypedApi(polkadot_people).constants.System.BlockLength({
|
||||
at: selectedBlock,
|
||||
}),
|
||||
client.getTypedApi(polkadot_people).constants.System.BlockWeights({
|
||||
at: selectedBlock,
|
||||
}),
|
||||
]).then(
|
||||
([length, weights]) => ({
|
||||
length: length.max,
|
||||
maxWeight: weights.max_block,
|
||||
}),
|
||||
() => null,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
export const AnalyzePriority: FC<{
|
||||
txPayment?: { tip?: bigint }
|
||||
extrinsic: HexString
|
||||
}> = ({ txPayment, extrinsic }) => {
|
||||
const blockHex = useStateObservable(selectedBlockHex$)
|
||||
const maxBlockSize = useStateObservable(maxBlockSize$)
|
||||
const [queryInfo, setQueryInfo] = useState<{
|
||||
weight: Weight
|
||||
class: { type: "Normal" | "Operational" | "Mandatory" }
|
||||
partial_fee: bigint
|
||||
} | null>(null)
|
||||
const length = (extrinsic.length - 2) / 8
|
||||
const tip = txPayment?.tip ?? 0n
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
setQueryInfo(null)
|
||||
const client = await firstValueFrom(client$)
|
||||
const result = await client
|
||||
.getUnsafeApi()
|
||||
.apis.TransactionPaymentApi.query_info(
|
||||
Binary.fromOpaque(extrinsic),
|
||||
length,
|
||||
{
|
||||
at: blockHex,
|
||||
},
|
||||
)
|
||||
if (!cancelled) {
|
||||
setQueryInfo(result as any)
|
||||
}
|
||||
})()
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [extrinsic, blockHex, length])
|
||||
|
||||
if (!queryInfo) return null
|
||||
|
||||
const priority = (() => {
|
||||
if (!maxBlockSize) return null
|
||||
const maxLength =
|
||||
maxBlockSize.length[
|
||||
queryInfo.class.type.toLocaleLowerCase() as keyof typeof maxBlockSize.length
|
||||
]
|
||||
|
||||
const maxTxPerBlockWeight = divWeight(
|
||||
maxBlockSize.maxWeight,
|
||||
queryInfo.weight,
|
||||
)
|
||||
const maxTxPerBlockLength = BigInt(Math.floor(maxLength / length))
|
||||
const maxTxPerBlock =
|
||||
maxTxPerBlockWeight < maxTxPerBlockLength
|
||||
? maxTxPerBlockWeight
|
||||
: maxTxPerBlockLength
|
||||
const priority = (tip + 1n) * maxTxPerBlock
|
||||
|
||||
return { priority, maxTxPerBlockLength, maxTxPerBlockWeight }
|
||||
})()
|
||||
|
||||
return (
|
||||
<div>
|
||||
<b>Priority:</b> tip={tip.toLocaleString()} fee=
|
||||
{queryInfo.partial_fee.toLocaleString()} class={queryInfo.class.type}{" "}
|
||||
weight=
|
||||
{queryInfo.weight.proof_size.toLocaleString() +
|
||||
"/" +
|
||||
queryInfo.weight.ref_time.toLocaleString()}{" "}
|
||||
{priority ? (
|
||||
<>
|
||||
txPerBlockLength={priority.maxTxPerBlockLength.toLocaleString()}{" "}
|
||||
txPerBlockWeight={priority.maxTxPerBlockWeight.toLocaleString()}{" "}
|
||||
priority={priority.priority.toLocaleString()}
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export const analyzePriority$ = maxBlockSize$
|
||||
|
||||
type Weight = { ref_time: bigint; proof_size: bigint }
|
||||
const divWeight = (a: Weight, b: Weight) => {
|
||||
const ref_time = b.ref_time === 0n ? 1n : a.ref_time / b.ref_time
|
||||
const proof_size = b.proof_size === 0n ? 1n : a.proof_size / b.proof_size
|
||||
return ref_time < proof_size ? ref_time : proof_size
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { state } from "@react-rxjs/core"
|
||||
import { map } from "rxjs"
|
||||
import { selectedBlock$ } from "../../Storage/BlockPicker"
|
||||
|
||||
export { selectedBlock$ }
|
||||
export const selectedBlockHex$ = state(selectedBlock$.pipe(map((v) => v.hash)))
|
||||
@@ -1,309 +0,0 @@
|
||||
import { CopyBinary } from "@/codec-components/ViewCodec/CopyBinary"
|
||||
import { JsonDisplay } from "@/components/JsonDisplay"
|
||||
import { TextInputField } from "@/components/TextInputField"
|
||||
import { useHashParamState } from "@/hashParams"
|
||||
import { client$ } from "@/state/chains/chain.state"
|
||||
import { polkadot_people } from "@polkadot-api/descriptors"
|
||||
import { DecodedExtrinsic, getExtrinsicDecoder } from "@polkadot-api/tx-utils"
|
||||
import { state, Subscribe, useStateObservable } from "@react-rxjs/core"
|
||||
import { Binary, HexString, TxCallData } from "polkadot-api"
|
||||
import { toHex } from "polkadot-api/utils"
|
||||
import { FC, useEffect, useMemo, useState } from "react"
|
||||
import { combineLatest, firstValueFrom, map, merge, switchMap } from "rxjs"
|
||||
import { Sender, SignedExtensions } from "../Explorer/Detail/Extrinsic"
|
||||
import { BlockPicker, selectedBlock$ } from "../Storage/BlockPicker"
|
||||
|
||||
const extDecoder$ = state(
|
||||
selectedBlock$.pipe(
|
||||
map((block) => getExtrinsicDecoder(block.ctx.metadataRaw)),
|
||||
),
|
||||
)
|
||||
const selectedBlockHex$ = state(selectedBlock$.pipe(map((v) => v.hash)))
|
||||
|
||||
export const ExtrinsicAnalyzer: FC = () => {
|
||||
const [extrinsicHex, setExtrinsicHex] = useHashParamState(
|
||||
"extrinsic",
|
||||
() => "",
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="p-2 space-y-2">
|
||||
<h2 className="text-lg font-bold">Analyze Extrinsic</h2>
|
||||
<div className="flex items-center gap-1 flex-wrap">
|
||||
<div>
|
||||
<label>
|
||||
Block
|
||||
<BlockPicker />
|
||||
</label>
|
||||
</div>
|
||||
<div className="grow">
|
||||
<label>
|
||||
Extrinsic
|
||||
<TextInputField
|
||||
className="w-full"
|
||||
value={extrinsicHex}
|
||||
onChange={setExtrinsicHex}
|
||||
placeholder="Extrinsic Hex"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<Subscribe source$={extAnalyzer$} fallback={null}>
|
||||
{extrinsicHex ? <DecodeExtrinsic extrinsic={extrinsicHex} /> : null}
|
||||
</Subscribe>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const DecodeExtrinsic: FC<{
|
||||
extrinsic: HexString
|
||||
}> = ({ extrinsic }) => {
|
||||
const extrinsicDecoder = useStateObservable(extDecoder$)
|
||||
const decodeResult = useMemo(() => {
|
||||
try {
|
||||
return {
|
||||
type: "success" as const,
|
||||
value: extrinsicDecoder(extrinsic),
|
||||
}
|
||||
} catch (ex) {
|
||||
console.error(ex)
|
||||
return {
|
||||
type: "error" as const,
|
||||
value: ex as Error,
|
||||
}
|
||||
}
|
||||
}, [extrinsicDecoder, extrinsic])
|
||||
|
||||
if (decodeResult.type === "error") {
|
||||
return <div>Can't decode: {decodeResult.value.message}</div>
|
||||
}
|
||||
|
||||
const decoded = decodeResult.value
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2 className="capitalize text-xl font-bold">
|
||||
{decoded.type} Transaction v{decoded.version}
|
||||
</h2>
|
||||
{decoded.type === "signed" ? (
|
||||
<SignedInfo extrinsic={extrinsic} decoded={decoded} />
|
||||
) : decoded.type === "general" ? (
|
||||
<div>TODO</div>
|
||||
) : (
|
||||
<AnalyzePriority extrinsic={extrinsic} />
|
||||
)}
|
||||
<CallData call={decoded.call as TxCallData} callData={decoded.callData} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const SignedInfo: FC<{
|
||||
extrinsic: HexString
|
||||
decoded: DecodedExtrinsic & { type: "signed" }
|
||||
}> = ({ extrinsic, decoded }) => {
|
||||
const mortality = decoded.extra.CheckMortality
|
||||
const txPayment =
|
||||
decoded.extra.ChargeAssetTxPayment ?? decoded.extra.ChargeTxPayment
|
||||
|
||||
return (
|
||||
<div className="space-y-2 mb-4">
|
||||
<Sender sender={decoded.address} />
|
||||
<SignedExtensions extra={decoded.extra} />
|
||||
{mortality ? <AnalyzeMortality mortality={mortality} /> : null}
|
||||
<AnalyzePriority extrinsic={extrinsic} txPayment={txPayment ?? {}} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const CallData: FC<{ call: TxCallData; callData: Uint8Array }> = ({
|
||||
call,
|
||||
callData,
|
||||
}) => (
|
||||
<div>
|
||||
<div className="flex gap-2 items-baseline">
|
||||
<div className="text-lg">
|
||||
{call.type}.{call.value.type}
|
||||
</div>
|
||||
<div className="flex gap-1 items-center overflow-hidden">
|
||||
<div className="shrink overflow-hidden text-ellipsis text-muted-foreground">
|
||||
{toHex(callData)}
|
||||
</div>
|
||||
<CopyBinary value={callData} />
|
||||
</div>
|
||||
</div>
|
||||
<JsonDisplay src={call.value.value} />
|
||||
</div>
|
||||
)
|
||||
|
||||
const selectedBlockNumber$ = state(
|
||||
combineLatest([selectedBlockHex$, client$]).pipe(
|
||||
switchMap(([selectedBlock, client]) =>
|
||||
selectedBlock
|
||||
? (client
|
||||
.getTypedApi(polkadot_people)
|
||||
.query.System.Number.getValue({
|
||||
at: selectedBlock,
|
||||
})
|
||||
.catch(() => null) as Promise<number | null>)
|
||||
: client.finalizedBlock$.pipe(map((block) => block.number)),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
const AnalyzeMortality: FC<{ mortality: { type: string; value: number } }> = ({
|
||||
mortality,
|
||||
}) => {
|
||||
const selectedBlockNumber = useStateObservable(selectedBlockNumber$)
|
||||
|
||||
if (mortality.type === "Immortal") return null
|
||||
const parseResult = /^Mortal(\d+)$/.exec(mortality.type)
|
||||
if (parseResult === null) return null
|
||||
const first = BigInt(parseResult[1])
|
||||
const second = BigInt(mortality.value)
|
||||
// from polkadot-sdk primitives runtime generic era fn decode
|
||||
const encoded = first + (second << 8n)
|
||||
const period = Number(2n << (encoded % (1n << 4n)))
|
||||
const factor = period >> 12 || 1
|
||||
const phase = Number(encoded >> 4n) * factor
|
||||
|
||||
// From fn birth
|
||||
const birthBlock = selectedBlockNumber
|
||||
? Math.floor((Math.max(selectedBlockNumber, phase) - phase) / period) *
|
||||
period +
|
||||
phase
|
||||
: null
|
||||
|
||||
const referencedBlocks = birthBlock
|
||||
? new Array(5)
|
||||
.fill(0)
|
||||
.map((_, i) => (birthBlock - period * i).toLocaleString())
|
||||
: null
|
||||
|
||||
return (
|
||||
<div>
|
||||
<b>Mortality:</b> period={period} phase={phase}{" "}
|
||||
{referencedBlocks ? (
|
||||
<>
|
||||
currentBlock={selectedBlockNumber?.toLocaleString()} nextPeriod=
|
||||
{(birthBlock! + period).toLocaleString()} oldPeriods=
|
||||
{referencedBlocks.join(" ")}
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const maxBlockSize$ = state(
|
||||
combineLatest([selectedBlockHex$, client$]).pipe(
|
||||
switchMap(([selectedBlock, client]) =>
|
||||
Promise.all([
|
||||
client.getTypedApi(polkadot_people).constants.System.BlockLength({
|
||||
at: selectedBlock,
|
||||
}),
|
||||
client.getTypedApi(polkadot_people).constants.System.BlockWeights({
|
||||
at: selectedBlock,
|
||||
}),
|
||||
]).then(
|
||||
([length, weights]) => ({
|
||||
length,
|
||||
maxWeight: weights.max_block,
|
||||
}),
|
||||
() => null,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
const AnalyzePriority: FC<{
|
||||
txPayment?: { tip?: bigint }
|
||||
extrinsic: HexString
|
||||
}> = ({ txPayment, extrinsic }) => {
|
||||
const blockHex = useStateObservable(selectedBlockHex$)
|
||||
const maxBlockSize = useStateObservable(maxBlockSize$)
|
||||
const [queryInfo, setQueryInfo] = useState<{
|
||||
weight: Weight
|
||||
class: { type: "Normal" | "Operational" | "Mandatory" }
|
||||
partial_fee: bigint
|
||||
} | null>(null)
|
||||
const length = (extrinsic.length - 2) / 8
|
||||
const tip = txPayment?.tip ?? 0n
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
setQueryInfo(null)
|
||||
const client = await firstValueFrom(client$)
|
||||
console.log(extrinsic.length)
|
||||
const result = await client
|
||||
.getUnsafeApi()
|
||||
.apis.TransactionPaymentApi.query_info(
|
||||
Binary.fromOpaque(extrinsic),
|
||||
length,
|
||||
{
|
||||
at: blockHex,
|
||||
},
|
||||
)
|
||||
if (!cancelled) {
|
||||
setQueryInfo(result as any)
|
||||
}
|
||||
})()
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [extrinsic, blockHex, length])
|
||||
|
||||
if (!queryInfo) return null
|
||||
|
||||
const priority = (() => {
|
||||
if (!maxBlockSize) return null
|
||||
const maxLength =
|
||||
maxBlockSize.length.max[
|
||||
queryInfo.class.type.toLocaleLowerCase() as keyof typeof maxBlockSize.length.max
|
||||
]
|
||||
|
||||
const maxTxPerBlockWeight = divWeight(
|
||||
maxBlockSize.maxWeight,
|
||||
queryInfo.weight,
|
||||
)
|
||||
const maxTxPerBlockLength = BigInt(Math.floor(maxLength / length))
|
||||
const maxTxPerBlock =
|
||||
maxTxPerBlockWeight < maxTxPerBlockLength
|
||||
? maxTxPerBlockWeight
|
||||
: maxTxPerBlockLength
|
||||
const priority = (tip + 1n) * maxTxPerBlock
|
||||
|
||||
return { priority, maxTxPerBlockLength, maxTxPerBlockWeight }
|
||||
})()
|
||||
|
||||
return (
|
||||
<div>
|
||||
<b>Priority:</b> tip={tip.toLocaleString()} fee=
|
||||
{queryInfo.partial_fee.toLocaleString()} class={queryInfo.class.type}{" "}
|
||||
weight=
|
||||
{queryInfo.weight.proof_size.toLocaleString() +
|
||||
"/" +
|
||||
queryInfo.weight.ref_time.toLocaleString()}{" "}
|
||||
{priority ? (
|
||||
<>
|
||||
txPerBlockLength={priority.maxTxPerBlockLength.toLocaleString()}{" "}
|
||||
txPerBlockWeight={priority.maxTxPerBlockWeight.toLocaleString()}{" "}
|
||||
priority={priority.priority.toLocaleString()}
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const extAnalyzer$ = merge(
|
||||
extDecoder$,
|
||||
selectedBlockHex$,
|
||||
selectedBlockNumber$,
|
||||
maxBlockSize$,
|
||||
)
|
||||
|
||||
type Weight = { ref_time: bigint; proof_size: bigint }
|
||||
const divWeight = (a: Weight, b: Weight) => {
|
||||
const ref_time = b.ref_time === 0n ? 1n : a.ref_time / b.ref_time
|
||||
const proof_size = b.proof_size === 0n ? 1n : a.proof_size / b.proof_size
|
||||
return ref_time < proof_size ? ref_time : proof_size
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import { map } from "rxjs"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
import { CustomSignedExt, customSignedExtensions$ } from "./CustomSignedExt"
|
||||
import { EditMode } from "./EditMode"
|
||||
import { ExtrinsicAnalyzer } from "./ExtrinsicAnalyzer"
|
||||
import { ExtrinsicAnalyzer } from "./Analyzer/ExtrinsicAnalyzer"
|
||||
import { JsonMode } from "./JsonMode"
|
||||
import { ExtrinsicModal } from "./SubmitTx/SubmitTx"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user