debug_traceTransaction
debug的traceTransaction
方法尝试以网络上相同的方式执行交易,
该方法将重放任何可能在此交易之前执行的交易。
除了传入交易哈希作为参数,traceTransaction方法的第二个参数可选, 可用来指定调用的选项,可用选项包括:
- disableStorage: 是否禁用存储捕捉,布尔类型,默认值:false
- disableMemory: 是否禁用内存捕捉,布尔类型,默认值:false
- disableStack:是否禁用栈捕捉,布尔类型,默认值:false
- tracer:启用基于JavaScript的交易跟踪,字符串类型,详见下面描述
- timeout:设置基于JavaScript的跟踪调用的超时时长,字符串类型,默认值:"5s",即5秒钟
调用方法
Go:
debug.TraceTransaction(txHash common.Hash, logger *vm.LogConfig) (*ExecutionResurt, error)
Geth控制台:
debug.traceTransaction(txHash, [options])
JSON RPC:
{"method": "debug_traceTransaction", "params": [txHash, {}]}
示例代码
下面的示例在Geth控制台中使用traceTransaction方法:
> debug.traceTransaction("0x2059dd53ecac9827faad14d364f9e04b1d5fe5b506e3acc886eff7a6f88a696a")
{
gas: 85301,
returnValue: "",
structLogs: [{
depth: 1,
error: "",
gas: 162106,
gasCost: 3,
memory: null,
op: "PUSH1",
pc: 0,
stack: [],
storage: {}
},
/* snip */
{
depth: 1,
error: "",
gas: 100000,
gasCost: 0,
memory: ["0000000000000000000000000000000000000000000000000000000000000006", "0000000000000000000000000000000000000000000000000000000000000000", "0000000000000000000000000000000000000000000000000000000000000060"],
op: "STOP",
pc: 120,
stack: ["00000000000000000000000000000000000000000000000000000000d67cbec9"],
storage: {
0000000000000000000000000000000000000000000000000000000000000004: "8241fa522772837f0d05511f20caa6da1d5a3209000000000000000400000001",
0000000000000000000000000000000000000000000000000000000000000006: "0000000000000000000000000000000000000000000000000000000000000001",
f652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f: "00000000000000000000000002e816afc1b5c0f39852131959d946eb3b07b5ad"
}
}]
基于JavaScript的跟踪
在基于JavaScript的跟踪模式下,跟踪器被解读为一个JavaScript表达式, 该表达式的值为一个至少包含两个方法的对象:step和result。
//TODO