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
08c5d4dd
Unverified
Commit
08c5d4dd
authored
Jan 13, 2018
by
Martin Holst Swende
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/abi: address review concerns
parent
f0f594d0
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
5 additions
and
352 deletions
+5
-352
abi.go
accounts/abi/abi.go
+1
-1
abi_test.go
accounts/abi/abi_test.go
+1
-1
argument.go
accounts/abi/argument.go
+3
-15
unpackv2_test.go
accounts/abi/unpackv2_test.go
+0
-335
No files found.
accounts/abi/abi.go
View file @
08c5d4dd
...
...
@@ -142,5 +142,5 @@ func (abi *ABI) MethodById(sigdata []byte) (*Method, error) {
return
&
method
,
nil
}
}
return
nil
,
fmt
.
Errorf
(
"
ABI spec does not contain method signature in data: 0x%
x"
,
sigdata
[
:
4
])
return
nil
,
fmt
.
Errorf
(
"
no method with id: %#
x"
,
sigdata
[
:
4
])
}
accounts/abi/abi_test.go
View file @
08c5d4dd
...
...
@@ -691,7 +691,7 @@ func TestABI_MethodById(t *testing.T) {
a
:=
fmt
.
Sprintf
(
"%v"
,
m
)
m2
,
err
:=
abi
.
MethodById
(
m
.
Id
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
f
(
"Failed to look up ABI method: %v"
,
err
)
}
b
:=
fmt
.
Sprintf
(
"%v"
,
m2
)
if
a
!=
b
{
...
...
accounts/abi/argument.go
View file @
08c5d4dd
...
...
@@ -67,6 +67,7 @@ func (arguments Arguments) LengthNonIndexed() int {
return
out
}
// NonIndexed returns the arguments with indexed arguments filtered out
func
(
arguments
Arguments
)
NonIndexed
()
Arguments
{
var
ret
[]
Argument
for
_
,
arg
:=
range
arguments
{
...
...
@@ -89,12 +90,10 @@ func (arguments Arguments) Unpack(v interface{}, data []byte) error {
if
reflect
.
Ptr
!=
reflect
.
ValueOf
(
v
)
.
Kind
()
{
return
fmt
.
Errorf
(
"abi: Unpack(non-pointer %T)"
,
v
)
}
marshalledValues
,
err
:=
arguments
.
UnpackValues
(
data
)
if
err
!=
nil
{
return
err
}
if
arguments
.
isTuple
()
{
return
arguments
.
unpackTuple
(
v
,
marshalledValues
)
}
...
...
@@ -162,11 +161,9 @@ func (arguments Arguments) unpackTuple(v interface{}, marshalledValues []interfa
// unpackAtomic unpacks ( hexdata -> go ) a single value
func
(
arguments
Arguments
)
unpackAtomic
(
v
interface
{},
marshalledValues
[]
interface
{})
error
{
if
len
(
marshalledValues
)
!=
1
{
return
fmt
.
Errorf
(
"abi: wrong length, expected single value, got %d"
,
len
(
marshalledValues
))
}
elem
:=
reflect
.
ValueOf
(
v
)
.
Elem
()
reflectValue
:=
reflect
.
ValueOf
(
marshalledValues
[
0
])
return
set
(
elem
,
reflectValue
,
arguments
.
NonIndexed
()[
0
])
...
...
@@ -176,24 +173,18 @@ func (arguments Arguments) unpackAtomic(v interface{}, marshalledValues []interf
// without supplying a struct to unpack into. Instead, this method returns a list containing the
// values. An atomic argument will be a list with one element.
func
(
arguments
Arguments
)
UnpackValues
(
data
[]
byte
)
([]
interface
{},
error
)
{
retval
:=
make
([]
interface
{},
0
,
arguments
.
LengthNonIndexed
())
virtualArgs
:=
0
for
index
,
arg
:=
range
arguments
.
NonIndexed
()
{
marshalledValue
,
err
:=
toGoType
((
index
+
virtualArgs
)
*
32
,
arg
.
Type
,
data
)
if
arg
.
Type
.
T
==
ArrayTy
{
//If we have a static array, like [3]uint256, these are coded as
//
If we have a static array, like [3]uint256, these are coded as
// just like uint256,uint256,uint256.
// This means that we need to add two 'virtual' arguments when
// we count the index from now on
virtualArgs
+=
arg
.
Type
.
Size
-
1
}
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -202,7 +193,7 @@ func (arguments Arguments) UnpackValues(data []byte) ([]interface{}, error) {
return
retval
,
nil
}
//
Unp
ackValues performs the operation Go format -> Hexdata
//
P
ackValues performs the operation Go format -> Hexdata
// It is the semantic opposite of UnpackValues
func
(
arguments
Arguments
)
PackValues
(
args
[]
interface
{})
([]
byte
,
error
)
{
return
arguments
.
Pack
(
args
...
)
...
...
@@ -215,7 +206,6 @@ func (arguments Arguments) Pack(args ...interface{}) ([]byte, error) {
if
len
(
args
)
!=
len
(
abiArgs
)
{
return
nil
,
fmt
.
Errorf
(
"argument count mismatch: %d for %d"
,
len
(
args
),
len
(
abiArgs
))
}
// variable input is the output appended at the end of packed
// output. This is used for strings and bytes types input.
var
variableInput
[]
byte
...
...
@@ -229,7 +219,6 @@ func (arguments Arguments) Pack(args ...interface{}) ([]byte, error) {
inputOffset
+=
32
}
}
var
ret
[]
byte
for
i
,
a
:=
range
args
{
input
:=
abiArgs
[
i
]
...
...
@@ -238,7 +227,6 @@ func (arguments Arguments) Pack(args ...interface{}) ([]byte, error) {
if
err
!=
nil
{
return
nil
,
err
}
// check for a slice type (string, bytes, slice)
if
input
.
Type
.
requiresLengthPrefix
()
{
// calculate the offset
...
...
accounts/abi/unpackv2_test.go
deleted
100644 → 0
View file @
f0f594d0
This diff is collapsed.
Click to expand it.
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