plugeth/plugins/rpcloader/rpc_loader.go
Austin Roberts 091a2f4884 Checkpoint
Things are currently broken because of import cycles. I'm going to
need to revisit how the plugin loader works, but I wanted to make
a checkpoint before I start breaking things again.
2021-06-25 17:08:39 -05:00

48 lines
1.4 KiB
Go

package rpcloader
import (
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/plugins"
)
type APILoader func(*node.Node, Backend) []rpc.API
func GetRPCPluginsFromLoader(pl *plugins.PluginLoader) []APILoader {
result := []APILoader{}
for _, plug := range pl.Plugins {
fn, err := plug.Lookup("GetAPIs")
if err == nil {
apiLoader, ok := fn.(func(*node.Node, Backend) []rpc.API)
if !ok {
log.Warn("Could not cast plugin.GetAPIs to APILoader", "file", fpath)
} else {
result = append(result, APILoader(apiLoader))
}
} else { log.Debug("Error retrieving GetAPIs for plugin", "file", fpath, "error", err.Error()) }
}
}
func GetRPCPlugins() []APILoader {
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting GetRPCPlugins, but default PluginLoader has not been initialized")
return []APILoader{}
}
return GetRPCPluginsFromLoader(plugins.DefaultPluginLoader)
}
func GetAPIsFromLoader(pl *plugins.PluginLoader, stack *node.Node, backend Backend) []rpc.API {
apis := []rpc.API{}
for _, apiLoader := range pl.RPCPlugins {
apis = append(apis, apiLoader(stack, backend)...)
}
return apis
}
func GetAPIs(stack *node.Node, backend Backend) []rpc.API {
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting GetAPIs, but default PluginLoader has not been initialized")
return []rpc.API{}
}
return GetAPIsFromLoader(plugins.DefaultPluginLoader, stack, backend)
}