status-go/node/rpc.go

31 lines
745 B
Go
Raw Permalink Normal View History

package node
import (
"reflect"
"unicode"
)
2021-07-16 18:07:43 +00:00
// firstCharToLower converts to first character of name to lowercase.
func firstCharToLower(name string) string {
ret := []rune(name)
if len(ret) > 0 {
ret[0] = unicode.ToLower(ret[0])
}
return string(ret)
}
// addSuitableCallbacks iterates over the methods of the given type and adds them to
// the methods list
// This is taken from go-ethereum services
func addSuitableCallbacks(receiver reflect.Value, namespace string, methods map[string]bool) {
typ := receiver.Type()
for m := 0; m < typ.NumMethod(); m++ {
method := typ.Method(m)
if method.PkgPath != "" {
continue // method not exported
}
2021-07-16 18:07:43 +00:00
name := firstCharToLower(method.Name)
methods[namespace+"_"+name] = true
}
}