|
@ -129,10 +129,13 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc, logger log.Logger) http.Han |
|
|
WriteRPCResponseHTTP(w, types.RPCMethodNotFoundError(request.ID)) |
|
|
WriteRPCResponseHTTP(w, types.RPCMethodNotFoundError(request.ID)) |
|
|
return |
|
|
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) |
|
|
returns := rpcFunc.f.Call(args) |
|
|
logger.Info("HTTPJSONRPC", "method", request.Method, "args", args, "returns", returns) |
|
|
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
|
|
|
// 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
|
|
|
// 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 { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
@ -547,11 +550,11 @@ func (wsc *wsConnection) readRoutine() { |
|
|
var args []reflect.Value |
|
|
var args []reflect.Value |
|
|
if rpcFunc.ws { |
|
|
if rpcFunc.ws { |
|
|
wsCtx := types.WSRPCContext{Request: request, WSRPCConnection: wsc} |
|
|
wsCtx := types.WSRPCContext{Request: request, WSRPCConnection: wsc} |
|
|
if request.Params != nil { |
|
|
|
|
|
|
|
|
if len(request.Params) > 0 { |
|
|
args, err = jsonParamsToArgsWS(rpcFunc, request.Params, wsCtx) |
|
|
args, err = jsonParamsToArgsWS(rpcFunc, request.Params, wsCtx) |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
if request.Params != nil { |
|
|
|
|
|
|
|
|
if len(request.Params) > 0 { |
|
|
args, err = jsonParamsToArgsRPC(rpcFunc, request.Params) |
|
|
args, err = jsonParamsToArgsRPC(rpcFunc, request.Params) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|