|
|
@ -129,10 +129,13 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han |
|
|
|
WriteRPCResponseHTTP(w, types.RPCMethodNotFoundError(request.ID)) |
|
|
|
return |
|
|
|
} |
|
|
|
args, err := jsonParamsToArgsRPC(rpcFunc, request.Params) |
|
|
|
if err != nil { |
|
|
|
WriteRPCResponseHTTP(w, types.RPCInvalidParamsError(request.ID, errors.Wrap(err, "Error converting json params to arguments"))) |
|
|
|
return |
|
|
|
var args []reflect.Value |
|
|
|
if len(request.Params) > 0 { |
|
|
|
args, err = jsonParamsToArgsRPC(rpcFunc, request.Params) |
|
|
|
if err != nil { |
|
|
|
WriteRPCResponseHTTP(w, types.RPCInvalidParamsError(request.ID, errors.Wrap(err, "Error converting json params to arguments"))) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
returns := rpcFunc.f.Call(args) |
|
|
|
logger.Info("HTTPJSONRPC", "method", request.Method, "args", args, "returns", returns) |
|
|
@ -210,13 +213,13 @@ func jsonParamsToArgs(rpcFunc *RPCFunc, raw []byte, argsOffset int) ([]reflect.V |
|
|
|
} |
|
|
|
|
|
|
|
// Convert a []interface{} OR a map[string]interface{} to properly typed values
|
|
|
|
func jsonParamsToArgsRPC(rpcFunc *RPCFunc, params *json.RawMessage) ([]reflect.Value, error) { |
|
|
|
return jsonParamsToArgs(rpcFunc, *params, 0) |
|
|
|
func jsonParamsToArgsRPC(rpcFunc *RPCFunc, params json.RawMessage) ([]reflect.Value, error) { |
|
|
|
return jsonParamsToArgs(rpcFunc, params, 0) |
|
|
|
} |
|
|
|
|
|
|
|
// Same as above, but with the first param the websocket connection
|
|
|
|
func jsonParamsToArgsWS(rpcFunc *RPCFunc, params *json.RawMessage, wsCtx types.WSRPCContext) ([]reflect.Value, error) { |
|
|
|
values, err := jsonParamsToArgs(rpcFunc, *params, 1) |
|
|
|
func jsonParamsToArgsWS(rpcFunc *RPCFunc, params json.RawMessage, wsCtx types.WSRPCContext) ([]reflect.Value, error) { |
|
|
|
values, err := jsonParamsToArgs(rpcFunc, params, 1) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
@ -547,11 +550,11 @@ func (wsc *wsConnection) readRoutine() { |
|
|
|
var args []reflect.Value |
|
|
|
if rpcFunc.ws { |
|
|
|
wsCtx := types.WSRPCContext{Request: request, WSRPCConnection: wsc} |
|
|
|
if request.Params != nil { |
|
|
|
if len(request.Params) > 0 { |
|
|
|
args, err = jsonParamsToArgsWS(rpcFunc, request.Params, wsCtx) |
|
|
|
} |
|
|
|
} else { |
|
|
|
if request.Params != nil { |
|
|
|
if len(request.Params) > 0 { |
|
|
|
args, err = jsonParamsToArgsRPC(rpcFunc, request.Params) |
|
|
|
} |
|
|
|
} |
|
|
|