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
60a999f2
Commit
60a999f2
authored
Mar 05, 2018
by
Javier Peletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/abi: Modified unpackAtomic to accept struct lvalues
parent
13b566e0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
19 deletions
+49
-19
abi.go
accounts/abi/abi.go
+1
-1
argument.go
accounts/abi/argument.go
+32
-18
reflect.go
accounts/abi/reflect.go
+16
-0
No files found.
accounts/abi/abi.go
View file @
60a999f2
...
...
@@ -86,7 +86,7 @@ func (abi ABI) Unpack(v interface{}, name string, output []byte) (err error) {
}
return
method
.
Outputs
.
Unpack
(
v
,
output
)
}
else
if
event
,
ok
:=
abi
.
Events
[
name
];
ok
{
return
event
.
Inputs
.
unpackTuple
(
v
,
output
)
return
event
.
Inputs
.
Unpack
(
v
,
output
)
}
return
fmt
.
Errorf
(
"abi: could not locate named method or event"
)
}
...
...
accounts/abi/argument.go
View file @
60a999f2
...
...
@@ -113,16 +113,8 @@ func (arguments Arguments) unpackTuple(v interface{}, marshalledValues []interfa
}
// If the output interface is a struct, make sure names don't collide
if
kind
==
reflect
.
Struct
{
exists
:=
make
(
map
[
string
]
bool
)
for
_
,
arg
:=
range
arguments
{
field
:=
capitalise
(
arg
.
Name
)
if
field
==
""
{
return
fmt
.
Errorf
(
"abi: purely underscored output cannot unpack to struct"
)
}
if
exists
[
field
]
{
return
fmt
.
Errorf
(
"abi: multiple outputs mapping to the same struct field '%s'"
,
field
)
}
exists
[
field
]
=
true
if
err
:=
requireUniqueStructFieldNames
(
arguments
);
err
!=
nil
{
return
err
}
}
for
i
,
arg
:=
range
arguments
.
NonIndexed
()
{
...
...
@@ -131,14 +123,9 @@ func (arguments Arguments) unpackTuple(v interface{}, marshalledValues []interfa
switch
kind
{
case
reflect
.
Struct
:
name
:=
capitalise
(
arg
.
Name
)
for
j
:=
0
;
j
<
typ
.
NumField
();
j
++
{
// TODO read tags: `abi:"fieldName"`
if
typ
.
Field
(
j
)
.
Name
==
name
{
if
err
:=
set
(
value
.
Field
(
j
),
reflectValue
,
arg
);
err
!=
nil
{
return
err
}
}
err
:=
unpackStruct
(
value
,
reflectValue
,
arg
)
if
err
!=
nil
{
return
err
}
case
reflect
.
Slice
,
reflect
.
Array
:
if
value
.
Len
()
<
i
{
...
...
@@ -165,8 +152,20 @@ func (arguments Arguments) unpackAtomic(v interface{}, marshalledValues []interf
return
fmt
.
Errorf
(
"abi: wrong length, expected single value, got %d"
,
len
(
marshalledValues
))
}
elem
:=
reflect
.
ValueOf
(
v
)
.
Elem
()
kind
:=
elem
.
Kind
()
reflectValue
:=
reflect
.
ValueOf
(
marshalledValues
[
0
])
if
kind
==
reflect
.
Struct
{
//make sure names don't collide
if
err
:=
requireUniqueStructFieldNames
(
arguments
);
err
!=
nil
{
return
err
}
return
unpackStruct
(
elem
,
reflectValue
,
arguments
[
0
])
}
return
set
(
elem
,
reflectValue
,
arguments
.
NonIndexed
()[
0
])
}
// Computes the full size of an array;
...
...
@@ -278,3 +277,18 @@ func capitalise(input string) string {
}
return
strings
.
ToUpper
(
input
[
:
1
])
+
input
[
1
:
]
}
//unpackStruct extracts each argument into its corresponding struct field
func
unpackStruct
(
value
,
reflectValue
reflect
.
Value
,
arg
Argument
)
error
{
name
:=
capitalise
(
arg
.
Name
)
typ
:=
value
.
Type
()
for
j
:=
0
;
j
<
typ
.
NumField
();
j
++
{
// TODO read tags: `abi:"fieldName"`
if
typ
.
Field
(
j
)
.
Name
==
name
{
if
err
:=
set
(
value
.
Field
(
j
),
reflectValue
,
arg
);
err
!=
nil
{
return
err
}
}
}
return
nil
}
accounts/abi/reflect.go
View file @
60a999f2
...
...
@@ -110,3 +110,19 @@ func requireUnpackKind(v reflect.Value, t reflect.Type, k reflect.Kind,
}
return
nil
}
// requireUniqueStructFieldNames makes sure field names don't collide
func
requireUniqueStructFieldNames
(
args
Arguments
)
error
{
exists
:=
make
(
map
[
string
]
bool
)
for
_
,
arg
:=
range
args
{
field
:=
capitalise
(
arg
.
Name
)
if
field
==
""
{
return
fmt
.
Errorf
(
"abi: purely underscored output cannot unpack to struct"
)
}
if
exists
[
field
]
{
return
fmt
.
Errorf
(
"abi: multiple outputs mapping to the same struct field '%s'"
,
field
)
}
exists
[
field
]
=
true
}
return
nil
}
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