Fix instruction validation for parsed memo instructions (#16591)

This commit is contained in:
Justin Starry 2021-04-16 13:04:06 +08:00 committed by GitHub
parent 59268b8629
commit 013875e787
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -185,11 +185,15 @@ function isRelevantInstruction(
account.equals(pubkey) || account.equals(pubkey) ||
mintMap.get(account.toBase58())?.mint === address mintMap.get(account.toBase58())?.mint === address
); );
} else { } else if (
typeof instruction.parsed === "object" &&
"info" in instruction.parsed
) {
return Object.entries(instruction.parsed.info).some( return Object.entries(instruction.parsed.info).some(
([key, value]) => ([key, value]) =>
value === address || value === address ||
(typeof value === "string" && mintMap.get(value)?.mint === address) (typeof value === "string" && mintMap.get(value)?.mint === address)
); );
} }
return false;
} }

View File

@ -47,7 +47,11 @@ export class InstructionContainer {
this.instructions = parsedTransaction.transaction.message.instructions.map( this.instructions = parsedTransaction.transaction.message.instructions.map(
(instruction) => { (instruction) => {
if ("parsed" in 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 { return {