Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
d20238c2
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d20238c2
编写于
8月 24, 2016
作者:
N
Nick Johnson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
internal/ethapi: Improve tracer error reporting and serialization
上级
4ce83bf5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
11 deletion
+26
-11
internal/ethapi/tracer.go
internal/ethapi/tracer.go
+24
-9
internal/ethapi/tracer_test.go
internal/ethapi/tracer_test.go
+2
-2
未找到文件。
internal/ethapi/tracer.go
浏览文件 @
d20238c2
...
...
@@ -17,6 +17,7 @@
package
ethapi
import
(
"encoding/json"
"errors"
"fmt"
"math/big"
...
...
@@ -55,6 +56,11 @@ func (ocw *opCodeWrapper) isPush() bool {
return
ocw
.
op
.
IsPush
()
}
// MarshalJSON serializes the opcode as JSON
func
(
ocw
*
opCodeWrapper
)
MarshalJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
ocw
.
op
.
String
())
}
// toValue returns an otto.Value for the opCodeWrapper
func
(
ocw
*
opCodeWrapper
)
toValue
(
vm
*
otto
.
Otto
)
otto
.
Value
{
value
,
_
:=
vm
.
ToValue
(
ocw
)
...
...
@@ -165,8 +171,6 @@ type JavascriptTracer struct {
traceobj
*
otto
.
Object
// User-supplied object to call
log
map
[
string
]
interface
{}
// (Reusable) map for the `log` arg to `step`
logvalue
otto
.
Value
// JS view of `log`
opcode
*
opCodeWrapper
// Wrapper around the opcode
opcodevalue
otto
.
Value
// JS view of 'opcode'
memory
*
memoryWrapper
// Wrapper around the VM memory
memvalue
otto
.
Value
// JS view of `memory`
stack
*
stackWrapper
// Wrapper around the VM stack
...
...
@@ -213,7 +217,6 @@ func NewJavascriptTracer(code string) (*JavascriptTracer, error) {
logvalue
,
_
:=
vm
.
ToValue
(
log
)
// Create persistent wrappers for memory and stack
opcode
:=
&
opCodeWrapper
{}
mem
:=
&
memoryWrapper
{}
stack
:=
&
stackWrapper
{}
db
:=
&
dbWrapper
{}
...
...
@@ -223,8 +226,6 @@ func NewJavascriptTracer(code string) (*JavascriptTracer, error) {
traceobj
:
jstracer
,
log
:
log
,
logvalue
:
logvalue
,
opcode
:
opcode
,
opcodevalue
:
opcode
.
toValue
(
vm
),
memory
:
mem
,
memvalue
:
mem
.
toValue
(
vm
),
stack
:
stack
,
...
...
@@ -265,16 +266,26 @@ func (jst *JavascriptTracer) callSafely(method string, argumentList ...interface
return
ret
,
err
}
func
wrapError
(
context
string
,
err
error
)
error
{
var
message
string
switch
err
:=
err
.
(
type
)
{
case
*
otto
.
Error
:
message
=
err
.
String
()
default
:
message
=
err
.
Error
()
}
return
fmt
.
Errorf
(
"%v in server-side tracer function '%v'"
,
message
,
context
)
}
// CaptureState implements the Tracer interface to trace a single step of VM execution
func
(
jst
*
JavascriptTracer
)
CaptureState
(
env
vm
.
Environment
,
pc
uint64
,
op
vm
.
OpCode
,
gas
,
cost
*
big
.
Int
,
memory
*
vm
.
Memory
,
stack
*
vm
.
Stack
,
contract
*
vm
.
Contract
,
depth
int
,
err
error
)
{
if
jst
.
err
==
nil
{
jst
.
opcode
.
op
=
op
jst
.
memory
.
memory
=
memory
jst
.
stack
.
stack
=
stack
jst
.
db
.
db
=
env
.
Db
()
jst
.
log
[
"pc"
]
=
pc
jst
.
log
[
"op"
]
=
jst
.
opcodevalue
jst
.
log
[
"op"
]
=
&
opCodeWrapper
{
op
}
jst
.
log
[
"gas"
]
=
gas
.
Int64
()
jst
.
log
[
"gasPrice"
]
=
cost
.
Int64
()
jst
.
log
[
"memory"
]
=
jst
.
memvalue
...
...
@@ -285,7 +296,7 @@ func (jst *JavascriptTracer) CaptureState(env vm.Environment, pc uint64, op vm.O
_
,
err
:=
jst
.
callSafely
(
"step"
,
jst
.
logvalue
,
jst
.
dbvalue
)
if
err
!=
nil
{
jst
.
err
=
err
jst
.
err
=
wrapError
(
"step"
,
err
)
}
}
}
...
...
@@ -296,5 +307,9 @@ func (jst *JavascriptTracer) GetResult() (result interface{}, err error) {
return
nil
,
jst
.
err
}
return
jst
.
callSafely
(
"result"
)
result
,
err
=
jst
.
callSafely
(
"result"
)
if
err
!=
nil
{
err
=
wrapError
(
"result"
,
err
)
}
return
}
internal/ethapi/tracer_test.go
浏览文件 @
d20238c2
...
...
@@ -161,7 +161,7 @@ func TestHalt(t *testing.T) {
tracer
.
Stop
(
timeout
)
}()
if
_
,
err
=
runTrace
(
tracer
);
err
!=
timeout
{
if
_
,
err
=
runTrace
(
tracer
);
err
.
Error
()
!=
"stahp in server-side tracer function 'step'"
{
t
.
Errorf
(
"Expected timeout error, got %v"
,
err
)
}
}
...
...
@@ -180,7 +180,7 @@ func TestHaltBetweenSteps(t *testing.T) {
tracer
.
Stop
(
timeout
)
tracer
.
CaptureState
(
env
,
0
,
0
,
big
.
NewInt
(
0
),
big
.
NewInt
(
0
),
nil
,
nil
,
contract
,
0
,
nil
)
if
_
,
err
:=
tracer
.
GetResult
();
err
!=
timeout
{
if
_
,
err
:=
tracer
.
GetResult
();
err
.
Error
()
!=
"stahp in server-side tracer function 'step'"
{
t
.
Errorf
(
"Expected timeout error, got %v"
,
err
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录