Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
4880868c
Commit
4880868c
authored
Apr 20, 2016
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/abi: fixed string and fixed size bytes packing
parent
c3d52504
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
137 additions
and
85 deletions
+137
-85
abi.go
accounts/abi/abi.go
+4
-4
abi_test.go
accounts/abi/abi_test.go
+120
-74
error.go
accounts/abi/error.go
+3
-4
method.go
accounts/abi/method.go
+1
-1
packing.go
accounts/abi/packing.go
+1
-1
type.go
accounts/abi/type.go
+8
-1
No files found.
accounts/abi/abi.go
View file @
4880868c
...
...
@@ -197,13 +197,13 @@ func toGoType(i int, t Argument, output []byte) (interface{}, error) {
case
reflect
.
Uint64
:
return
uint64
(
bigNum
.
Uint64
()),
nil
case
reflect
.
Int8
:
return
u
int8
(
bigNum
.
Int64
()),
nil
return
int8
(
bigNum
.
Int64
()),
nil
case
reflect
.
Int16
:
return
u
int16
(
bigNum
.
Int64
()),
nil
return
int16
(
bigNum
.
Int64
()),
nil
case
reflect
.
Int32
:
return
u
int32
(
bigNum
.
Int64
()),
nil
return
int32
(
bigNum
.
Int64
()),
nil
case
reflect
.
Int64
:
return
u
int64
(
bigNum
.
Int64
()),
nil
return
int64
(
bigNum
.
Int64
()),
nil
case
reflect
.
Ptr
:
return
bigNum
,
nil
}
...
...
accounts/abi/abi_test.go
View file @
4880868c
This diff is collapsed.
Click to expand it.
accounts/abi/error.go
View file @
4880868c
...
...
@@ -33,7 +33,7 @@ func formatSliceString(kind reflect.Kind, sliceSize int) string {
// sliceTypeCheck checks that the given slice can by assigned to the reflection
// type in t.
func
sliceTypeCheck
(
t
Type
,
val
reflect
.
Value
)
error
{
if
!
(
val
.
Kind
()
==
reflect
.
Slice
||
val
.
Kind
()
==
reflect
.
Array
)
{
if
val
.
Kind
()
!=
reflect
.
Slice
&&
val
.
Kind
()
!=
reflect
.
Array
{
return
typeErr
(
formatSliceString
(
t
.
Kind
,
t
.
SliceSize
),
val
.
Type
())
}
if
t
.
IsArray
&&
val
.
Len
()
!=
t
.
SliceSize
{
...
...
@@ -48,14 +48,13 @@ func sliceTypeCheck(t Type, val reflect.Value) error {
return
sliceTypeCheck
(
*
t
.
Elem
,
val
.
Index
(
0
))
}
elemKind
:=
val
.
Type
()
.
Elem
()
.
Kind
()
if
elemKind
!=
t
.
Elem
.
Kind
{
if
elemKind
:=
val
.
Type
()
.
Elem
()
.
Kind
();
elemKind
!=
t
.
Elem
.
Kind
{
return
typeErr
(
formatSliceString
(
t
.
Elem
.
Kind
,
t
.
SliceSize
),
val
.
Type
())
}
return
nil
}
// typeCheck checks that the
t given reflection val
can be assigned to the reflection
// typeCheck checks that the
given reflection value
can be assigned to the reflection
// type in t.
func
typeCheck
(
t
Type
,
value
reflect
.
Value
)
error
{
if
t
.
IsSlice
||
t
.
IsArray
{
...
...
accounts/abi/method.go
View file @
4880868c
...
...
@@ -58,7 +58,7 @@ func (m Method) pack(method Method, args ...interface{}) ([]byte, error) {
}
// check for a slice type (string, bytes, slice)
if
input
.
Type
.
T
==
StringTy
||
input
.
Type
.
T
==
BytesTy
||
input
.
Type
.
IsSlice
||
input
.
Type
.
IsArray
{
if
input
.
Type
.
requiresLengthPrefix
()
{
// calculate the offset
offset
:=
len
(
method
.
Inputs
)
*
32
+
len
(
variableInput
)
// set the offset
...
...
accounts/abi/packing.go
View file @
4880868c
...
...
@@ -59,7 +59,7 @@ func packElement(t Type, reflectValue reflect.Value) []byte {
reflectValue
=
mustArrayToByteSlice
(
reflectValue
)
}
return
common
.
Lef
tPadBytes
(
reflectValue
.
Bytes
(),
32
)
return
common
.
Righ
tPadBytes
(
reflectValue
.
Bytes
(),
32
)
}
panic
(
"abi: fatal error"
)
}
accounts/abi/type.go
View file @
4880868c
...
...
@@ -89,6 +89,7 @@ func NewType(t string) (typ Type, err error) {
return
Type
{},
err
}
typ
.
Elem
=
&
sliceType
typ
.
stringKind
=
sliceType
.
stringKind
+
t
[
len
(
res
[
1
])
:
]
return
typ
,
nil
}
...
...
@@ -110,6 +111,7 @@ func NewType(t string) (typ Type, err error) {
varSize
=
256
t
+=
"256"
}
typ
.
stringKind
=
t
switch
varType
{
case
"int"
:
...
...
@@ -149,7 +151,6 @@ func NewType(t string) (typ Type, err error) {
default
:
return
Type
{},
fmt
.
Errorf
(
"unsupported arg type: %s"
,
t
)
}
typ
.
stringKind
=
t
return
}
...
...
@@ -181,3 +182,9 @@ func (t Type) pack(v reflect.Value) ([]byte, error) {
return
packElement
(
t
,
v
),
nil
}
// requireLengthPrefix returns whether the type requires any sort of length
// prefixing.
func
(
t
Type
)
requiresLengthPrefix
()
bool
{
return
t
.
T
!=
FixedBytesTy
&&
(
t
.
T
==
StringTy
||
t
.
T
==
BytesTy
||
t
.
IsSlice
||
t
.
IsArray
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment