Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 6, 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 web3/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 web3/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