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
e402e1dc
Commit
e402e1dc
authored
Apr 02, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New args types with stricter checking
parent
14c14fd6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
33 deletions
+79
-33
api.go
rpc/api.go
+6
-6
args.go
rpc/args.go
+62
-26
args_test.go
rpc/args_test.go
+11
-1
No files found.
rpc/api.go
View file @
e402e1dc
...
...
@@ -108,15 +108,15 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
count
:=
api
.
xethAtStateNum
(
args
.
BlockNumber
)
.
TxCountAt
(
args
.
Address
)
*
reply
=
common
.
ToHex
(
big
.
NewInt
(
int64
(
count
))
.
Bytes
())
case
"eth_getBlockTransactionCountByHash"
:
args
:=
new
(
GetBlockBy
HashArgs
)
args
:=
new
(
HashArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
block
:=
NewBlockRes
(
api
.
xeth
()
.
EthBlockByHash
(
args
.
Block
Hash
),
false
)
block
:=
NewBlockRes
(
api
.
xeth
()
.
EthBlockByHash
(
args
.
Hash
),
false
)
*
reply
=
common
.
ToHex
(
big
.
NewInt
(
int64
(
len
(
block
.
Transactions
)))
.
Bytes
())
case
"eth_getBlockTransactionCountByNumber"
:
args
:=
new
(
GetBlockByNumberArgs
)
args
:=
new
(
BlockNumArg
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
...
...
@@ -124,16 +124,16 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
block
:=
NewBlockRes
(
api
.
xeth
()
.
EthBlockByNumber
(
args
.
BlockNumber
),
false
)
*
reply
=
common
.
ToHex
(
big
.
NewInt
(
int64
(
len
(
block
.
Transactions
)))
.
Bytes
())
case
"eth_getUncleCountByBlockHash"
:
args
:=
new
(
GetBlockBy
HashArgs
)
args
:=
new
(
HashArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
block
:=
api
.
xeth
()
.
EthBlockByHash
(
args
.
Block
Hash
)
block
:=
api
.
xeth
()
.
EthBlockByHash
(
args
.
Hash
)
br
:=
NewBlockRes
(
block
,
false
)
*
reply
=
common
.
ToHex
(
big
.
NewInt
(
int64
(
len
(
br
.
Uncles
)))
.
Bytes
())
case
"eth_getUncleCountByBlockNumber"
:
args
:=
new
(
GetBlockByNumberArgs
)
args
:=
new
(
BlockNumArg
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
...
...
rpc/args.go
View file @
e402e1dc
...
...
@@ -108,8 +108,8 @@ func (args *GetBlockByHashArgs) UnmarshalJSON(b []byte) (err error) {
return
NewDecodeParamError
(
err
.
Error
())
}
if
len
(
obj
)
<
1
{
return
NewInsufficientParamsError
(
len
(
obj
),
1
)
if
len
(
obj
)
<
2
{
return
NewInsufficientParamsError
(
len
(
obj
),
2
)
}
argstr
,
ok
:=
obj
[
0
]
.
(
string
)
...
...
@@ -118,9 +118,7 @@ func (args *GetBlockByHashArgs) UnmarshalJSON(b []byte) (err error) {
}
args
.
BlockHash
=
argstr
if
len
(
obj
)
>
1
{
args
.
IncludeTxs
=
obj
[
1
]
.
(
bool
)
}
args
.
IncludeTxs
=
obj
[
1
]
.
(
bool
)
return
nil
}
...
...
@@ -136,8 +134,8 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
return
NewDecodeParamError
(
err
.
Error
())
}
if
len
(
obj
)
<
1
{
return
NewInsufficientParamsError
(
len
(
obj
),
1
)
if
len
(
obj
)
<
2
{
return
NewInsufficientParamsError
(
len
(
obj
),
2
)
}
if
v
,
ok
:=
obj
[
0
]
.
(
float64
);
ok
{
...
...
@@ -148,9 +146,7 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
return
NewInvalidTypeError
(
"blockNumber"
,
"not a number or string"
)
}
if
len
(
obj
)
>
1
{
args
.
IncludeTxs
=
obj
[
1
]
.
(
bool
)
}
args
.
IncludeTxs
=
obj
[
1
]
.
(
bool
)
return
nil
}
...
...
@@ -496,6 +492,27 @@ func (args *GetDataArgs) UnmarshalJSON(b []byte) (err error) {
return
nil
}
type
BlockNumArg
struct
{
BlockNumber
int64
}
func
(
args
*
BlockNumArg
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
interface
{}
if
err
:=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
return
NewDecodeParamError
(
err
.
Error
())
}
if
len
(
obj
)
<
1
{
return
NewInsufficientParamsError
(
len
(
obj
),
1
)
}
if
err
:=
blockHeight
(
obj
[
0
],
&
args
.
BlockNumber
);
err
!=
nil
{
return
err
}
return
nil
}
type
BlockNumIndexArgs
struct
{
BlockNumber
int64
Index
int64
...
...
@@ -507,21 +524,42 @@ func (args *BlockNumIndexArgs) UnmarshalJSON(b []byte) (err error) {
return
NewDecodeParamError
(
err
.
Error
())
}
if
len
(
obj
)
<
1
{
return
NewInsufficientParamsError
(
len
(
obj
),
1
)
if
len
(
obj
)
<
2
{
return
NewInsufficientParamsError
(
len
(
obj
),
2
)
}
if
err
:=
blockHeight
(
obj
[
0
],
&
args
.
BlockNumber
);
err
!=
nil
{
return
err
}
if
len
(
obj
)
>
1
{
arg1
,
ok
:=
obj
[
1
]
.
(
string
)
if
!
ok
{
return
NewInvalidTypeError
(
"index"
,
"not a string"
)
}
args
.
Index
=
common
.
Big
(
arg1
)
.
Int64
()
arg1
,
ok
:=
obj
[
1
]
.
(
string
)
if
!
ok
{
return
NewInvalidTypeError
(
"index"
,
"not a string"
)
}
args
.
Index
=
common
.
Big
(
arg1
)
.
Int64
()
return
nil
}
type
HashArgs
struct
{
Hash
string
}
func
(
args
*
HashArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
interface
{}
if
err
:=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
return
NewDecodeParamError
(
err
.
Error
())
}
if
len
(
obj
)
<
1
{
return
NewInsufficientParamsError
(
len
(
obj
),
1
)
}
arg0
,
ok
:=
obj
[
0
]
.
(
string
)
if
!
ok
{
return
NewInvalidTypeError
(
"hash"
,
"not a string"
)
}
args
.
Hash
=
arg0
return
nil
}
...
...
@@ -537,8 +575,8 @@ func (args *HashIndexArgs) UnmarshalJSON(b []byte) (err error) {
return
NewDecodeParamError
(
err
.
Error
())
}
if
len
(
obj
)
<
1
{
return
NewInsufficientParamsError
(
len
(
obj
),
1
)
if
len
(
obj
)
<
2
{
return
NewInsufficientParamsError
(
len
(
obj
),
2
)
}
arg0
,
ok
:=
obj
[
0
]
.
(
string
)
...
...
@@ -547,13 +585,11 @@ func (args *HashIndexArgs) UnmarshalJSON(b []byte) (err error) {
}
args
.
Hash
=
arg0
if
len
(
obj
)
>
1
{
arg1
,
ok
:=
obj
[
1
]
.
(
string
)
if
!
ok
{
return
NewInvalidTypeError
(
"index"
,
"not a string"
)
}
args
.
Index
=
common
.
Big
(
arg1
)
.
Int64
()
arg1
,
ok
:=
obj
[
1
]
.
(
string
)
if
!
ok
{
return
NewInvalidTypeError
(
"index"
,
"not a string"
)
}
args
.
Index
=
common
.
Big
(
arg1
)
.
Int64
()
return
nil
}
...
...
rpc/args_test.go
View file @
e402e1dc
...
...
@@ -225,7 +225,7 @@ func TestGetBlockByHashArgsHashInt(t *testing.T) {
input
:=
`[8]`
args
:=
new
(
GetBlockByHashArgs
)
str
:=
ExpectIn
validType
Error
(
json
.
Unmarshal
([]
byte
(
input
),
&
args
))
str
:=
ExpectIn
sufficientParams
Error
(
json
.
Unmarshal
([]
byte
(
input
),
&
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
...
...
@@ -281,6 +281,16 @@ func TestGetBlockByNumberEmpty(t *testing.T) {
}
}
func
TestGetBlockByNumberShort
(
t
*
testing
.
T
)
{
input
:=
`["0xbbb"]`
args
:=
new
(
GetBlockByNumberArgs
)
str
:=
ExpectInsufficientParamsError
(
json
.
Unmarshal
([]
byte
(
input
),
&
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestGetBlockByNumberBool
(
t
*
testing
.
T
)
{
input
:=
`[true, true]`
...
...
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