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
60b780c2
Commit
60b780c2
authored
Jun 09, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1217 from tgerring/rpcsign
Fix RPC sign
parents
76148515
04641186
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
13 deletions
+74
-13
args.go
rpc/args.go
+13
-13
args_test.go
rpc/args_test.go
+61
-0
No files found.
rpc/args.go
View file @
60b780c2
...
...
@@ -172,13 +172,8 @@ type NewSigArgs struct {
}
func
(
args
*
NewSigArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
json
.
RawMessage
var
ext
struct
{
From
string
Data
string
}
var
obj
[]
interface
{}
// Decode byte slice to array of RawMessages
if
err
:=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
return
NewDecodeParamError
(
err
.
Error
())
}
...
...
@@ -188,21 +183,26 @@ func (args *NewSigArgs) UnmarshalJSON(b []byte) (err error) {
return
NewInsufficientParamsError
(
len
(
obj
),
1
)
}
// Decode 0th RawMessage to temporary struct
if
err
:=
json
.
Unmarshal
(
obj
[
0
],
&
ext
);
err
!=
nil
{
return
New
DecodeParamError
(
err
.
Error
()
)
from
,
ok
:=
obj
[
0
]
.
(
string
)
if
!
ok
{
return
New
InvalidTypeError
(
"from"
,
"not a string"
)
}
args
.
From
=
from
if
len
(
ext
.
From
)
==
0
{
if
len
(
args
.
From
)
==
0
{
return
NewValidationError
(
"from"
,
"is required"
)
}
if
len
(
ext
.
Data
)
==
0
{
data
,
ok
:=
obj
[
1
]
.
(
string
)
if
!
ok
{
return
NewInvalidTypeError
(
"data"
,
"not a string"
)
}
args
.
Data
=
data
if
len
(
args
.
Data
)
==
0
{
return
NewValidationError
(
"data"
,
"is required"
)
}
args
.
From
=
ext
.
From
args
.
Data
=
ext
.
Data
return
nil
}
...
...
rpc/args_test.go
View file @
60b780c2
...
...
@@ -2508,3 +2508,64 @@ func TestSourceArgsEmpty(t *testing.T) {
t
.
Error
(
str
)
}
}
func
TestSigArgs
(
t
*
testing
.
T
)
{
input
:=
`["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x0"]`
expected
:=
new
(
NewSigArgs
)
expected
.
From
=
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"
expected
.
Data
=
"0x0"
args
:=
new
(
NewSigArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
}
func
TestSigArgsEmptyData
(
t
*
testing
.
T
)
{
input
:=
`["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", ""]`
args
:=
new
(
NewSigArgs
)
str
:=
ExpectValidationError
(
json
.
Unmarshal
([]
byte
(
input
),
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestSigArgsDataType
(
t
*
testing
.
T
)
{
input
:=
`["0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b", 13]`
args
:=
new
(
NewSigArgs
)
str
:=
ExpectInvalidTypeError
(
json
.
Unmarshal
([]
byte
(
input
),
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestSigArgsEmptyFrom
(
t
*
testing
.
T
)
{
input
:=
`["", "0x0"]`
args
:=
new
(
NewSigArgs
)
str
:=
ExpectValidationError
(
json
.
Unmarshal
([]
byte
(
input
),
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestSigArgsFromType
(
t
*
testing
.
T
)
{
input
:=
`[false, "0x0"]`
args
:=
new
(
NewSigArgs
)
str
:=
ExpectInvalidTypeError
(
json
.
Unmarshal
([]
byte
(
input
),
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestSigArgsEmpty
(
t
*
testing
.
T
)
{
input
:=
`[]`
args
:=
new
(
NewSigArgs
)
str
:=
ExpectInsufficientParamsError
(
json
.
Unmarshal
([]
byte
(
input
),
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
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