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
253ecdc8
Commit
253ecdc8
authored
Mar 23, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' of github.com-obscure:ethereum/go-ethereum into develop
parents
9be7853e
3f6e1b2f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
181 additions
and
15 deletions
+181
-15
api.go
rpc/api.go
+29
-4
api_test.go
rpc/api_test.go
+46
-0
args.go
rpc/args.go
+72
-6
args_test.go
rpc/args_test.go
+34
-5
No files found.
rpc/api.go
View file @
253ecdc8
...
@@ -21,7 +21,10 @@ type EthereumApi struct {
...
@@ -21,7 +21,10 @@ type EthereumApi struct {
func
NewEthereumApi
(
xeth
*
xeth
.
XEth
,
dataDir
string
)
*
EthereumApi
{
func
NewEthereumApi
(
xeth
*
xeth
.
XEth
,
dataDir
string
)
*
EthereumApi
{
// What about when dataDir is empty?
// What about when dataDir is empty?
db
,
_
:=
ethdb
.
NewLDBDatabase
(
path
.
Join
(
dataDir
,
"dapps"
))
db
,
err
:=
ethdb
.
NewLDBDatabase
(
path
.
Join
(
dataDir
,
"dapps"
))
if
err
!=
nil
{
panic
(
err
)
}
api
:=
&
EthereumApi
{
api
:=
&
EthereumApi
{
eth
:
xeth
,
eth
:
xeth
,
db
:
db
,
db
:
db
,
...
@@ -361,7 +364,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
...
@@ -361,7 +364,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
return
err
return
err
}
}
api
.
db
.
Put
([]
byte
(
args
.
Database
+
args
.
Key
),
[]
byte
(
args
.
Value
)
)
api
.
db
.
Put
([]
byte
(
args
.
Database
+
args
.
Key
),
args
.
Value
)
*
reply
=
true
*
reply
=
true
case
"db_getString"
:
case
"db_getString"
:
args
:=
new
(
DbArgs
)
args
:=
new
(
DbArgs
)
...
@@ -375,8 +378,30 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
...
@@ -375,8 +378,30 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
res
,
_
:=
api
.
db
.
Get
([]
byte
(
args
.
Database
+
args
.
Key
))
res
,
_
:=
api
.
db
.
Get
([]
byte
(
args
.
Database
+
args
.
Key
))
*
reply
=
string
(
res
)
*
reply
=
string
(
res
)
case
"db_putHex"
,
"db_getHex"
:
case
"db_putHex"
:
return
NewNotImplementedError
(
req
.
Method
)
args
:=
new
(
DbHexArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
if
err
:=
args
.
requirements
();
err
!=
nil
{
return
err
}
api
.
db
.
Put
([]
byte
(
args
.
Database
+
args
.
Key
),
args
.
Value
)
*
reply
=
true
case
"db_getHex"
:
args
:=
new
(
DbHexArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
if
err
:=
args
.
requirements
();
err
!=
nil
{
return
err
}
res
,
_
:=
api
.
db
.
Get
([]
byte
(
args
.
Database
+
args
.
Key
))
*
reply
=
common
.
ToHex
(
res
)
case
"shh_post"
:
case
"shh_post"
:
args
:=
new
(
WhisperMessageArgs
)
args
:=
new
(
WhisperMessageArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
...
...
rpc/api_test.go
View file @
253ecdc8
...
@@ -5,6 +5,8 @@ import (
...
@@ -5,6 +5,8 @@ import (
// "sync"
// "sync"
"testing"
"testing"
// "time"
// "time"
"github.com/ethereum/go-ethereum/xeth"
)
)
func
TestWeb3Sha3
(
t
*
testing
.
T
)
{
func
TestWeb3Sha3
(
t
*
testing
.
T
)
{
...
@@ -24,6 +26,50 @@ func TestWeb3Sha3(t *testing.T) {
...
@@ -24,6 +26,50 @@ func TestWeb3Sha3(t *testing.T) {
}
}
}
}
func
TestDbStr
(
t
*
testing
.
T
)
{
jsonput
:=
`{"jsonrpc":"2.0","method":"db_putString","params":["testDB","myKey","myString"],"id":64}`
jsonget
:=
`{"jsonrpc":"2.0","method":"db_getString","params":["testDB","myKey"],"id":64}`
expected
:=
"myString"
xeth
:=
&
xeth
.
XEth
{}
api
:=
NewEthereumApi
(
xeth
,
""
)
defer
api
.
db
.
Close
()
var
response
interface
{}
var
req
RpcRequest
json
.
Unmarshal
([]
byte
(
jsonput
),
&
req
)
_
=
api
.
GetRequestReply
(
&
req
,
&
response
)
json
.
Unmarshal
([]
byte
(
jsonget
),
&
req
)
_
=
api
.
GetRequestReply
(
&
req
,
&
response
)
if
response
.
(
string
)
!=
expected
{
t
.
Errorf
(
"Expected %s got %s"
,
expected
,
response
)
}
}
func
TestDbHexStr
(
t
*
testing
.
T
)
{
jsonput
:=
`{"jsonrpc":"2.0","method":"db_putHex","params":["testDB","beefKey","0xbeef"],"id":64}`
jsonget
:=
`{"jsonrpc":"2.0","method":"db_getHex","params":["testDB","beefKey"],"id":64}`
expected
:=
"0xbeef"
xeth
:=
&
xeth
.
XEth
{}
api
:=
NewEthereumApi
(
xeth
,
""
)
defer
api
.
db
.
Close
()
var
response
interface
{}
var
req
RpcRequest
json
.
Unmarshal
([]
byte
(
jsonput
),
&
req
)
_
=
api
.
GetRequestReply
(
&
req
,
&
response
)
json
.
Unmarshal
([]
byte
(
jsonget
),
&
req
)
_
=
api
.
GetRequestReply
(
&
req
,
&
response
)
if
response
.
(
string
)
!=
expected
{
t
.
Errorf
(
"Expected %s got %s"
,
expected
,
response
)
}
}
// func TestFilterClose(t *testing.T) {
// func TestFilterClose(t *testing.T) {
// t.Skip()
// t.Skip()
// api := &EthereumApi{
// api := &EthereumApi{
...
...
rpc/args.go
View file @
253ecdc8
...
@@ -497,24 +497,39 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) {
...
@@ -497,24 +497,39 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) {
type
DbArgs
struct
{
type
DbArgs
struct
{
Database
string
Database
string
Key
string
Key
string
Value
string
Value
[]
byte
}
}
func
(
args
*
DbArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
func
(
args
*
DbArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
interface
{}
var
obj
[]
interface
{}
r
:=
bytes
.
NewReader
(
b
)
if
err
:=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
return
NewDecodeParamError
(
err
.
Error
())
return
NewDecodeParamError
(
err
.
Error
())
}
}
if
len
(
obj
)
<
2
{
if
len
(
obj
)
<
2
{
return
NewInsufficientParamsError
(
len
(
obj
),
2
)
return
NewInsufficientParamsError
(
len
(
obj
),
2
)
}
}
args
.
Database
=
obj
[
0
]
.
(
string
)
args
.
Key
=
obj
[
1
]
.
(
string
)
var
objstr
string
var
ok
bool
if
objstr
,
ok
=
obj
[
0
]
.
(
string
);
!
ok
{
return
NewDecodeParamError
(
"Database is not a string"
)
}
args
.
Database
=
objstr
if
objstr
,
ok
=
obj
[
1
]
.
(
string
);
!
ok
{
return
NewDecodeParamError
(
"Key is not a string"
)
}
args
.
Key
=
objstr
if
len
(
obj
)
>
2
{
if
len
(
obj
)
>
2
{
args
.
Value
=
obj
[
2
]
.
(
string
)
objstr
,
ok
=
obj
[
2
]
.
(
string
)
if
!
ok
{
return
NewDecodeParamError
(
"Value is not a string"
)
}
args
.
Value
=
[]
byte
(
objstr
)
}
}
return
nil
return
nil
...
@@ -530,6 +545,57 @@ func (a *DbArgs) requirements() error {
...
@@ -530,6 +545,57 @@ func (a *DbArgs) requirements() error {
return
nil
return
nil
}
}
type
DbHexArgs
struct
{
Database
string
Key
string
Value
[]
byte
}
func
(
args
*
DbHexArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
interface
{}
if
err
:=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
return
NewDecodeParamError
(
err
.
Error
())
}
if
len
(
obj
)
<
2
{
return
NewInsufficientParamsError
(
len
(
obj
),
2
)
}
var
objstr
string
var
ok
bool
if
objstr
,
ok
=
obj
[
0
]
.
(
string
);
!
ok
{
return
NewDecodeParamError
(
"Database is not a string"
)
}
args
.
Database
=
objstr
if
objstr
,
ok
=
obj
[
1
]
.
(
string
);
!
ok
{
return
NewDecodeParamError
(
"Key is not a string"
)
}
args
.
Key
=
objstr
if
len
(
obj
)
>
2
{
objstr
,
ok
=
obj
[
2
]
.
(
string
)
if
!
ok
{
return
NewDecodeParamError
(
"Value is not a string"
)
}
args
.
Value
=
common
.
FromHex
(
objstr
)
}
return
nil
}
func
(
a
*
DbHexArgs
)
requirements
()
error
{
if
len
(
a
.
Database
)
==
0
{
return
NewValidationError
(
"Database"
,
"cannot be blank"
)
}
if
len
(
a
.
Key
)
==
0
{
return
NewValidationError
(
"Key"
,
"cannot be blank"
)
}
return
nil
}
type
WhisperMessageArgs
struct
{
type
WhisperMessageArgs
struct
{
Payload
string
Payload
string
To
string
To
string
...
...
rpc/args_test.go
View file @
253ecdc8
...
@@ -485,11 +485,11 @@ func TestBlockFilterArgsEmptyArgs(t *testing.T) {
...
@@ -485,11 +485,11 @@ func TestBlockFilterArgsEmptyArgs(t *testing.T) {
}
}
func
TestDbArgs
(
t
*
testing
.
T
)
{
func
TestDbArgs
(
t
*
testing
.
T
)
{
input
:=
`["
0x74657374","0x6b6579","0x6d79537472696e67
"]`
input
:=
`["
testDB","myKey","0xbeef
"]`
expected
:=
new
(
DbArgs
)
expected
:=
new
(
DbArgs
)
expected
.
Database
=
"
0x74657374
"
expected
.
Database
=
"
testDB
"
expected
.
Key
=
"
0x6b6579
"
expected
.
Key
=
"
myKey
"
expected
.
Value
=
"0x6d79537472696e67"
expected
.
Value
=
[]
byte
(
"0xbeef"
)
args
:=
new
(
DbArgs
)
args
:=
new
(
DbArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
...
@@ -508,7 +508,36 @@ func TestDbArgs(t *testing.T) {
...
@@ -508,7 +508,36 @@ func TestDbArgs(t *testing.T) {
t
.
Errorf
(
"Key shoud be %#v but is %#v"
,
expected
.
Key
,
args
.
Key
)
t
.
Errorf
(
"Key shoud be %#v but is %#v"
,
expected
.
Key
,
args
.
Key
)
}
}
if
expected
.
Value
!=
args
.
Value
{
if
bytes
.
Compare
(
expected
.
Value
,
args
.
Value
)
!=
0
{
t
.
Errorf
(
"Value shoud be %#v but is %#v"
,
expected
.
Value
,
args
.
Value
)
}
}
func
TestDbHexArgs
(
t
*
testing
.
T
)
{
input
:=
`["testDB","myKey","0xbeef"]`
expected
:=
new
(
DbHexArgs
)
expected
.
Database
=
"testDB"
expected
.
Key
=
"myKey"
expected
.
Value
=
[]
byte
{
0xbe
,
0xef
}
args
:=
new
(
DbHexArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
err
:=
args
.
requirements
();
err
!=
nil
{
t
.
Error
(
err
)
}
if
expected
.
Database
!=
args
.
Database
{
t
.
Errorf
(
"Database shoud be %#v but is %#v"
,
expected
.
Database
,
args
.
Database
)
}
if
expected
.
Key
!=
args
.
Key
{
t
.
Errorf
(
"Key shoud be %#v but is %#v"
,
expected
.
Key
,
args
.
Key
)
}
if
bytes
.
Compare
(
expected
.
Value
,
args
.
Value
)
!=
0
{
t
.
Errorf
(
"Value shoud be %#v but is %#v"
,
expected
.
Value
,
args
.
Value
)
t
.
Errorf
(
"Value shoud be %#v but is %#v"
,
expected
.
Value
,
args
.
Value
)
}
}
}
}
...
...
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