Browse Source

rpc: remove positional parameter encoding from clients (#7545)

Apart from the tests for the websocket client, positional parameters are not
used by RPC clients. The server supports both arrays and objects, but the
client only needs to provide one or the other.
pull/7548/head
M. J. Fromberger 3 years ago
committed by GitHub
parent
commit
211d755aca
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 59 deletions
  1. +0
    -10
      rpc/jsonrpc/client/ws_client.go
  2. +0
    -31
      rpc/jsonrpc/jsonrpc_test.go
  3. +0
    -18
      rpc/jsonrpc/types/types.go

+ 0
- 10
rpc/jsonrpc/client/ws_client.go View File

@ -224,16 +224,6 @@ func (c *WSClient) Call(ctx context.Context, method string, params map[string]in
return c.Send(ctx, request) return c.Send(ctx, request)
} }
// CallWithArrayParams enqueues a call request onto the Send queue. Params are
// in a form of array (e.g. []interface{}{"abcd"}). Requests are JSON encoded.
func (c *WSClient) CallWithArrayParams(ctx context.Context, method string, params []interface{}) error {
request, err := rpctypes.ArrayToRequest(c.nextRequestID(), method, params)
if err != nil {
return err
}
return c.Send(ctx, request)
}
// Private methods // Private methods
func (c *WSClient) nextRequestID() rpctypes.JSONRPCIntID { func (c *WSClient) nextRequestID() rpctypes.JSONRPCIntID {


+ 0
- 31
rpc/jsonrpc/jsonrpc_test.go View File

@ -329,37 +329,6 @@ func TestWSNewWSRPCFunc(t *testing.T) {
assert.Equal(t, got, val) assert.Equal(t, got, val)
} }
func TestWSHandlesArrayParams(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cl, err := client.NewWS(tcpAddr, websocketEndpoint)
require.NoError(t, err)
cl.Logger = log.NewTestingLogger(t)
require.Nil(t, cl.Start(ctx))
t.Cleanup(func() {
if err := cl.Stop(); err != nil {
t.Error(err)
}
})
val := testVal
params := []interface{}{val}
err = cl.CallWithArrayParams(ctx, "echo_ws", params)
require.NoError(t, err)
msg := <-cl.ResponsesCh
if msg.Error != nil {
t.Fatalf("%+v", err)
}
result := new(ResultEcho)
err = json.Unmarshal(msg.Result, result)
require.NoError(t, err)
got := result.Value
assert.Equal(t, got, val)
}
// TestWSClientPingPong checks that a client & server exchange pings // TestWSClientPingPong checks that a client & server exchange pings
// & pongs so connection stays alive. // & pongs so connection stays alive.
func TestWSClientPingPong(t *testing.T) { func TestWSClientPingPong(t *testing.T) {


+ 0
- 18
rpc/jsonrpc/types/types.go View File

@ -116,24 +116,6 @@ func MapToRequest(id jsonrpcid, method string, params map[string]interface{}) (R
return NewRPCRequest(id, method, payload), nil return NewRPCRequest(id, method, payload), nil
} }
func ArrayToRequest(id jsonrpcid, method string, params []interface{}) (RPCRequest, error) {
var paramsMap = make([]json.RawMessage, len(params))
for i, value := range params {
valueJSON, err := tmjson.Marshal(value)
if err != nil {
return RPCRequest{}, err
}
paramsMap[i] = valueJSON
}
payload, err := json.Marshal(paramsMap)
if err != nil {
return RPCRequest{}, err
}
return NewRPCRequest(id, method, payload), nil
}
//---------------------------------------- //----------------------------------------
// RESPONSE // RESPONSE


Loading…
Cancel
Save