From 4055c3e9b08b0fb369ee67d4d203fe5b2f283884 Mon Sep 17 00:00:00 2001 From: Tim B <79199034+timbrinded@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:19:35 +0000 Subject: [PATCH] createblock fix2 (#360) --- .changeset/tall-spoons-suffer.md | 5 +++ .../internal/foundations/devModeHelpers.ts | 39 +++++++++++-------- 2 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 .changeset/tall-spoons-suffer.md diff --git a/.changeset/tall-spoons-suffer.md b/.changeset/tall-spoons-suffer.md new file mode 100644 index 00000000..62a48c76 --- /dev/null +++ b/.changeset/tall-spoons-suffer.md @@ -0,0 +1,5 @@ +--- +"@moonwall/cli": patch +--- + +CreateBlock fix v2 diff --git a/packages/cli/src/internal/foundations/devModeHelpers.ts b/packages/cli/src/internal/foundations/devModeHelpers.ts index e467d079..6438e289 100644 --- a/packages/cli/src/internal/foundations/devModeHelpers.ts +++ b/packages/cli/src/internal/foundations/devModeHelpers.ts @@ -7,7 +7,7 @@ import { generateKeyringPair, } from "@moonwall/util"; import { Keyring } from "@polkadot/api"; -import { ApiTypes, SubmittableExtrinsic } from "@polkadot/api/types"; +import type { ApiTypes, SubmittableExtrinsic } from "@polkadot/api/types"; import { RegistryError } from "@polkadot/types-codec/types/registry"; import { EventRecord } from "@polkadot/types/interfaces"; import chalk from "chalk"; @@ -130,26 +130,33 @@ export async function createDevBlock< ).query.system.events()) as any; const blockData = await api.rpc.chain.getBlock(blockResult.hash); + const getExtIndex = (records: EventRecord[], result: { type: "sub" | "eth"; hash: string }) => { + if (result.type == "eth") { + const res = records + .find( + ({ phase, event: { section, method, data } }) => + phase.isApplyExtrinsic && + section == "ethereum" && + method == "Executed" && + data[2].toString() == result.hash + ) + ?.phase?.asApplyExtrinsic?.toString(); + + return res === undefined ? undefined : Number(res); + } else { + return blockData.block.extrinsics.findIndex((ext) => ext.hash.toHex() == result.hash); + } + }; + const result: ExtrinsicCreation[] = results.map((result) => { - const extrinsicIndex = - result.type == "eth" - ? parseInt( - allRecords - .find( - ({ phase, event: { section, method, data } }) => - phase.isApplyExtrinsic && - section == "ethereum" && - method == "Executed" && - data[2].toString() == result.hash - ) - ?.phase?.asApplyExtrinsic?.toString() || "-1" - ) - : blockData.block.extrinsics.findIndex((ext) => ext.hash.toHex() == result.hash); + const extrinsicIndex = getExtIndex(allRecords, result); + // We retrieve the events associated with the extrinsic const events = allRecords.filter( ({ phase }) => - phase.isApplyExtrinsic && parseInt(phase.asApplyExtrinsic.toString()) === extrinsicIndex + phase.isApplyExtrinsic && Number(phase.asApplyExtrinsic.toString()) === extrinsicIndex ); + const failure = extractError(events); return { extrinsic: extrinsicIndex! >= 0 ? blockData.block.extrinsics[extrinsicIndex!] : null,