|
|
@ -124,7 +124,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc) http.HandlerFunc { |
|
|
|
WriteRPCResponseHTTP(w, types.NewRPCResponse(request.ID, nil, "RPC method is only for websockets: "+request.Method)) |
|
|
|
return |
|
|
|
} |
|
|
|
args, err := jsonParamsToArgs(rpcFunc, request.Params, 0) |
|
|
|
args, err := jsonParamsToArgsRPC(rpcFunc, request.Params) |
|
|
|
if err != nil { |
|
|
|
WriteRPCResponseHTTP(w, types.NewRPCResponse(request.ID, nil, fmt.Sprintf("Error converting json params to arguments: %v", err.Error()))) |
|
|
|
return |
|
|
@ -142,7 +142,7 @@ func makeJSONRPCHandler(funcMap map[string]*RPCFunc) http.HandlerFunc { |
|
|
|
|
|
|
|
// Convert a []interface{} OR a map[string]interface{} to properly typed values
|
|
|
|
//
|
|
|
|
// argsOffset is used in jsonParamsToArgsWS, where len(rpcFunc.args) != len(rpcFunc.argNames).
|
|
|
|
// argsOffset should be 0 for RPC calls, and 1 for WS requests, where len(rpcFunc.args) != len(rpcFunc.argNames).
|
|
|
|
// Example:
|
|
|
|
// rpcFunc.args = [rpctypes.WSRPCContext string]
|
|
|
|
// rpcFunc.argNames = ["arg"]
|
|
|
@ -173,7 +173,7 @@ func jsonParamsToArgs(rpcFunc *RPCFunc, paramsI interface{}, argsOffset int) ([] |
|
|
|
} |
|
|
|
values := make([]reflect.Value, len(params)) |
|
|
|
for i, p := range params { |
|
|
|
ty := rpcFunc.args[i] |
|
|
|
ty := rpcFunc.args[i+argsOffset] |
|
|
|
v, err := _jsonObjectToArg(ty, p) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
@ -187,6 +187,11 @@ func jsonParamsToArgs(rpcFunc *RPCFunc, paramsI interface{}, argsOffset int) ([] |
|
|
|
return values, nil |
|
|
|
} |
|
|
|
|
|
|
|
// Convert a []interface{} OR a map[string]interface{} to properly typed values
|
|
|
|
func jsonParamsToArgsRPC(rpcFunc *RPCFunc, paramsI interface{}) ([]reflect.Value, error) { |
|
|
|
return jsonParamsToArgs(rpcFunc, paramsI, 0) |
|
|
|
} |
|
|
|
|
|
|
|
// Same as above, but with the first param the websocket connection
|
|
|
|
func jsonParamsToArgsWS(rpcFunc *RPCFunc, paramsI interface{}, wsCtx types.WSRPCContext) ([]reflect.Value, error) { |
|
|
|
values, err := jsonParamsToArgs(rpcFunc, paramsI, 1) |
|
|
@ -494,7 +499,7 @@ func (wsc *wsConnection) readRoutine() { |
|
|
|
wsCtx := types.WSRPCContext{Request: request, WSRPCConnection: wsc} |
|
|
|
args, err = jsonParamsToArgsWS(rpcFunc, request.Params, wsCtx) |
|
|
|
} else { |
|
|
|
args, err = jsonParamsToArgs(rpcFunc, request.Params, 0) |
|
|
|
args, err = jsonParamsToArgsRPC(rpcFunc, request.Params) |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
wsc.WriteRPCResponse(types.NewRPCResponse(request.ID, nil, err.Error())) |
|
|
|