Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
970f4c06
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 搜索 >>
提交
970f4c06
编写于
6月 14, 2016
作者:
P
Péter Szilágyi
提交者:
GitHub
6月 14, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2680 from karalabe/abi-fix-uints
accounts/abi: fix uint64 upper range encoding.
上级
22ef7370
0f9539e1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
21 deletion
+33
-21
accounts/abi/numbers.go
accounts/abi/numbers.go
+3
-9
accounts/abi/numbers_test.go
accounts/abi/numbers_test.go
+30
-12
未找到文件。
accounts/abi/numbers.go
浏览文件 @
970f4c06
...
...
@@ -56,27 +56,21 @@ var (
big_ts
=
reflect
.
TypeOf
([]
*
big
.
Int
(
nil
))
)
// U256
will ensure unsigned 256bit on big nums
// U256
converts a big Int into a 256bit EVM number.
func
U256
(
n
*
big
.
Int
)
[]
byte
{
return
common
.
LeftPadBytes
(
common
.
U256
(
n
)
.
Bytes
(),
32
)
}
// S256 will ensure signed 256bit on big nums
func
U2U256
(
n
uint64
)
[]
byte
{
return
U256
(
big
.
NewInt
(
int64
(
n
)))
}
// packNum packs the given number (using the reflect value) and will cast it to appropriate number representation
func
packNum
(
value
reflect
.
Value
)
[]
byte
{
switch
kind
:=
value
.
Kind
();
kind
{
case
reflect
.
Uint
,
reflect
.
Uint8
,
reflect
.
Uint16
,
reflect
.
Uint32
,
reflect
.
Uint64
:
return
U2
U256
(
value
.
Uint
(
))
return
U2
56
(
new
(
big
.
Int
)
.
SetUint64
(
value
.
Uint
()
))
case
reflect
.
Int
,
reflect
.
Int8
,
reflect
.
Int16
,
reflect
.
Int32
,
reflect
.
Int64
:
return
U2
U256
(
uint64
(
value
.
Int
()))
return
U2
56
(
big
.
NewInt
(
value
.
Int
()))
case
reflect
.
Ptr
:
return
U256
(
value
.
Interface
()
.
(
*
big
.
Int
))
}
return
nil
}
...
...
accounts/abi/numbers_test.go
浏览文件 @
970f4c06
...
...
@@ -18,6 +18,7 @@ package abi
import
(
"bytes"
"math"
"math/big"
"reflect"
"testing"
...
...
@@ -34,21 +35,38 @@ func TestNumberTypes(t *testing.T) {
}
func
TestPackNumber
(
t
*
testing
.
T
)
{
ubytes
:=
make
([]
byte
,
32
)
ubytes
[
31
]
=
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
}
tests
:=
[]
struct
{
value
reflect
.
Value
packed
[]
byte
}{
// Protocol limits
{
reflect
.
ValueOf
(
0
),
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
}},
{
reflect
.
ValueOf
(
1
),
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
}},
{
reflect
.
ValueOf
(
-
1
),
[]
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
}},
// Type corner cases
{
reflect
.
ValueOf
(
uint8
(
math
.
MaxUint8
)),
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
255
}},
{
reflect
.
ValueOf
(
uint16
(
math
.
MaxUint16
)),
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
255
,
255
}},
{
reflect
.
ValueOf
(
uint32
(
math
.
MaxUint32
)),
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
255
,
255
,
255
,
255
}},
{
reflect
.
ValueOf
(
uint64
(
math
.
MaxUint64
)),
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
255
,
255
,
255
,
255
,
255
,
255
,
255
,
255
}},
packed
:=
packNum
(
reflect
.
ValueOf
(
1
))
if
!
bytes
.
Equal
(
packed
,
ubytes
)
{
t
.
Errorf
(
"expected %x got %x"
,
ubytes
,
packed
)
{
reflect
.
ValueOf
(
int8
(
math
.
MaxInt8
)),
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
127
}},
{
reflect
.
ValueOf
(
int16
(
math
.
MaxInt16
)),
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
127
,
255
}},
{
reflect
.
ValueOf
(
int32
(
math
.
MaxInt32
)),
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
127
,
255
,
255
,
255
}},
{
reflect
.
ValueOf
(
int64
(
math
.
MaxInt64
)),
[]
byte
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
127
,
255
,
255
,
255
,
255
,
255
,
255
,
255
}},
{
reflect
.
ValueOf
(
int8
(
math
.
MinInt8
)),
[]
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
,
128
}},
{
reflect
.
ValueOf
(
int16
(
math
.
MinInt16
)),
[]
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
,
128
,
0
}},
{
reflect
.
ValueOf
(
int32
(
math
.
MinInt32
)),
[]
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
,
128
,
0
,
0
,
0
}},
{
reflect
.
ValueOf
(
int64
(
math
.
MinInt64
)),
[]
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
,
128
,
0
,
0
,
0
,
0
,
0
,
0
,
0
}},
}
packed
=
packNum
(
reflect
.
ValueOf
(
-
1
))
if
!
bytes
.
Equal
(
packed
,
maxunsigned
)
{
t
.
Errorf
(
"expected %x got %x"
,
maxunsigned
,
packed
)
for
i
,
tt
:=
range
tests
{
packed
:=
packNum
(
tt
.
value
)
if
!
bytes
.
Equal
(
packed
,
tt
.
packed
)
{
t
.
Errorf
(
"test %d: pack mismatch: have %x, want %x"
,
i
,
packed
,
tt
.
packed
)
}
}
packed
=
packNum
(
reflect
.
ValueOf
(
"string"
))
if
packed
!=
nil
{
if
packed
:=
packNum
(
reflect
.
ValueOf
(
"string"
));
packed
!=
nil
{
t
.
Errorf
(
"expected 'string' to pack to nil. got %x instead"
,
packed
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录