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

feat: add error code mapping for gw/polyjuice/evmc #591

Merged
merged 3 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/api-server/src/filter-web3-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export async function filterWeb3Transaction(
return undefined;
}

function parsePolyjuiceSystemLog(data: HexString): PolyjuiceSystemLog {
export function parsePolyjuiceSystemLog(data: HexString): PolyjuiceSystemLog {
// 2 + (8 + 8 + 20 + 4) * 2
if (data.length !== 82) {
throw new Error(`invalid system log raw data length: ${data.length}`);
Expand Down
22 changes: 19 additions & 3 deletions packages/api-server/src/methods/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,32 @@ import {
} from "./error-code";
import { HexString } from "@ckb-lumos/base";

// evmc/polyjuice/godwoken exit code error
export interface Extra {
exit_code: string;
message: string;
stack: ExtraStack;
}
// exit code throw stack
export enum ExtraStack {
evmc = "EVMC",
poly = "POLYJUICE",
gw = "GODWOKEN",
unknown = "UNKNOWN",
}

export class RpcError extends Error implements JSONRPCError {
code: number;
data?: any;
extra?: Extra;

constructor(code: number, message: string, data?: any) {
constructor(code: number, message: string, data?: any, extra?: Extra) {
super(message);
this.name = "RpcError";

this.code = code;
this.data = data;
this.extra = extra;
}
}

Expand All @@ -30,8 +46,8 @@ export function isRpcError(err: any): err is RpcError {
}

export class TransactionExecutionError extends RpcError {
constructor(message: string, data?: HexString) {
super(TRANSACTION_EXECUTION_ERROR, message, data);
constructor(message: string, data?: HexString, extra?: Extra) {
super(TRANSACTION_EXECUTION_ERROR, message, data, extra);
}
}

Expand Down
Loading