Merge pull request #379 from tgerring/rpcupdates

RPC cleanup
This commit is contained in:
Jeffrey Wilcke 2015-02-24 22:00:39 +01:00
commit 52ccaa605e
6 changed files with 127 additions and 170 deletions

View File

@ -9,7 +9,6 @@ For each request type, define the following:
package rpc package rpc
import ( import (
"fmt"
"math/big" "math/big"
"strings" "strings"
"sync" "sync"
@ -28,6 +27,7 @@ import (
var ( var (
defaultGasPrice = big.NewInt(10000000000000) defaultGasPrice = big.NewInt(10000000000000)
defaultGas = big.NewInt(10000) defaultGas = big.NewInt(10000)
filterTickerTime = 15 * time.Second
) )
type EthereumApi struct { type EthereumApi struct {
@ -63,6 +63,39 @@ func NewEthereumApi(eth *xeth.XEth) *EthereumApi {
return api return api
} }
func (self *EthereumApi) start() {
timer := time.NewTicker(filterTickerTime)
done:
for {
select {
case <-timer.C:
self.logMut.Lock()
self.messagesMut.Lock()
for id, filter := range self.logs {
if time.Since(filter.timeout) > 20*time.Second {
self.filterManager.UninstallFilter(id)
delete(self.logs, id)
}
}
for id, filter := range self.messages {
if time.Since(filter.timeout) > 20*time.Second {
self.xeth.Whisper().Unwatch(id)
delete(self.messages, id)
}
}
self.logMut.Unlock()
self.messagesMut.Unlock()
case <-self.quit:
break done
}
}
}
func (self *EthereumApi) stop() {
close(self.quit)
}
func (self *EthereumApi) Register(args string, reply *interface{}) error { func (self *EthereumApi) Register(args string, reply *interface{}) error {
self.regmut.Lock() self.regmut.Lock()
defer self.regmut.Unlock() defer self.regmut.Unlock()
@ -410,7 +443,7 @@ func (p *EthereumApi) WhisperMessages(id int, reply *interface{}) error {
} }
func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error { func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error {
// Spec at https://github.com/ethereum/wiki/wiki/Generic-ON-RPC // Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC
rpclogger.DebugDetailf("%T %s", req.Params, req.Params) rpclogger.DebugDetailf("%T %s", req.Params, req.Params)
switch req.Method { switch req.Method {
case "eth_coinbase": case "eth_coinbase":
@ -595,44 +628,9 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
} }
return p.WhisperMessages(args, reply) return p.WhisperMessages(args, reply)
default: default:
return NewErrorResponse(fmt.Sprintf("%v %s", ErrorNotImplemented, req.Method)) return NewErrorWithMessage(errNotImplemented, req.Method)
} }
rpclogger.DebugDetailf("Reply: %T %s", reply, reply) rpclogger.DebugDetailf("Reply: %T %s", reply, reply)
return nil return nil
} }
var filterTickerTime = 15 * time.Second
func (self *EthereumApi) start() {
timer := time.NewTicker(filterTickerTime)
done:
for {
select {
case <-timer.C:
self.logMut.Lock()
self.messagesMut.Lock()
for id, filter := range self.logs {
if time.Since(filter.timeout) > 20*time.Second {
self.filterManager.UninstallFilter(id)
delete(self.logs, id)
}
}
for id, filter := range self.messages {
if time.Since(filter.timeout) > 20*time.Second {
self.xeth.Whisper().Unwatch(id)
delete(self.messages, id)
}
}
self.logMut.Unlock()
self.messagesMut.Unlock()
case <-self.quit:
break done
}
}
}
func (self *EthereumApi) stop() {
close(self.quit)
}

View File

@ -19,7 +19,7 @@ func (obj *GetBlockArgs) UnmarshalJSON(b []byte) (err error) {
obj.Hash = argstr obj.Hash = argstr
return return
} }
return NewErrorResponse(ErrorDecodeArgs) return errDecodeArgs
} }
type NewTxArgs struct { type NewTxArgs struct {
@ -57,7 +57,7 @@ func (obj *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
return return
} }
return NewErrorResponse(ErrorDecodeArgs) return errDecodeArgs
} }
type PushTxArgs struct { type PushTxArgs struct {
@ -70,12 +70,12 @@ func (obj *PushTxArgs) UnmarshalJSON(b []byte) (err error) {
obj.Tx = arg0 obj.Tx = arg0
return return
} }
return NewErrorResponse(ErrorDecodeArgs) return errDecodeArgs
} }
func (a *PushTxArgs) requirementsPushTx() error { func (a *PushTxArgs) requirementsPushTx() error {
if a.Tx == "" { if a.Tx == "" {
return NewErrorResponse("PushTx requires a 'tx' as argument") return NewErrorWithMessage(errArguments, "PushTx requires a 'tx' as argument")
} }
return nil return nil
} }
@ -86,14 +86,14 @@ type GetStorageArgs struct {
func (obj *GetStorageArgs) UnmarshalJSON(b []byte) (err error) { func (obj *GetStorageArgs) UnmarshalJSON(b []byte) (err error) {
if err = json.Unmarshal(b, &obj.Address); err != nil { if err = json.Unmarshal(b, &obj.Address); err != nil {
return NewErrorResponse(ErrorDecodeArgs) return errDecodeArgs
} }
return return
} }
func (a *GetStorageArgs) requirements() error { func (a *GetStorageArgs) requirements() error {
if len(a.Address) == 0 { if len(a.Address) == 0 {
return NewErrorResponse("GetStorageAt requires an 'address' value as argument") return NewErrorWithMessage(errArguments, "GetStorageAt requires an 'address' value as argument")
} }
return nil return nil
} }
@ -109,64 +109,39 @@ func (obj *GetStateArgs) UnmarshalJSON(b []byte) (err error) {
obj.Address = arg0 obj.Address = arg0
return return
} }
return NewErrorResponse(ErrorDecodeArgs) return errDecodeArgs
} }
func (a *GetStateArgs) requirements() error { func (a *GetStateArgs) requirements() error {
if a.Address == "" { if a.Address == "" {
return NewErrorResponse("GetStorageAt requires an 'address' value as argument") return NewErrorWithMessage(errArguments, "GetStorageAt requires an 'address' value as argument")
} }
if a.Key == "" { if a.Key == "" {
return NewErrorResponse("GetStorageAt requires an 'key' value as argument") return NewErrorWithMessage(errArguments, "GetStorageAt requires an 'key' value as argument")
} }
return nil return nil
} }
type GetStorageAtRes struct {
Key string `json:"key"`
Value string `json:"value"`
}
type GetTxCountArgs struct { type GetTxCountArgs struct {
Address string `json:"address"` Address string `json:"address"`
} }
// type GetTxCountRes struct {
// Nonce int `json:"nonce"`
// }
func (obj *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) { func (obj *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) {
arg0 := "" arg0 := ""
if err = json.Unmarshal(b, &arg0); err == nil { if err = json.Unmarshal(b, &arg0); err == nil {
obj.Address = arg0 obj.Address = arg0
return return
} }
return NewErrorResponse("Could not determine JSON parameters") return errDecodeArgs
} }
func (a *GetTxCountArgs) requirements() error { func (a *GetTxCountArgs) requirements() error {
if a.Address == "" { if a.Address == "" {
return NewErrorResponse("GetTxCountAt requires an 'address' value as argument") return NewErrorWithMessage(errArguments, "GetTxCountAt requires an 'address' value as argument")
} }
return nil return nil
} }
// type GetPeerCountRes struct {
// PeerCount int `json:"peerCount"`
// }
// type GetListeningRes struct {
// IsListening bool `json:"isListening"`
// }
// type GetCoinbaseRes struct {
// Coinbase string `json:"coinbase"`
// }
// type GetMiningRes struct {
// IsMining bool `json:"isMining"`
// }
type GetBalanceArgs struct { type GetBalanceArgs struct {
Address string Address string
} }
@ -177,21 +152,16 @@ func (obj *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) {
obj.Address = arg0 obj.Address = arg0
return return
} }
return NewErrorResponse("Could not determine JSON parameters") return errDecodeArgs
} }
func (a *GetBalanceArgs) requirements() error { func (a *GetBalanceArgs) requirements() error {
if a.Address == "" { if a.Address == "" {
return NewErrorResponse("GetBalanceAt requires an 'address' value as argument") return NewErrorWithMessage(errArguments, "GetBalanceAt requires an 'address' value as argument")
} }
return nil return nil
} }
type BalanceRes struct {
Balance string `json:"balance"`
Address string `json:"address"`
}
type GetCodeAtArgs struct { type GetCodeAtArgs struct {
Address string Address string
} }
@ -202,12 +172,12 @@ func (obj *GetCodeAtArgs) UnmarshalJSON(b []byte) (err error) {
obj.Address = arg0 obj.Address = arg0
return return
} }
return NewErrorResponse(ErrorDecodeArgs) return errDecodeArgs
} }
func (a *GetCodeAtArgs) requirements() error { func (a *GetCodeAtArgs) requirements() error {
if a.Address == "" { if a.Address == "" {
return NewErrorResponse("GetCodeAt requires an 'address' value as argument") return NewErrorWithMessage(errArguments, "GetCodeAt requires an 'address' value as argument")
} }
return nil return nil
} }
@ -218,7 +188,7 @@ type Sha3Args struct {
func (obj *Sha3Args) UnmarshalJSON(b []byte) (err error) { func (obj *Sha3Args) UnmarshalJSON(b []byte) (err error) {
if err = json.Unmarshal(b, &obj.Data); err != nil { if err = json.Unmarshal(b, &obj.Data); err != nil {
return NewErrorResponse(ErrorDecodeArgs) return errDecodeArgs
} }
return return
} }
@ -270,10 +240,10 @@ type DbArgs struct {
func (a *DbArgs) requirements() error { func (a *DbArgs) requirements() error {
if len(a.Database) == 0 { if len(a.Database) == 0 {
return NewErrorResponse("DbPutArgs requires an 'Database' value as argument") return NewErrorWithMessage(errArguments, "DbPutArgs requires an 'Database' value as argument")
} }
if len(a.Key) == 0 { if len(a.Key) == 0 {
return NewErrorResponse("DbPutArgs requires an 'Key' value as argument") return NewErrorWithMessage(errArguments, "DbPutArgs requires an 'Key' value as argument")
} }
return nil return nil
} }

View File

@ -92,7 +92,7 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
reqParsed, reqerr := JSON.ParseRequestBody(req) reqParsed, reqerr := JSON.ParseRequestBody(req)
if reqerr != nil { if reqerr != nil {
jsonerr := &rpc.RpcErrorObject{-32700, rpc.ErrorParseRequest} jsonerr := &rpc.RpcErrorObject{-32700, "Error: Could not parse request"}
JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr}) JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr})
return return
} }

View File

@ -25,12 +25,11 @@ import (
"github.com/ethereum/go-ethereum/xeth" "github.com/ethereum/go-ethereum/xeth"
) )
const ( var (
ErrorArguments = "Error: Insufficient arguments" errArguments = errors.New("Error: Insufficient arguments")
ErrorNotImplemented = "Error: Method not implemented" errNotImplemented = errors.New("Error: Method not implemented")
ErrorUnknown = "Error: Unknown error" errUnknown = errors.New("Error: Unknown error")
ErrorParseRequest = "Error: Could not parse request" errDecodeArgs = errors.New("Error: Could not decode arguments")
ErrorDecodeArgs = "Error: Could not decode arguments"
) )
type RpcRequest struct { type RpcRequest struct {
@ -58,76 +57,72 @@ type RpcErrorObject struct {
// Data interface{} `json:"data"` // Data interface{} `json:"data"`
} }
func NewErrorResponse(msg string) error { func NewErrorWithMessage(err error, msg string) error {
return errors.New(msg) return fmt.Errorf("%s: %s", err.Error(), msg)
}
func NewErrorResponseWithError(msg string, err error) error {
return fmt.Errorf("%s: %v", msg, err)
} }
func (req *RpcRequest) ToSha3Args() (*Sha3Args, error) { func (req *RpcRequest) ToSha3Args() (*Sha3Args, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
args := new(Sha3Args) args := new(Sha3Args)
r := bytes.NewReader(req.Params[0]) r := bytes.NewReader(req.Params[0])
if err := json.NewDecoder(r).Decode(args); err != nil { if err := json.NewDecoder(r).Decode(args); err != nil {
return nil, NewErrorResponse(ErrorDecodeArgs) return nil, errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToGetBlockArgs() (*GetBlockArgs, error) { func (req *RpcRequest) ToGetBlockArgs() (*GetBlockArgs, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
args := new(GetBlockArgs) args := new(GetBlockArgs)
r := bytes.NewReader(req.Params[0]) r := bytes.NewReader(req.Params[0])
err := json.NewDecoder(r).Decode(args) err := json.NewDecoder(r).Decode(args)
if err != nil { if err != nil {
return nil, NewErrorResponse(ErrorDecodeArgs) return nil, errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToNewTxArgs() (*NewTxArgs, error) { func (req *RpcRequest) ToNewTxArgs() (*NewTxArgs, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
args := new(NewTxArgs) args := new(NewTxArgs)
r := bytes.NewReader(req.Params[0]) r := bytes.NewReader(req.Params[0])
err := json.NewDecoder(r).Decode(args) err := json.NewDecoder(r).Decode(args)
if err != nil { if err != nil {
return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToPushTxArgs() (*PushTxArgs, error) { func (req *RpcRequest) ToPushTxArgs() (*PushTxArgs, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
args := new(PushTxArgs) args := new(PushTxArgs)
r := bytes.NewReader(req.Params[0]) r := bytes.NewReader(req.Params[0])
err := json.NewDecoder(r).Decode(args) err := json.NewDecoder(r).Decode(args)
if err != nil { if err != nil {
return nil, NewErrorResponse(ErrorDecodeArgs) return nil, errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToGetStateArgs() (*GetStateArgs, error) { func (req *RpcRequest) ToGetStateArgs() (*GetStateArgs, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
args := new(GetStateArgs) args := new(GetStateArgs)
@ -135,234 +130,228 @@ func (req *RpcRequest) ToGetStateArgs() (*GetStateArgs, error) {
r := bytes.NewReader(req.Params[0]) r := bytes.NewReader(req.Params[0])
err := json.NewDecoder(r).Decode(args) err := json.NewDecoder(r).Decode(args)
if err != nil { if err != nil {
return nil, NewErrorResponse(ErrorDecodeArgs) return nil, errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToStorageAtArgs() (*GetStorageArgs, error) { func (req *RpcRequest) ToStorageAtArgs() (*GetStorageArgs, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
args := new(GetStorageArgs) args := new(GetStorageArgs)
r := bytes.NewReader(req.Params[0]) r := bytes.NewReader(req.Params[0])
err := json.NewDecoder(r).Decode(args) err := json.NewDecoder(r).Decode(args)
if err != nil { if err != nil {
return nil, NewErrorResponse(ErrorDecodeArgs) return nil, errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToGetTxCountArgs() (*GetTxCountArgs, error) { func (req *RpcRequest) ToGetTxCountArgs() (*GetTxCountArgs, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
args := new(GetTxCountArgs) args := new(GetTxCountArgs)
r := bytes.NewReader(req.Params[0]) r := bytes.NewReader(req.Params[0])
err := json.NewDecoder(r).Decode(args) err := json.NewDecoder(r).Decode(args)
if err != nil { if err != nil {
return nil, NewErrorResponse(ErrorDecodeArgs) return nil, errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToGetBalanceArgs() (*GetBalanceArgs, error) { func (req *RpcRequest) ToGetBalanceArgs() (*GetBalanceArgs, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
args := new(GetBalanceArgs) args := new(GetBalanceArgs)
r := bytes.NewReader(req.Params[0]) r := bytes.NewReader(req.Params[0])
err := json.NewDecoder(r).Decode(args) err := json.NewDecoder(r).Decode(args)
if err != nil { if err != nil {
return nil, NewErrorResponse(ErrorDecodeArgs) return nil, errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToGetCodeAtArgs() (*GetCodeAtArgs, error) { func (req *RpcRequest) ToGetCodeAtArgs() (*GetCodeAtArgs, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
args := new(GetCodeAtArgs) args := new(GetCodeAtArgs)
r := bytes.NewReader(req.Params[0]) r := bytes.NewReader(req.Params[0])
err := json.NewDecoder(r).Decode(args) err := json.NewDecoder(r).Decode(args)
if err != nil { if err != nil {
return nil, NewErrorResponse(ErrorDecodeArgs) return nil, errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToBoolArgs() (bool, error) { func (req *RpcRequest) ToBoolArgs() (bool, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return false, NewErrorResponse(ErrorArguments) return false, errArguments
} }
var args bool var args bool
err := json.Unmarshal(req.Params[0], &args) err := json.Unmarshal(req.Params[0], &args)
if err != nil { if err != nil {
return false, NewErrorResponse(ErrorDecodeArgs) return false, errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToCompileArgs() (string, error) { func (req *RpcRequest) ToCompileArgs() (string, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return "", NewErrorResponse(ErrorArguments) return "", errArguments
} }
var args string var args string
err := json.Unmarshal(req.Params[0], &args) err := json.Unmarshal(req.Params[0], &args)
if err != nil { if err != nil {
return "", NewErrorResponse(ErrorDecodeArgs) return "", errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToFilterArgs() (*FilterOptions, error) { func (req *RpcRequest) ToFilterArgs() (*FilterOptions, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
args := new(FilterOptions) args := new(FilterOptions)
r := bytes.NewReader(req.Params[0]) r := bytes.NewReader(req.Params[0])
err := json.NewDecoder(r).Decode(args) err := json.NewDecoder(r).Decode(args)
if err != nil { if err != nil {
return nil, NewErrorResponse(ErrorDecodeArgs) return nil, errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToFilterStringArgs() (string, error) { func (req *RpcRequest) ToFilterStringArgs() (string, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return "", NewErrorResponse(ErrorArguments) return "", errArguments
} }
var args string var args string
err := json.Unmarshal(req.Params[0], &args) err := json.Unmarshal(req.Params[0], &args)
if err != nil { if err != nil {
return "", NewErrorResponse(ErrorDecodeArgs) return "", errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToUninstallFilterArgs() (int, error) { func (req *RpcRequest) ToUninstallFilterArgs() (int, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return 0, NewErrorResponse(ErrorArguments) return 0, errArguments
} }
var args int var args int
err := json.Unmarshal(req.Params[0], &args) err := json.Unmarshal(req.Params[0], &args)
if err != nil { if err != nil {
return 0, NewErrorResponse(ErrorDecodeArgs) return 0, errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToFilterChangedArgs() (int, error) { func (req *RpcRequest) ToFilterChangedArgs() (int, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return 0, NewErrorResponse(ErrorArguments) return 0, errArguments
} }
var id int var id int
r := bytes.NewReader(req.Params[0]) r := bytes.NewReader(req.Params[0])
err := json.NewDecoder(r).Decode(&id) err := json.NewDecoder(r).Decode(&id)
if err != nil { if err != nil {
return 0, NewErrorResponse(ErrorDecodeArgs) return 0, errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", id, id)
return id, nil return id, nil
} }
func (req *RpcRequest) ToDbPutArgs() (*DbArgs, error) { func (req *RpcRequest) ToDbPutArgs() (*DbArgs, error) {
if len(req.Params) < 3 { if len(req.Params) < 3 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
var args DbArgs var args DbArgs
err := json.Unmarshal(req.Params[0], &args.Database) err := json.Unmarshal(req.Params[0], &args.Database)
if err != nil { if err != nil {
return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
} }
err = json.Unmarshal(req.Params[1], &args.Key) err = json.Unmarshal(req.Params[1], &args.Key)
if err != nil { if err != nil {
return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
} }
err = json.Unmarshal(req.Params[2], &args.Value) err = json.Unmarshal(req.Params[2], &args.Value)
if err != nil { if err != nil {
return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
} }
rpclogger.DebugDetailf("%T %v", args, args)
return &args, nil return &args, nil
} }
func (req *RpcRequest) ToDbGetArgs() (*DbArgs, error) { func (req *RpcRequest) ToDbGetArgs() (*DbArgs, error) {
if len(req.Params) < 2 { if len(req.Params) < 2 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
var args DbArgs var args DbArgs
err := json.Unmarshal(req.Params[0], &args.Database) err := json.Unmarshal(req.Params[0], &args.Database)
if err != nil { if err != nil {
return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
} }
err = json.Unmarshal(req.Params[1], &args.Key) err = json.Unmarshal(req.Params[1], &args.Key)
if err != nil { if err != nil {
return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
} }
rpclogger.DebugDetailf("%T %v", args, args)
return &args, nil return &args, nil
} }
func (req *RpcRequest) ToWhisperFilterArgs() (*xeth.Options, error) { func (req *RpcRequest) ToWhisperFilterArgs() (*xeth.Options, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
var args xeth.Options var args xeth.Options
err := json.Unmarshal(req.Params[0], &args) err := json.Unmarshal(req.Params[0], &args)
if err != nil { if err != nil {
return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) return nil, NewErrorWithMessage(errDecodeArgs, err.Error())
} }
rpclogger.DebugDetailf("%T %v", args, args)
return &args, nil return &args, nil
} }
func (req *RpcRequest) ToIdArgs() (int, error) { func (req *RpcRequest) ToIdArgs() (int, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return 0, NewErrorResponse(ErrorArguments) return 0, errArguments
} }
var id int var id int
err := json.Unmarshal(req.Params[0], &id) err := json.Unmarshal(req.Params[0], &id)
if err != nil { if err != nil {
return 0, NewErrorResponse(ErrorDecodeArgs) return 0, errDecodeArgs
} }
rpclogger.DebugDetailf("%T %v", id, id)
return id, nil return id, nil
} }
func (req *RpcRequest) ToWhisperPostArgs() (*WhisperMessageArgs, error) { func (req *RpcRequest) ToWhisperPostArgs() (*WhisperMessageArgs, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, errArguments
} }
var args WhisperMessageArgs var args WhisperMessageArgs
@ -370,13 +359,13 @@ func (req *RpcRequest) ToWhisperPostArgs() (*WhisperMessageArgs, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
rpclogger.DebugDetailf("%T %v", args, args)
return &args, nil return &args, nil
} }
func (req *RpcRequest) ToWhisperHasIdentityArgs() (string, error) { func (req *RpcRequest) ToWhisperHasIdentityArgs() (string, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return "", NewErrorResponse(ErrorArguments) return "", errArguments
} }
var args string var args string
@ -384,13 +373,13 @@ func (req *RpcRequest) ToWhisperHasIdentityArgs() (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToRegisterArgs() (string, error) { func (req *RpcRequest) ToRegisterArgs() (string, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return "", NewErrorResponse(ErrorArguments) return "", errArguments
} }
var args string var args string
@ -398,13 +387,13 @@ func (req *RpcRequest) ToRegisterArgs() (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }
func (req *RpcRequest) ToWatchTxArgs() (string, error) { func (req *RpcRequest) ToWatchTxArgs() (string, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return "", NewErrorResponse(ErrorArguments) return "", errArguments
} }
var args string var args string
@ -412,6 +401,6 @@ func (req *RpcRequest) ToWatchTxArgs() (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
rpclogger.DebugDetailf("%T %v", args, args)
return args, nil return args, nil
} }

View File

@ -99,7 +99,7 @@ func sockHandler(api *rpc.EthereumApi) websocket.Handler {
// reqParsed, reqerr := JSON.ParseRequestBody(conn.Request()) // 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, "Error: Could not parse request"}
JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr}) JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr})
continue continue
} }