rpc: add 'rpc' as always-available module

The MetadataAPI module 'rpc' is registered on
the creation of a new handler.

Signed-off-by: meows <b5c6@protonmail.com>
This commit is contained in:
meows 2020-03-16 08:42:58 -05:00
parent 8d7aa9078f
commit 1e63f2dec1
No known key found for this signature in database
GPG key ID: 5786AEA5C8D5A520

View file

@ -22,18 +22,26 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
// availableAPISetBase defines available api modules which are always available.
var availableAPISetBase = map[string]struct{}{
MetadataApi: {},
}
// checkModuleAvailability check that all names given in modules are actually // checkModuleAvailability check that all names given in modules are actually
// available API services. // available API services.
func checkModuleAvailability(modules []string, apis []API) (bad, available []string) { func checkModuleAvailability(modules []string, apis []API) (bad, available []string) {
availableSet := make(map[string]struct{}) availableAPISet := make(map[string]struct{})
for k, v := range availableAPISetBase {
availableAPISet[k] = v
}
for _, api := range apis { for _, api := range apis {
if _, ok := availableSet[api.Namespace]; !ok { if _, ok := availableAPISet[api.Namespace]; !ok {
availableSet[api.Namespace] = struct{}{} availableAPISet[api.Namespace] = struct{}{}
available = append(available, api.Namespace) available = append(available, api.Namespace)
} }
} }
for _, name := range modules { for _, name := range modules {
if _, ok := availableSet[name]; !ok { if _, ok := availableAPISet[name]; !ok {
bad = append(bad, name) bad = append(bad, name)
} }
} }