From 013875e787438b17af0c1d116db3559bdeba8fb0 Mon Sep 17 00:00:00 2001 From: Justin Starry Date: Fri, 16 Apr 2021 13:04:06 +0800 Subject: [PATCH] Fix instruction validation for parsed memo instructions (#16591) --- .../components/account/history/TokenInstructionsCard.tsx | 6 +++++- explorer/src/utils/instruction.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/explorer/src/components/account/history/TokenInstructionsCard.tsx b/explorer/src/components/account/history/TokenInstructionsCard.tsx index e8bf1bd2e..73cbf3125 100644 --- a/explorer/src/components/account/history/TokenInstructionsCard.tsx +++ b/explorer/src/components/account/history/TokenInstructionsCard.tsx @@ -185,11 +185,15 @@ function isRelevantInstruction( account.equals(pubkey) || mintMap.get(account.toBase58())?.mint === address ); - } else { + } else if ( + typeof instruction.parsed === "object" && + "info" in instruction.parsed + ) { return Object.entries(instruction.parsed.info).some( ([key, value]) => value === address || (typeof value === "string" && mintMap.get(value)?.mint === address) ); } + return false; } diff --git a/explorer/src/utils/instruction.ts b/explorer/src/utils/instruction.ts index 6ea01cd6a..36a13469e 100644 --- a/explorer/src/utils/instruction.ts +++ b/explorer/src/utils/instruction.ts @@ -47,7 +47,11 @@ export class InstructionContainer { this.instructions = parsedTransaction.transaction.message.instructions.map( (instruction) => { if ("parsed" in instruction) { - instruction.parsed = create(instruction.parsed, ParsedInfo); + if (typeof instruction.parsed === "object") { + instruction.parsed = create(instruction.parsed, ParsedInfo); + } else if (typeof instruction.parsed !== "string") { + throw new Error("Unexpected parsed response"); + } } return {