This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #573 from godwokenrises/add-debug-api
Add debug RPCs
- Loading branch information
Showing
5 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Hash } from "@ckb-lumos/base"; | ||
import { RPC } from "@ckb-lumos/toolkit"; | ||
import { LogItem } from "@godwoken-web3/godwoken"; | ||
import { envConfig } from "../../base/env-config"; | ||
import { CACHE_EXPIRED_TIME_MILSECS } from "../../cache/constant"; | ||
import { Store } from "../../cache/store"; | ||
import { ethTxHashToGwTxHash } from "../../cache/tx-hash"; | ||
import { Query } from "../../db"; | ||
import { parsePolyjuiceUserLog } from "../../filter-web3-tx"; | ||
import { POLYJUICE_USER_LOG_FLAG } from "../constant"; | ||
import { handleGwError } from "../gw-error"; | ||
import { middleware } from "../validator"; | ||
|
||
export class Debug { | ||
private readonlyRpc: RPC; | ||
private cacheStore: Store; | ||
private query: Query; | ||
|
||
constructor() { | ||
this.readonlyRpc = new RPC( | ||
envConfig.godwokenReadonlyJsonRpc || envConfig.godwokenJsonRpc | ||
); | ||
this.cacheStore = new Store(true, CACHE_EXPIRED_TIME_MILSECS); | ||
this.query = new Query(); | ||
|
||
this.replayTransaction = middleware(this.replayTransaction.bind(this), 1); | ||
} | ||
|
||
async replayTransaction(args: any[]) { | ||
const ethTxHash: Hash = args[0]; | ||
const gwTxHash: Hash | undefined = await ethTxHashToGwTxHash( | ||
ethTxHash, | ||
this.query, | ||
this.cacheStore | ||
); | ||
if (gwTxHash == null) { | ||
throw new Error(`gw tx hash not found by eth tx hash ${ethTxHash}`); | ||
} | ||
let result; | ||
try { | ||
result = await this.readonlyRpc.debug_replay_transaction( | ||
gwTxHash, | ||
...args.slice(1) | ||
); | ||
} catch (error) { | ||
handleGwError(error); | ||
} | ||
|
||
if (result == null) { | ||
return undefined; | ||
} | ||
|
||
const web3Logs = result.logs | ||
.filter((log: LogItem) => log.service_flag === POLYJUICE_USER_LOG_FLAG) | ||
.map((log: LogItem) => { | ||
const info = parsePolyjuiceUserLog(log.data); | ||
return { | ||
address: info.address, | ||
data: info.data, | ||
topics: info.topics, | ||
}; | ||
}); | ||
|
||
// Replace logs with web3 logs | ||
result.logs = web3Logs; | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters