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
67c9d9c2
Commit
67c9d9c2
authored
Mar 18, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove JsonWrapper
parent
c6f84325
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
22 deletions
+19
-22
http.go
rpc/http.go
+19
-6
util.go
rpc/util.go
+0
-16
No files found.
rpc/http.go
View file @
67c9d9c2
...
@@ -2,6 +2,7 @@ package rpc
...
@@ -2,6 +2,7 @@ package rpc
import
(
import
(
"encoding/json"
"encoding/json"
"io"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
...
@@ -18,7 +19,6 @@ const (
...
@@ -18,7 +19,6 @@ const (
// JSONRPC returns a handler that implements the Ethereum JSON-RPC API.
// JSONRPC returns a handler that implements the Ethereum JSON-RPC API.
func
JSONRPC
(
pipe
*
xeth
.
XEth
,
dataDir
string
)
http
.
Handler
{
func
JSONRPC
(
pipe
*
xeth
.
XEth
,
dataDir
string
)
http
.
Handler
{
var
jsw
JsonWrapper
api
:=
NewEthereumApi
(
pipe
,
dataDir
)
api
:=
NewEthereumApi
(
pipe
,
dataDir
)
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
...
@@ -28,22 +28,23 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
...
@@ -28,22 +28,23 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
// Limit request size to resist DoS
// Limit request size to resist DoS
if
req
.
ContentLength
>
maxSizeReqLength
{
if
req
.
ContentLength
>
maxSizeReqLength
{
jsonerr
:=
&
RpcErrorObject
{
-
32700
,
"Request too large"
}
jsonerr
:=
&
RpcErrorObject
{
-
32700
,
"Request too large"
}
jsw
.
Send
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
Send
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
return
return
}
}
// Read request body
defer
req
.
Body
.
Close
()
defer
req
.
Body
.
Close
()
body
,
err
:=
ioutil
.
ReadAll
(
req
.
Body
)
body
,
err
:=
ioutil
.
ReadAll
(
req
.
Body
)
if
err
!=
nil
{
if
err
!=
nil
{
jsonerr
:=
&
RpcErrorObject
{
-
32700
,
"Could not read request body"
}
jsonerr
:=
&
RpcErrorObject
{
-
32700
,
"Could not read request body"
}
jsw
.
Send
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
Send
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
}
}
// Try to parse the request as a single
// Try to parse the request as a single
var
reqSingle
RpcRequest
var
reqSingle
RpcRequest
if
err
:=
json
.
Unmarshal
(
body
,
&
reqSingle
);
err
==
nil
{
if
err
:=
json
.
Unmarshal
(
body
,
&
reqSingle
);
err
==
nil
{
response
:=
RpcResponse
(
api
,
&
reqSingle
)
response
:=
RpcResponse
(
api
,
&
reqSingle
)
jsw
.
Send
(
w
,
&
response
)
Send
(
w
,
&
response
)
return
return
}
}
...
@@ -56,13 +57,13 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
...
@@ -56,13 +57,13 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
response
:=
RpcResponse
(
api
,
&
request
)
response
:=
RpcResponse
(
api
,
&
request
)
resBatch
[
i
]
=
response
resBatch
[
i
]
=
response
}
}
jsw
.
Send
(
w
,
resBatch
)
Send
(
w
,
resBatch
)
return
return
}
}
// Not a batch or single request, error
// Not a batch or single request, error
jsonerr
:=
&
RpcErrorObject
{
-
32600
,
"Could not decode request"
}
jsonerr
:=
&
RpcErrorObject
{
-
32600
,
"Could not decode request"
}
jsw
.
Send
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
Send
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
})
})
}
}
...
@@ -86,3 +87,15 @@ func RpcResponse(api *EthereumApi, request *RpcRequest) *interface{} {
...
@@ -86,3 +87,15 @@ func RpcResponse(api *EthereumApi, request *RpcRequest) *interface{} {
rpchttplogger
.
DebugDetailf
(
"Generated response: %T %s"
,
response
,
response
)
rpchttplogger
.
DebugDetailf
(
"Generated response: %T %s"
,
response
,
response
)
return
&
response
return
&
response
}
}
func
Send
(
writer
io
.
Writer
,
v
interface
{})
(
n
int
,
err
error
)
{
var
payload
[]
byte
payload
,
err
=
json
.
MarshalIndent
(
v
,
""
,
"
\t
"
)
if
err
!=
nil
{
rpclogger
.
Fatalln
(
"Error marshalling JSON"
,
err
)
return
0
,
err
}
rpclogger
.
DebugDetailf
(
"Sending payload: %s"
,
payload
)
return
writer
.
Write
(
payload
)
}
rpc/util.go
View file @
67c9d9c2
...
@@ -19,9 +19,7 @@ package rpc
...
@@ -19,9 +19,7 @@ package rpc
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"io"
"math/big"
"math/big"
// "net/http"
"reflect"
"reflect"
"time"
"time"
...
@@ -33,8 +31,6 @@ import (
...
@@ -33,8 +31,6 @@ import (
var
rpclogger
=
logger
.
NewLogger
(
"RPC"
)
var
rpclogger
=
logger
.
NewLogger
(
"RPC"
)
type
JsonWrapper
struct
{}
// Unmarshal state is a helper method which has the ability to decode messsages
// Unmarshal state is a helper method which has the ability to decode messsages
// that use the `defaultBlock` (https://github.com/ethereum/wiki/wiki/JSON-RPC#the-default-block-parameter)
// that use the `defaultBlock` (https://github.com/ethereum/wiki/wiki/JSON-RPC#the-default-block-parameter)
// For example a `call`: [{to: "0x....", data:"0x..."}, "latest"]. The first argument is the transaction
// For example a `call`: [{to: "0x....", data:"0x..."}, "latest"]. The first argument is the transaction
...
@@ -94,18 +90,6 @@ func UnmarshalRawMessages(b []byte, iface interface{}, number *int64) (err error
...
@@ -94,18 +90,6 @@ func UnmarshalRawMessages(b []byte, iface interface{}, number *int64) (err error
return
nil
return
nil
}
}
func
(
self
JsonWrapper
)
Send
(
writer
io
.
Writer
,
v
interface
{})
(
n
int
,
err
error
)
{
var
payload
[]
byte
payload
,
err
=
json
.
MarshalIndent
(
v
,
""
,
"
\t
"
)
if
err
!=
nil
{
rpclogger
.
Fatalln
(
"Error marshalling JSON"
,
err
)
return
0
,
err
}
rpclogger
.
DebugDetailf
(
"Sending payload: %s"
,
payload
)
return
writer
.
Write
(
payload
)
}
func
toHex
(
b
[]
byte
)
string
{
func
toHex
(
b
[]
byte
)
string
{
hex
:=
common
.
Bytes2Hex
(
b
)
hex
:=
common
.
Bytes2Hex
(
b
)
// Prefer output of "0x0" instead of "0x"
// Prefer output of "0x0" instead of "0x"
...
...
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