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
a5330fe0
Commit
a5330fe0
authored
Oct 12, 2017
by
Yondon Fu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/abi: include fixed array size in offset for dynamic type
parent
8d8034fe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
1 deletion
+62
-1
abi_test.go
accounts/abi/abi_test.go
+50
-0
method.go
accounts/abi/method.go
+12
-1
No files found.
accounts/abi/abi_test.go
View file @
a5330fe0
...
...
@@ -367,6 +367,56 @@ func TestInputVariableInputLength(t *testing.T) {
}
}
func
TestInputFixedArrayAndVariableInputLength
(
t
*
testing
.
T
)
{
const
definition
=
`[
{ "type" : "function", "name" : "fixedArrStr", "constant" : true, "inputs" : [ { "name" : "str", "type" : "string" }, { "name" : "fixedArr", "type" : "uint256[2]" } ] },
{ "type" : "function", "name" : "fixedArrBytes", "constant" : true, "inputs" : [ { "name" : "str", "type" : "bytes" }, { "name" : "fixedArr", "type" : "uint256[2]" } ] }
]`
abi
,
err
:=
JSON
(
strings
.
NewReader
(
definition
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
// test fixed array of uint256 and a string
arrin
:=
[
2
]
*
big
.
Int
{
big
.
NewInt
(
1
),
big
.
NewInt
(
2
)}
strin
:=
"hello world"
fixedArrStrPack
,
err
:=
abi
.
Pack
(
"fixedArrStr"
,
strin
,
arrin
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
offset
:=
make
([]
byte
,
32
)
offset
[
31
]
=
96
length
:=
make
([]
byte
,
32
)
length
[
31
]
=
byte
(
len
(
strin
))
strvalue
:=
common
.
RightPadBytes
([]
byte
(
strin
),
32
)
arrinvalue1
:=
common
.
LeftPadBytes
(
arrin
[
0
]
.
Bytes
(),
32
)
arrinvalue2
:=
common
.
LeftPadBytes
(
arrin
[
1
]
.
Bytes
(),
32
)
exp
:=
append
(
offset
,
arrinvalue1
...
)
exp
=
append
(
exp
,
arrinvalue2
...
)
exp
=
append
(
exp
,
append
(
length
,
strvalue
...
)
...
)
// ignore first 4 bytes of the output. This is the function identifier
fixedArrStrPack
=
fixedArrStrPack
[
4
:
]
if
!
bytes
.
Equal
(
fixedArrStrPack
,
exp
)
{
t
.
Errorf
(
"expected %x, got %x
\n
"
,
exp
,
fixedArrStrPack
)
}
// test fixed array of uint256 and a byte array
bytesin
:=
[]
byte
(
strin
)
fixedArrBytesPack
,
err
:=
abi
.
Pack
(
"fixedArrBytes"
,
bytesin
,
arrin
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
// ignore first 4 bytes of the output. This is the function identifier
fixedArrBytesPack
=
fixedArrBytesPack
[
4
:
]
if
!
bytes
.
Equal
(
fixedArrBytesPack
,
exp
)
{
t
.
Errorf
(
"expected %x, got %x
\n
"
,
exp
,
fixedArrBytesPack
)
}
}
func
TestDefaultFunctionParsing
(
t
*
testing
.
T
)
{
const
definition
=
`[{ "name" : "balance" }]`
...
...
accounts/abi/method.go
View file @
a5330fe0
...
...
@@ -48,6 +48,16 @@ func (method Method) pack(args ...interface{}) ([]byte, error) {
// output. This is used for strings and bytes types input.
var
variableInput
[]
byte
// input offset is the bytes offset for packed output
inputOffset
:=
0
for
_
,
input
:=
range
method
.
Inputs
{
if
input
.
Type
.
IsArray
{
inputOffset
+=
(
32
*
input
.
Type
.
SliceSize
)
}
else
{
inputOffset
+=
32
}
}
var
ret
[]
byte
for
i
,
a
:=
range
args
{
input
:=
method
.
Inputs
[
i
]
...
...
@@ -60,7 +70,8 @@ func (method Method) pack(args ...interface{}) ([]byte, error) {
// check for a slice type (string, bytes, slice)
if
input
.
Type
.
requiresLengthPrefix
()
{
// calculate the offset
offset
:=
len
(
method
.
Inputs
)
*
32
+
len
(
variableInput
)
offset
:=
inputOffset
+
len
(
variableInput
)
// set the offset
ret
=
append
(
ret
,
packNum
(
reflect
.
ValueOf
(
offset
))
...
)
// Append the packed output to the variable input. The variable input
...
...
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