Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #526 from keroro520/fix-parsing-panic-code
Browse files Browse the repository at this point in the history
fix: parse panic code from transaction error
  • Loading branch information
RetricSu authored Sep 19, 2022
2 parents 92b36a0 + d566cf4 commit 9f82ab7
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions packages/api-server/src/methods/gw-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,25 @@ export function unpackPanic(returnData: HexString): string {
"Too much memory was allocated, or an array was created that is too large",
"0x51": "Called a zero-initialized variable of internal function type",
};
const code: HexNumber =
"0x" + BigInt(returnData.slice(PANIC_SELECTOR.length)).toString(16);
const reason = panicCodeToReason[code];
if (reason != null) {
return `execution reverted: panic code ${code} (${reason})`;
} else {
return `execution reverted: panic code ${code}`;

const abi = abiCoder as unknown as AbiCoder;
try {
const parsedArgs = abi.decodeParameters(
["uint256"],
returnData.slice(PANIC_SELECTOR.length)
);
const code: HexNumber = "0x" + BigInt(parsedArgs[0]).toString(16);
const reason = panicCodeToReason[code];
if (reason != null) {
return `execution reverted: panic code ${code} (${reason})`;
} else {
return `execution reverted: panic code ${code}`;
}
} catch (err: any) {
logger.error(
`fail to decode panic error code, error: ${err}, returnData: ${returnData}`
);
return "execution reverted";
}
}

Expand Down

0 comments on commit 9f82ab7

Please sign in to comment.