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
9c4504dc
Commit
9c4504dc
authored
Mar 26, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GetStorageAtArgs
parent
300d36b8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
27 deletions
+74
-27
api.go
rpc/api.go
+2
-5
args.go
rpc/args.go
+4
-15
args_test.go
rpc/args_test.go
+68
-7
No files found.
rpc/api.go
View file @
9c4504dc
...
...
@@ -112,12 +112,9 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
if
err
:=
args
.
requirements
();
err
!=
nil
{
return
err
}
state
:=
api
.
xethAtStateNum
(
args
.
BlockNumber
)
.
State
()
.
SafeGet
(
args
.
Address
)
value
:=
state
.
StorageString
(
args
.
Key
)
state
:=
api
.
xethAtStateNum
(
args
.
BlockNumber
)
.
State
()
.
SafeGet
(
args
.
Address
.
Hex
()
)
value
:=
state
.
StorageString
(
args
.
Key
.
Hex
()
)
*
reply
=
common
.
Bytes2Hex
(
value
.
Bytes
())
case
"eth_getTransactionCount"
:
...
...
rpc/args.go
View file @
9c4504dc
...
...
@@ -184,8 +184,8 @@ func (args *GetStorageArgs) UnmarshalJSON(b []byte) (err error) {
}
type
GetStorageAtArgs
struct
{
Address
string
Key
string
Address
common
.
Address
Key
common
.
Hash
BlockNumber
int64
}
...
...
@@ -203,13 +203,13 @@ func (args *GetStorageAtArgs) UnmarshalJSON(b []byte) (err error) {
if
!
ok
{
return
NewDecodeParamError
(
"Address is not a string"
)
}
args
.
Address
=
addstr
args
.
Address
=
common
.
HexToAddress
(
addstr
)
keystr
,
ok
:=
obj
[
1
]
.
(
string
)
if
!
ok
{
return
NewDecodeParamError
(
"Key is not a string"
)
}
args
.
Key
=
keystr
args
.
Key
=
common
.
HexToHash
(
keystr
)
if
len
(
obj
)
>
2
{
if
err
:=
blockHeight
(
obj
[
2
],
&
args
.
BlockNumber
);
err
!=
nil
{
...
...
@@ -220,17 +220,6 @@ func (args *GetStorageAtArgs) UnmarshalJSON(b []byte) (err error) {
return
nil
}
func
(
args
*
GetStorageAtArgs
)
requirements
()
error
{
if
len
(
args
.
Address
)
==
0
{
return
NewValidationError
(
"Address"
,
"cannot be blank"
)
}
if
len
(
args
.
Key
)
==
0
{
return
NewValidationError
(
"Key"
,
"cannot be blank"
)
}
return
nil
}
type
GetTxCountArgs
struct
{
Address
string
BlockNumber
int64
...
...
rpc/args_test.go
View file @
9c4504dc
...
...
@@ -461,8 +461,8 @@ func TestGetStorageAddressInt(t *testing.T) {
func
TestGetStorageAtArgs
(
t
*
testing
.
T
)
{
input
:=
`["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x0", "0x2"]`
expected
:=
new
(
GetStorageAtArgs
)
expected
.
Address
=
"0x407d73d8a49eeb85d32cf465507dd71d507100c1"
expected
.
Key
=
"0x0"
expected
.
Address
=
common
.
HexToAddress
(
"0x407d73d8a49eeb85d32cf465507dd71d507100c1"
)
expected
.
Key
=
common
.
HexToHash
(
"0x0"
)
expected
.
BlockNumber
=
2
args
:=
new
(
GetStorageAtArgs
)
...
...
@@ -470,10 +470,6 @@ func TestGetStorageAtArgs(t *testing.T) {
t
.
Error
(
err
)
}
if
err
:=
args
.
requirements
();
err
!=
nil
{
t
.
Error
(
err
)
}
if
expected
.
Address
!=
args
.
Address
{
t
.
Errorf
(
"Address shoud be %#v but is %#v"
,
expected
.
Address
,
args
.
Address
)
}
...
...
@@ -492,8 +488,73 @@ func TestGetStorageAtEmptyArgs(t *testing.T) {
args
:=
new
(
GetStorageAtArgs
)
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
)
if
err
==
nil
{
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
InsufficientParamsError
:
break
default
:
t
.
Errorf
(
"Expected *rpc.InsufficientParamsError but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
func
TestGetStorageAtArgsInvalid
(
t
*
testing
.
T
)
{
input
:=
`{}`
args
:=
new
(
GetStorageAtArgs
)
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
)
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParamError
:
break
default
:
t
.
Errorf
(
"Expected *rpc.DecodeParamError but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
func
TestGetStorageAtArgsAddressNotString
(
t
*
testing
.
T
)
{
input
:=
`[true, "0x0", "0x2"]`
args
:=
new
(
GetStorageAtArgs
)
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
)
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParamError
:
break
default
:
t
.
Errorf
(
"Expected *rpc.DecodeParamError but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
func
TestGetStorageAtArgsKeyNotString
(
t
*
testing
.
T
)
{
input
:=
`["0x407d73d8a49eeb85d32cf465507dd71d507100c1", true, "0x2"]`
args
:=
new
(
GetStorageAtArgs
)
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
)
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParamError
:
break
default
:
t
.
Errorf
(
"Expected *rpc.DecodeParamError but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
func
TestGetStorageAtArgsValueNotString
(
t
*
testing
.
T
)
{
input
:=
`["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "0x1", true]`
args
:=
new
(
GetStorageAtArgs
)
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
)
switch
err
.
(
type
)
{
case
nil
:
t
.
Error
(
"Expected error but didn't get one"
)
case
*
DecodeParamError
:
break
default
:
t
.
Errorf
(
"Expected *rpc.DecodeParamError but got %T with message `%s`"
,
err
,
err
.
Error
())
}
}
...
...
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