rpc: clean up the RPCFunc constructor signature (#7586)

Instead of taking a comma-separated string of parameter names, take each
parameter name as a separate argument. Now that we no longer have an extra flag
for caching, this fits nicely into a variadic trailer.

* Update all usage of NewRPCFunc and NewWSRPCFunc.
This commit is contained in:
M. J. Fromberger
2022-01-13 12:13:28 -08:00
committed by GitHub
parent 8ff367ad29
commit b7c19a5cd4
9 changed files with 34 additions and 39 deletions
+6 -11
View File
@@ -3,7 +3,6 @@ package server
import (
"net/http"
"reflect"
"strings"
"github.com/tendermint/tendermint/libs/log"
)
@@ -35,26 +34,22 @@ type RPCFunc struct {
// NewRPCFunc wraps a function for introspection.
// f is the function, args are comma separated argument names
func NewRPCFunc(f interface{}, args string) *RPCFunc {
return newRPCFunc(f, args, false)
func NewRPCFunc(f interface{}, argNames ...string) *RPCFunc {
return newRPCFunc(f, argNames, false)
}
// NewWSRPCFunc wraps a function for introspection and use in the websockets.
func NewWSRPCFunc(f interface{}, args string) *RPCFunc {
return newRPCFunc(f, args, true)
func NewWSRPCFunc(f interface{}, argNames ...string) *RPCFunc {
return newRPCFunc(f, argNames, true)
}
func newRPCFunc(f interface{}, args string, ws bool) *RPCFunc {
var argNames []string
if args != "" {
argNames = strings.Split(args, ",")
}
func newRPCFunc(f interface{}, argNames []string, wsOnly bool) *RPCFunc {
return &RPCFunc{
f: reflect.ValueOf(f),
args: funcArgTypes(f),
returns: funcReturnTypes(f),
argNames: argNames,
ws: ws,
ws: wsOnly,
}
}