Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
7df52e32
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,发现更多精彩内容 >>
提交
7df52e32
编写于
12月 22, 2018
作者:
B
bas-vk
提交者:
Guillaume Ballet
12月 22, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
accounts/abi: add support for unpacking returned bytesN arrays (#15242)
上级
5e4fd8e7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
64 addition
and
0 deletion
+64
-0
accounts/abi/reflect.go
accounts/abi/reflect.go
+15
-0
accounts/abi/unpack_test.go
accounts/abi/unpack_test.go
+49
-0
未找到文件。
accounts/abi/reflect.go
浏览文件 @
7df52e32
...
...
@@ -77,6 +77,8 @@ func set(dst, src reflect.Value, output Argument) error {
switch
{
case
dstType
.
AssignableTo
(
srcType
)
:
dst
.
Set
(
src
)
case
dstType
.
Kind
()
==
reflect
.
Slice
&&
srcType
.
Kind
()
==
reflect
.
Slice
:
return
setSlice
(
dst
,
src
,
output
)
case
dstType
.
Kind
()
==
reflect
.
Interface
:
dst
.
Set
(
src
)
case
dstType
.
Kind
()
==
reflect
.
Ptr
:
...
...
@@ -87,6 +89,19 @@ func set(dst, src reflect.Value, output Argument) error {
return
nil
}
// setSlice attempts to assign src to dst when slices are not assignable by default
// e.g. src: [][]byte -> dst: [][15]byte
func
setSlice
(
dst
,
src
reflect
.
Value
,
output
Argument
)
error
{
slice
:=
reflect
.
MakeSlice
(
dst
.
Type
(),
src
.
Len
(),
src
.
Len
())
for
i
:=
0
;
i
<
src
.
Len
();
i
++
{
v
:=
src
.
Index
(
i
)
reflect
.
Copy
(
slice
.
Index
(
i
),
v
)
}
dst
.
Set
(
slice
)
return
nil
}
// requireAssignable assures that `dest` is a pointer and it's not an interface.
func
requireAssignable
(
dst
,
src
reflect
.
Value
)
error
{
if
dst
.
Kind
()
!=
reflect
.
Ptr
&&
dst
.
Kind
()
!=
reflect
.
Interface
{
...
...
accounts/abi/unpack_test.go
浏览文件 @
7df52e32
...
...
@@ -364,6 +364,55 @@ func TestUnpack(t *testing.T) {
}
}
func
TestUnpackSetDynamicArrayOutput
(
t
*
testing
.
T
)
{
abi
,
err
:=
JSON
(
strings
.
NewReader
(
`[{"constant":true,"inputs":[],"name":"testDynamicFixedBytes15","outputs":[{"name":"","type":"bytes15[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"testDynamicFixedBytes32","outputs":[{"name":"","type":"bytes32[]"}],"payable":false,"stateMutability":"view","type":"function"}]`
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
var
(
marshalledReturn32
=
common
.
Hex2Bytes
(
"0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000230783132333435363738393000000000000000000000000000000000000000003078303938373635343332310000000000000000000000000000000000000000"
)
marshalledReturn15
=
common
.
Hex2Bytes
(
"0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000230783031323334350000000000000000000000000000000000000000000000003078393837363534000000000000000000000000000000000000000000000000"
)
out32
[][
32
]
byte
out15
[][
15
]
byte
)
// test 32
err
=
abi
.
Unpack
(
&
out32
,
"testDynamicFixedBytes32"
,
marshalledReturn32
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
out32
)
!=
2
{
t
.
Fatalf
(
"expected array with 2 values, got %d"
,
len
(
out32
))
}
expected
:=
common
.
Hex2Bytes
(
"3078313233343536373839300000000000000000000000000000000000000000"
)
if
!
bytes
.
Equal
(
out32
[
0
][
:
],
expected
)
{
t
.
Errorf
(
"expected %x, got %x
\n
"
,
expected
,
out32
[
0
])
}
expected
=
common
.
Hex2Bytes
(
"3078303938373635343332310000000000000000000000000000000000000000"
)
if
!
bytes
.
Equal
(
out32
[
1
][
:
],
expected
)
{
t
.
Errorf
(
"expected %x, got %x
\n
"
,
expected
,
out32
[
1
])
}
// test 15
err
=
abi
.
Unpack
(
&
out15
,
"testDynamicFixedBytes32"
,
marshalledReturn15
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
out15
)
!=
2
{
t
.
Fatalf
(
"expected array with 2 values, got %d"
,
len
(
out15
))
}
expected
=
common
.
Hex2Bytes
(
"307830313233343500000000000000"
)
if
!
bytes
.
Equal
(
out15
[
0
][
:
],
expected
)
{
t
.
Errorf
(
"expected %x, got %x
\n
"
,
expected
,
out15
[
0
])
}
expected
=
common
.
Hex2Bytes
(
"307839383736353400000000000000"
)
if
!
bytes
.
Equal
(
out15
[
1
][
:
],
expected
)
{
t
.
Errorf
(
"expected %x, got %x
\n
"
,
expected
,
out15
[
1
])
}
}
type
methodMultiOutput
struct
{
Int
*
big
.
Int
String
string
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录