Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
c039bb38
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,体验更适合开发者的 AI 搜索 >>
提交
c039bb38
编写于
6月 10, 2016
作者:
P
Péter Szilágyi
提交者:
GitHub
6月 10, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2653 from tbocek/develop
Negative numbers not properly converted in ABI encoding
上级
6886913f
89c6c5bb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
10 addition
and
64 deletion
+10
-64
accounts/abi/method.go
accounts/abi/method.go
+1
-1
accounts/abi/numbers.go
accounts/abi/numbers.go
+4
-38
accounts/abi/numbers_test.go
accounts/abi/numbers_test.go
+3
-23
accounts/abi/packing.go
accounts/abi/packing.go
+2
-2
未找到文件。
accounts/abi/method.go
浏览文件 @
c039bb38
...
...
@@ -62,7 +62,7 @@ func (m Method) pack(method Method, args ...interface{}) ([]byte, error) {
// calculate the offset
offset
:=
len
(
method
.
Inputs
)
*
32
+
len
(
variableInput
)
// set the offset
ret
=
append
(
ret
,
packNum
(
reflect
.
ValueOf
(
offset
)
,
UintTy
)
...
)
ret
=
append
(
ret
,
packNum
(
reflect
.
ValueOf
(
offset
))
...
)
// Append the packed output to the variable input. The variable input
// will be appended at the end of the input.
variableInput
=
append
(
variableInput
,
packed
...
)
...
...
accounts/abi/numbers.go
浏览文件 @
c039bb38
...
...
@@ -61,54 +61,20 @@ func U256(n *big.Int) []byte {
return
common
.
LeftPadBytes
(
common
.
U256
(
n
)
.
Bytes
(),
32
)
}
func
S256
(
n
*
big
.
Int
)
[]
byte
{
sint
:=
common
.
S256
(
n
)
ret
:=
common
.
LeftPadBytes
(
sint
.
Bytes
(),
32
)
if
sint
.
Cmp
(
common
.
Big0
)
<
0
{
for
i
,
b
:=
range
ret
{
if
b
==
0
{
ret
[
i
]
=
1
continue
}
break
}
}
return
ret
}
// S256 will ensure signed 256bit on big nums
func
U2U256
(
n
uint64
)
[]
byte
{
return
U256
(
big
.
NewInt
(
int64
(
n
)))
}
func
S2S256
(
n
int64
)
[]
byte
{
return
S256
(
big
.
NewInt
(
n
))
}
// packNum packs the given number (using the reflect value) and will cast it to appropriate number representation
func
packNum
(
value
reflect
.
Value
,
to
byte
)
[]
byte
{
func
packNum
(
value
reflect
.
Value
)
[]
byte
{
switch
kind
:=
value
.
Kind
();
kind
{
case
reflect
.
Uint
,
reflect
.
Uint8
,
reflect
.
Uint16
,
reflect
.
Uint32
,
reflect
.
Uint64
:
if
to
==
UintTy
{
return
U2U256
(
value
.
Uint
())
}
else
{
return
S2S256
(
int64
(
value
.
Uint
()))
}
return
U2U256
(
value
.
Uint
())
case
reflect
.
Int
,
reflect
.
Int8
,
reflect
.
Int16
,
reflect
.
Int32
,
reflect
.
Int64
:
if
to
==
UintTy
{
return
U2U256
(
uint64
(
value
.
Int
()))
}
else
{
return
S2S256
(
value
.
Int
())
}
return
U2U256
(
uint64
(
value
.
Int
()))
case
reflect
.
Ptr
:
// This only takes care of packing and casting. No type checking is done here. It should be done prior to using this function.
if
to
==
UintTy
{
return
U256
(
value
.
Interface
()
.
(
*
big
.
Int
))
}
else
{
return
S256
(
value
.
Interface
()
.
(
*
big
.
Int
))
}
return
U256
(
value
.
Interface
()
.
(
*
big
.
Int
))
}
return
nil
...
...
accounts/abi/numbers_test.go
浏览文件 @
c039bb38
...
...
@@ -26,48 +26,28 @@ import (
func
TestNumberTypes
(
t
*
testing
.
T
)
{
ubytes
:=
make
([]
byte
,
32
)
ubytes
[
31
]
=
1
sbytesmin
:=
[]
byte
{
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
}
unsigned
:=
U256
(
big
.
NewInt
(
1
))
if
!
bytes
.
Equal
(
unsigned
,
ubytes
)
{
t
.
Errorf
(
"expected %x got %x"
,
ubytes
,
unsigned
)
}
signed
:=
S256
(
big
.
NewInt
(
1
))
if
!
bytes
.
Equal
(
signed
,
ubytes
)
{
t
.
Errorf
(
"expected %x got %x"
,
ubytes
,
unsigned
)
}
signed
=
S256
(
big
.
NewInt
(
-
1
))
if
!
bytes
.
Equal
(
signed
,
sbytesmin
)
{
t
.
Errorf
(
"expected %x got %x"
,
ubytes
,
unsigned
)
}
}
func
TestPackNumber
(
t
*
testing
.
T
)
{
ubytes
:=
make
([]
byte
,
32
)
ubytes
[
31
]
=
1
sbytesmin
:=
[]
byte
{
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
}
maxunsigned
:=
[]
byte
{
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
}
packed
:=
packNum
(
reflect
.
ValueOf
(
1
),
IntTy
)
if
!
bytes
.
Equal
(
packed
,
ubytes
)
{
t
.
Errorf
(
"expected %x got %x"
,
ubytes
,
packed
)
}
packed
=
packNum
(
reflect
.
ValueOf
(
-
1
),
IntTy
)
if
!
bytes
.
Equal
(
packed
,
sbytesmin
)
{
t
.
Errorf
(
"expected %x got %x"
,
ubytes
,
packed
)
}
packed
=
packNum
(
reflect
.
ValueOf
(
1
),
UintTy
)
packed
:=
packNum
(
reflect
.
ValueOf
(
1
))
if
!
bytes
.
Equal
(
packed
,
ubytes
)
{
t
.
Errorf
(
"expected %x got %x"
,
ubytes
,
packed
)
}
packed
=
packNum
(
reflect
.
ValueOf
(
-
1
)
,
UintTy
)
packed
=
packNum
(
reflect
.
ValueOf
(
-
1
))
if
!
bytes
.
Equal
(
packed
,
maxunsigned
)
{
t
.
Errorf
(
"expected %x got %x"
,
maxunsigned
,
packed
)
}
packed
=
packNum
(
reflect
.
ValueOf
(
"string"
)
,
UintTy
)
packed
=
packNum
(
reflect
.
ValueOf
(
"string"
))
if
packed
!=
nil
{
t
.
Errorf
(
"expected 'string' to pack to nil. got %x instead"
,
packed
)
}
...
...
accounts/abi/packing.go
浏览文件 @
c039bb38
...
...
@@ -25,7 +25,7 @@ import (
// packBytesSlice packs the given bytes as [L, V] as the canonical representation
// bytes slice
func
packBytesSlice
(
bytes
[]
byte
,
l
int
)
[]
byte
{
len
:=
packNum
(
reflect
.
ValueOf
(
l
)
,
UintTy
)
len
:=
packNum
(
reflect
.
ValueOf
(
l
))
return
append
(
len
,
common
.
RightPadBytes
(
bytes
,
(
l
+
31
)
/
32
*
32
)
...
)
}
...
...
@@ -34,7 +34,7 @@ func packBytesSlice(bytes []byte, l int) []byte {
func
packElement
(
t
Type
,
reflectValue
reflect
.
Value
)
[]
byte
{
switch
t
.
T
{
case
IntTy
,
UintTy
:
return
packNum
(
reflectValue
,
t
.
T
)
return
packNum
(
reflectValue
)
case
StringTy
:
return
packBytesSlice
([]
byte
(
reflectValue
.
String
()),
reflectValue
.
Len
())
case
AddressTy
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录