aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/types.go
diff options
context:
space:
mode:
authorBas van Kervel <bas@ethdev.com>2016-03-14 16:38:54 +0800
committerBas van Kervel <bas@ethdev.com>2016-04-12 17:02:39 +0800
commitaa9fff3e68b1def0a9a22009c233150bf9ba481f (patch)
tree926c241574d6d80dfe4ffd6d2e447a9f7f84dc8b /rpc/types.go
parent7e02105672cda92889a78db864a5701d78f45eb2 (diff)
downloaddexon-aa9fff3e68b1def0a9a22009c233150bf9ba481f.tar.gz
dexon-aa9fff3e68b1def0a9a22009c233150bf9ba481f.tar.zst
dexon-aa9fff3e68b1def0a9a22009c233150bf9ba481f.zip
rpc: various fixes/enhancements
rpc: be less restrictive on the request id rpc: improved documentation console: upgrade web3.js to version 0.16.0 rpc: cache http connections rpc: rename wsDomains parameter to wsOrigins
Diffstat (limited to 'rpc/types.go')
-rw-r--r--rpc/types.go51
1 files changed, 7 insertions, 44 deletions
diff --git a/rpc/types.go b/rpc/types.go
index 596fdf264..a1f36fbd2 100644
--- a/rpc/types.go
+++ b/rpc/types.go
@@ -56,7 +56,7 @@ type service struct {
// serverRequest is an incoming request
type serverRequest struct {
- id int64
+ id interface{}
svcname string
rcvr reflect.Value
callb *callback
@@ -85,7 +85,7 @@ type Server struct {
type rpcRequest struct {
service string
method string
- id int64
+ id interface{}
isPubSub bool
params interface{}
}
@@ -106,12 +106,12 @@ type ServerCodec interface {
ReadRequestHeaders() ([]rpcRequest, bool, RPCError)
// Parse request argument to the given types
ParseRequestArguments([]reflect.Type, interface{}) ([]reflect.Value, RPCError)
- // Assemble success response
- CreateResponse(int64, interface{}) interface{}
- // Assemble error response
- CreateErrorResponse(*int64, RPCError) interface{}
+ // Assemble success response, expects response id and payload
+ CreateResponse(interface{}, interface{}) interface{}
+ // Assemble error response, expects response id and error
+ CreateErrorResponse(interface{}, RPCError) interface{}
// Assemble error response with extra information about the error through info
- CreateErrorResponseWithInfo(id *int64, err RPCError, info interface{}) interface{}
+ CreateErrorResponseWithInfo(id interface{}, err RPCError, info interface{}) interface{}
// Create notification response
CreateNotification(string, interface{}) interface{}
// Write msg to client.
@@ -207,43 +207,6 @@ func (h *HexNumber) BigInt() *big.Int {
return (*big.Int)(h)
}
-type Number int64
-
-func (n *Number) UnmarshalJSON(data []byte) error {
- input := strings.TrimSpace(string(data))
-
- if len(input) >= 2 && input[0] == '"' && input[len(input)-1] == '"' {
- input = input[1 : len(input)-1]
- }
-
- if len(input) == 0 {
- *n = Number(latestBlockNumber.Int64())
- return nil
- }
-
- in := new(big.Int)
- _, ok := in.SetString(input, 0)
-
- if !ok { // test if user supplied string tag
- return fmt.Errorf(`invalid number %s`, data)
- }
-
- if in.Cmp(earliestBlockNumber) >= 0 && in.Cmp(maxBlockNumber) <= 0 {
- *n = Number(in.Int64())
- return nil
- }
-
- return fmt.Errorf("blocknumber not in range [%d, %d]", earliestBlockNumber, maxBlockNumber)
-}
-
-func (n *Number) Int64() int64 {
- return *(*int64)(n)
-}
-
-func (n *Number) BigInt() *big.Int {
- return big.NewInt(n.Int64())
-}
-
var (
pendingBlockNumber = big.NewInt(-2)
latestBlockNumber = big.NewInt(-1)