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
ef6c7bd7
Commit
ef6c7bd7
authored
Feb 11, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #300 from tgerring/jsonrpc
Allow RPC ID to be string or null
parents
c6af5f0a
d613bf69
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
7 deletions
+8
-7
server.go
rpc/http/server.go
+1
-1
message.go
rpc/message.go
+3
-3
util.go
rpc/util.go
+1
-1
server.go
rpc/ws/server.go
+3
-2
No files found.
rpc/http/server.go
View file @
ef6c7bd7
...
@@ -102,7 +102,7 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
...
@@ -102,7 +102,7 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
if
reserr
!=
nil
{
if
reserr
!=
nil
{
rpchttplogger
.
Warnln
(
reserr
)
rpchttplogger
.
Warnln
(
reserr
)
jsonerr
:=
&
rpc
.
RpcErrorObject
{
-
32603
,
reserr
.
Error
()}
jsonerr
:=
&
rpc
.
RpcErrorObject
{
-
32603
,
reserr
.
Error
()}
JSON
.
Send
(
w
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
&
reqParsed
.
ID
,
Error
:
jsonerr
})
JSON
.
Send
(
w
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
reqParsed
.
ID
,
Error
:
jsonerr
})
return
return
}
}
...
...
rpc/message.go
View file @
ef6c7bd7
...
@@ -34,20 +34,20 @@ const (
...
@@ -34,20 +34,20 @@ const (
)
)
type
RpcRequest
struct
{
type
RpcRequest
struct
{
ID
interface
{}
`json:"id"`
JsonRpc
string
`json:"jsonrpc"`
JsonRpc
string
`json:"jsonrpc"`
ID
int
`json:"id"`
Method
string
`json:"method"`
Method
string
`json:"method"`
Params
[]
json
.
RawMessage
`json:"params"`
Params
[]
json
.
RawMessage
`json:"params"`
}
}
type
RpcSuccessResponse
struct
{
type
RpcSuccessResponse
struct
{
ID
int
`json:"id"`
ID
int
erface
{}
`json:"id"`
JsonRpc
string
`json:"jsonrpc"`
JsonRpc
string
`json:"jsonrpc"`
Result
interface
{}
`json:"result"`
Result
interface
{}
`json:"result"`
}
}
type
RpcErrorResponse
struct
{
type
RpcErrorResponse
struct
{
ID
*
int
`json:"id"`
ID
interface
{}
`json:"id"`
JsonRpc
string
`json:"jsonrpc"`
JsonRpc
string
`json:"jsonrpc"`
Error
*
RpcErrorObject
`json:"error"`
Error
*
RpcErrorObject
`json:"error"`
}
}
...
...
rpc/util.go
View file @
ef6c7bd7
...
@@ -47,7 +47,6 @@ func (self JsonWrapper) ParseRequestBody(req *http.Request) (RpcRequest, error)
...
@@ -47,7 +47,6 @@ func (self JsonWrapper) ParseRequestBody(req *http.Request) (RpcRequest, error)
// Convert JSON to native types
// Convert JSON to native types
d
:=
json
.
NewDecoder
(
req
.
Body
)
d
:=
json
.
NewDecoder
(
req
.
Body
)
// d.UseNumber()
defer
req
.
Body
.
Close
()
defer
req
.
Body
.
Close
()
err
:=
d
.
Decode
(
&
reqParsed
)
err
:=
d
.
Decode
(
&
reqParsed
)
...
@@ -55,6 +54,7 @@ func (self JsonWrapper) ParseRequestBody(req *http.Request) (RpcRequest, error)
...
@@ -55,6 +54,7 @@ func (self JsonWrapper) ParseRequestBody(req *http.Request) (RpcRequest, error)
rpclogger
.
Errorln
(
"Error decoding JSON: "
,
err
)
rpclogger
.
Errorln
(
"Error decoding JSON: "
,
err
)
return
reqParsed
,
err
return
reqParsed
,
err
}
}
rpclogger
.
DebugDetailf
(
"Parsed request: %s"
,
reqParsed
)
rpclogger
.
DebugDetailf
(
"Parsed request: %s"
,
reqParsed
)
return
reqParsed
,
nil
return
reqParsed
,
nil
...
...
rpc/ws/server.go
View file @
ef6c7bd7
...
@@ -94,9 +94,10 @@ func sockHandler(api *rpc.EthereumApi) websocket.Handler {
...
@@ -94,9 +94,10 @@ func sockHandler(api *rpc.EthereumApi) websocket.Handler {
var
jsonrpcver
string
=
"2.0"
var
jsonrpcver
string
=
"2.0"
fn
:=
func
(
conn
*
websocket
.
Conn
)
{
fn
:=
func
(
conn
*
websocket
.
Conn
)
{
for
{
for
{
wslogger
.
Debugln
(
"Handling
request
"
)
wslogger
.
Debugln
(
"Handling
connection
"
)
var
reqParsed
rpc
.
RpcRequest
var
reqParsed
rpc
.
RpcRequest
// reqParsed, reqerr := JSON.ParseRequestBody(conn.Request())
if
err
:=
websocket
.
JSON
.
Receive
(
conn
,
&
reqParsed
);
err
!=
nil
{
if
err
:=
websocket
.
JSON
.
Receive
(
conn
,
&
reqParsed
);
err
!=
nil
{
jsonerr
:=
&
rpc
.
RpcErrorObject
{
-
32700
,
rpc
.
ErrorParseRequest
}
jsonerr
:=
&
rpc
.
RpcErrorObject
{
-
32700
,
rpc
.
ErrorParseRequest
}
JSON
.
Send
(
conn
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
nil
,
Error
:
jsonerr
})
JSON
.
Send
(
conn
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
nil
,
Error
:
jsonerr
})
...
@@ -108,7 +109,7 @@ func sockHandler(api *rpc.EthereumApi) websocket.Handler {
...
@@ -108,7 +109,7 @@ func sockHandler(api *rpc.EthereumApi) websocket.Handler {
if
reserr
!=
nil
{
if
reserr
!=
nil
{
wslogger
.
Warnln
(
reserr
)
wslogger
.
Warnln
(
reserr
)
jsonerr
:=
&
rpc
.
RpcErrorObject
{
-
32603
,
reserr
.
Error
()}
jsonerr
:=
&
rpc
.
RpcErrorObject
{
-
32603
,
reserr
.
Error
()}
JSON
.
Send
(
conn
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
&
reqParsed
.
ID
,
Error
:
jsonerr
})
JSON
.
Send
(
conn
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
reqParsed
.
ID
,
Error
:
jsonerr
})
continue
continue
}
}
...
...
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