mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-02 22:21:44 +00:00
rpc: cleanup, use client for tests, rpc-gen fixes
This commit is contained in:
@ -12,8 +12,14 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// maps camel-case function names to lower case rpc version
|
||||
// populated by calls to funcWrap
|
||||
var reverseFuncMap = make(map[string]string)
|
||||
|
||||
// cache all type information about each function up front
|
||||
// (func, responseStruct, argNames)
|
||||
var funcMap = map[string]*FuncWrapper{
|
||||
@ -40,6 +46,16 @@ func initHandlers() {
|
||||
|
||||
// JSONRPC endpoints
|
||||
http.HandleFunc("/", JSONRPCHandler)
|
||||
|
||||
// fill the map from camelcase to lowercase
|
||||
for name, f := range funcMap {
|
||||
camelName := runtime.FuncForPC(f.f.Pointer()).Name()
|
||||
spl := strings.Split(camelName, ".")
|
||||
if len(spl) > 1 {
|
||||
camelName = spl[len(spl)-1]
|
||||
}
|
||||
reverseFuncMap[camelName] = name
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
@ -86,6 +102,10 @@ func funcReturnTypes(f interface{}) []reflect.Type {
|
||||
|
||||
// jsonrpc calls grab the given method's function info and runs reflect.Call
|
||||
func JSONRPCHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if len(r.URL.Path) > 1 {
|
||||
WriteRPCResponse(w, NewRPCResponse(nil, fmt.Sprintf("Invalid JSONRPC endpoint %s", r.URL.Path)))
|
||||
return
|
||||
}
|
||||
b, _ := ioutil.ReadAll(r.Body)
|
||||
var request RPCRequest
|
||||
err := json.Unmarshal(b, &request)
|
||||
|
Reference in New Issue
Block a user