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
a49c8154
Commit
a49c8154
authored
Mar 26, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DecodeParamError -> InvalidTypeError for unexpected input type
parent
ca03e976
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
53 deletions
+53
-53
args.go
rpc/args.go
+27
-27
args_test.go
rpc/args_test.go
+26
-26
No files found.
rpc/args.go
View file @
a49c8154
...
...
@@ -27,7 +27,7 @@ func blockHeight(raw interface{}, number *int64) error {
// Parse as string/hexstring
str
,
ok
:=
raw
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"BlockNumber is
not a number or string"
)
return
New
InvalidTypeError
(
"blockNumber"
,
"
not a number or string"
)
}
switch
str
{
...
...
@@ -60,7 +60,7 @@ func (args *GetBlockByHashArgs) UnmarshalJSON(b []byte) (err error) {
argstr
,
ok
:=
obj
[
0
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"BlockHash
not a string"
)
return
New
InvalidTypeError
(
"blockHash"
,
"
not a string"
)
}
args
.
BlockHash
=
common
.
HexToHash
(
argstr
)
...
...
@@ -92,7 +92,7 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
}
else
if
v
,
ok
:=
obj
[
0
]
.
(
string
);
ok
{
args
.
BlockNumber
=
common
.
Big
(
v
)
.
Int64
()
}
else
{
return
New
DecodeParamError
(
"blockNumber must be
number or string"
)
return
New
InvalidTypeError
(
"blockNumber"
,
"not a
number or string"
)
}
if
len
(
obj
)
>
1
{
...
...
@@ -170,7 +170,7 @@ func (args *GetStorageArgs) UnmarshalJSON(b []byte) (err error) {
addstr
,
ok
:=
obj
[
0
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"address is
not a string"
)
return
New
InvalidTypeError
(
"address"
,
"
not a string"
)
}
args
.
Address
=
common
.
HexToAddress
(
addstr
)
...
...
@@ -201,13 +201,13 @@ func (args *GetStorageAtArgs) UnmarshalJSON(b []byte) (err error) {
addstr
,
ok
:=
obj
[
0
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"Address is
not a string"
)
return
New
InvalidTypeError
(
"address"
,
"
not a string"
)
}
args
.
Address
=
common
.
HexToAddress
(
addstr
)
keystr
,
ok
:=
obj
[
1
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"Key is
not a string"
)
return
New
InvalidTypeError
(
"key"
,
"
not a string"
)
}
args
.
Key
=
common
.
HexToHash
(
keystr
)
...
...
@@ -237,7 +237,7 @@ func (args *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) {
addstr
,
ok
:=
obj
[
0
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"Address is
not a string"
)
return
New
InvalidTypeError
(
"address"
,
"
not a string"
)
}
args
.
Address
=
common
.
HexToAddress
(
addstr
)
...
...
@@ -267,7 +267,7 @@ func (args *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) {
addstr
,
ok
:=
obj
[
0
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"Address is
not a string"
)
return
New
InvalidTypeError
(
"address"
,
"
not a string"
)
}
args
.
Address
=
common
.
HexToAddress
(
addstr
)
...
...
@@ -297,7 +297,7 @@ func (args *GetDataArgs) UnmarshalJSON(b []byte) (err error) {
addstr
,
ok
:=
obj
[
0
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"Address is
not a string"
)
return
New
InvalidTypeError
(
"address"
,
"
not a string"
)
}
args
.
Address
=
addstr
...
...
@@ -335,14 +335,14 @@ func (args *BlockNumIndexArgs) UnmarshalJSON(b []byte) (err error) {
arg0
,
ok
:=
obj
[
0
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"BlockNumber is not
string"
)
return
New
InvalidTypeError
(
"blockNumber"
,
"not a
string"
)
}
args
.
BlockNumber
=
common
.
Big
(
arg0
)
.
Int64
()
if
len
(
obj
)
>
1
{
arg1
,
ok
:=
obj
[
1
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"Index
not a string"
)
return
New
InvalidTypeError
(
"index"
,
"
not a string"
)
}
args
.
Index
=
common
.
Big
(
arg1
)
.
Int64
()
}
...
...
@@ -368,14 +368,14 @@ func (args *HashIndexArgs) UnmarshalJSON(b []byte) (err error) {
arg0
,
ok
:=
obj
[
0
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"Hash
not a string"
)
return
New
InvalidTypeError
(
"hash"
,
"
not a string"
)
}
args
.
Hash
=
arg0
if
len
(
obj
)
>
1
{
arg1
,
ok
:=
obj
[
1
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"Index
not a string"
)
return
New
InvalidTypeError
(
"index"
,
"
not a string"
)
}
args
.
Index
=
common
.
Big
(
arg1
)
.
Int64
()
}
...
...
@@ -431,7 +431,7 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) {
fromstr
,
ok
:=
obj
[
0
]
.
FromBlock
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"FromBlock
is not a string"
)
return
New
InvalidTypeError
(
"fromBlock"
,
"
is not a string"
)
}
switch
fromstr
{
...
...
@@ -443,7 +443,7 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) {
tostr
,
ok
:=
obj
[
0
]
.
ToBlock
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"ToBlock is
not a string"
)
return
New
InvalidTypeError
(
"toBlock"
,
"
not a string"
)
}
switch
tostr
{
...
...
@@ -483,19 +483,19 @@ func (args *DbArgs) UnmarshalJSON(b []byte) (err error) {
var
ok
bool
if
objstr
,
ok
=
obj
[
0
]
.
(
string
);
!
ok
{
return
New
DecodeParamError
(
"Database is
not a string"
)
return
New
InvalidTypeError
(
"database"
,
"
not a string"
)
}
args
.
Database
=
objstr
if
objstr
,
ok
=
obj
[
1
]
.
(
string
);
!
ok
{
return
New
DecodeParamError
(
"Key is
not a string"
)
return
New
InvalidTypeError
(
"key"
,
"
not a string"
)
}
args
.
Key
=
objstr
if
len
(
obj
)
>
2
{
objstr
,
ok
=
obj
[
2
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"Value is
not a string"
)
return
New
InvalidTypeError
(
"value"
,
"
not a string"
)
}
args
.
Value
=
[]
byte
(
objstr
)
...
...
@@ -534,19 +534,19 @@ func (args *DbHexArgs) UnmarshalJSON(b []byte) (err error) {
var
ok
bool
if
objstr
,
ok
=
obj
[
0
]
.
(
string
);
!
ok
{
return
New
DecodeParamError
(
"Database is
not a string"
)
return
New
InvalidTypeError
(
"database"
,
"
not a string"
)
}
args
.
Database
=
objstr
if
objstr
,
ok
=
obj
[
1
]
.
(
string
);
!
ok
{
return
New
DecodeParamError
(
"Key is
not a string"
)
return
New
InvalidTypeError
(
"key"
,
"
not a string"
)
}
args
.
Key
=
objstr
if
len
(
obj
)
>
2
{
objstr
,
ok
=
obj
[
2
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"Value is
not a string"
)
return
New
InvalidTypeError
(
"value"
,
"
not a string"
)
}
args
.
Value
=
common
.
FromHex
(
objstr
)
...
...
@@ -557,10 +557,10 @@ func (args *DbHexArgs) UnmarshalJSON(b []byte) (err error) {
func
(
a
*
DbHexArgs
)
requirements
()
error
{
if
len
(
a
.
Database
)
==
0
{
return
New
Validation
Error
(
"Database"
,
"cannot be blank"
)
return
New
InvalidType
Error
(
"Database"
,
"cannot be blank"
)
}
if
len
(
a
.
Key
)
==
0
{
return
New
Validation
Error
(
"Key"
,
"cannot be blank"
)
return
New
InvalidType
Error
(
"Key"
,
"cannot be blank"
)
}
return
nil
}
...
...
@@ -637,7 +637,7 @@ func (args *FilterStringArgs) UnmarshalJSON(b []byte) (err error) {
var
argstr
string
argstr
,
ok
:=
obj
[
0
]
.
(
string
)
if
!
ok
{
return
New
DecodeParamError
(
"Filter is
not a string"
)
return
New
InvalidTypeError
(
"filter"
,
"
not a string"
)
}
args
.
Word
=
argstr
...
...
@@ -741,18 +741,18 @@ func (args *SubmitWorkArgs) UnmarshalJSON(b []byte) (err error) {
var
objstr
string
var
ok
bool
if
objstr
,
ok
=
obj
[
0
]
.
(
string
);
!
ok
{
return
New
DecodeParamError
(
"Nonce is
not a string"
)
return
New
InvalidTypeError
(
"nonce"
,
"
not a string"
)
}
args
.
Nonce
=
common
.
String2Big
(
objstr
)
.
Uint64
()
if
objstr
,
ok
=
obj
[
1
]
.
(
string
);
!
ok
{
return
New
DecodeParamError
(
"Header is
not a string"
)
return
New
InvalidTypeError
(
"header"
,
"
not a string"
)
}
args
.
Header
=
common
.
HexToHash
(
objstr
)
if
objstr
,
ok
=
obj
[
2
]
.
(
string
);
!
ok
{
return
New
DecodeParamError
(
"Digest is
not a string"
)
return
New
InvalidTypeError
(
"digest"
,
"
not a string"
)
}
args
.
Digest
=
common
.
HexToHash
(
objstr
)
...
...
rpc/args_test.go
View file @
a49c8154
...
...
@@ -99,10 +99,10 @@ func TestGetBalanceArgsBlockInvalid(t *testing.T) {
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParam
Error
:
case
*
InvalidType
Error
:
break
default
:
t
.
Errorf
(
"Expected *rpc.
DecodeParam
Error but got %T with message %s"
,
err
,
err
.
Error
())
t
.
Errorf
(
"Expected *rpc.
InvalidType
Error but got %T with message %s"
,
err
,
err
.
Error
())
}
}
...
...
@@ -114,10 +114,10 @@ func TestGetBalanceArgsAddressInvalid(t *testing.T) {
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParam
Error
:
case
*
InvalidType
Error
:
break
default
:
t
.
Errorf
(
"Expected *rpc.
DecodeParam
Error but got %T with message %s"
,
err
,
err
.
Error
())
t
.
Errorf
(
"Expected *rpc.
InvalidType
Error but got %T with message %s"
,
err
,
err
.
Error
())
}
}
...
...
@@ -179,10 +179,10 @@ func TestGetBlockByHashArgsHashInt(t *testing.T) {
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParam
Error
:
case
*
InvalidType
Error
:
break
default
:
t
.
Errorf
(
"Expected *rpc.
DecodeParam
Error but got %T with message %s"
,
err
,
err
.
Error
())
t
.
Errorf
(
"Expected *rpc.
InvalidType
Error but got %T with message %s"
,
err
,
err
.
Error
())
}
}
...
...
@@ -249,10 +249,10 @@ func TestGetBlockByNumberBool(t *testing.T) {
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParam
Error
:
case
*
InvalidType
Error
:
break
default
:
t
.
Errorf
(
"Expected *rpc.
DecodeParam
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
t
.
Errorf
(
"Expected *rpc.
InvalidType
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
func
TestGetBlockByNumberBlockObject
(
t
*
testing
.
T
)
{
...
...
@@ -352,10 +352,10 @@ func TestNewTxArgsBlockInvalid(t *testing.T) {
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParam
Error
:
case
*
InvalidType
Error
:
break
default
:
t
.
Errorf
(
"Expeted *rpc.
DecodeParam
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
t
.
Errorf
(
"Expeted *rpc.
InvalidType
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
...
...
@@ -462,10 +462,10 @@ func TestGetStorageInvalidBlockheight(t *testing.T) {
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParam
Error
:
case
*
InvalidType
Error
:
break
default
:
t
.
Errorf
(
"Expected *rpc.
DecodeParam
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
t
.
Errorf
(
"Expected *rpc.
InvalidType
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
...
...
@@ -492,10 +492,10 @@ func TestGetStorageAddressInt(t *testing.T) {
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParam
Error
:
case
*
InvalidType
Error
:
break
default
:
t
.
Errorf
(
"Expected *rpc.
DecodeParam
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
t
.
Errorf
(
"Expected *rpc.
InvalidType
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
...
...
@@ -562,10 +562,10 @@ func TestGetStorageAtArgsAddressNotString(t *testing.T) {
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParam
Error
:
case
*
InvalidType
Error
:
break
default
:
t
.
Errorf
(
"Expected *rpc.
DecodeParam
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
t
.
Errorf
(
"Expected *rpc.
InvalidType
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
...
...
@@ -577,10 +577,10 @@ func TestGetStorageAtArgsKeyNotString(t *testing.T) {
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParam
Error
:
case
*
InvalidType
Error
:
break
default
:
t
.
Errorf
(
"Expected *rpc.
DecodeParam
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
t
.
Errorf
(
"Expected *rpc.
InvalidType
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
...
...
@@ -592,10 +592,10 @@ func TestGetStorageAtArgsValueNotString(t *testing.T) {
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParam
Error
:
case
*
InvalidType
Error
:
break
default
:
t
.
Errorf
(
"Expected *rpc.
DecodeParam
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
t
.
Errorf
(
"Expected *rpc.
InvalidType
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
...
...
@@ -657,10 +657,10 @@ func TestGetTxCountAddressNotString(t *testing.T) {
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParam
Error
:
case
*
InvalidType
Error
:
break
default
:
t
.
Errorf
(
"Expected *rpc.
DecodeParam
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
t
.
Errorf
(
"Expected *rpc.
InvalidType
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
...
...
@@ -672,10 +672,10 @@ func TestGetTxCountBlockheightInvalid(t *testing.T) {
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParam
Error
:
case
*
InvalidType
Error
:
break
default
:
t
.
Errorf
(
"Expected *rpc.
DecodeParam
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
t
.
Errorf
(
"Expected *rpc.
InvalidType
Error but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
...
...
@@ -791,10 +791,10 @@ func TestBlockFilterArgsNums(t *testing.T) {
args
:=
new
(
BlockFilterArgs
)
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
)
switch
err
.
(
type
)
{
case
*
DecodeParam
Error
:
case
*
InvalidType
Error
:
break
default
:
t
.
Errorf
(
"Should have *
DecodeParam
Error but instead have %T"
,
err
)
t
.
Errorf
(
"Should have *
rpc.InvalidType
Error but instead have %T"
,
err
)
}
}
...
...
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