plugeth/cmd/geth/plugin_hooks.go

34 lines
1.1 KiB
Go
Raw Normal View History

package main
import (
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/plugins"
2021-06-26 04:27:09 +00:00
"github.com/ethereum/go-ethereum/plugins/interfaces"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/log"
)
2021-06-26 04:27:09 +00:00
type APILoader func(*node.Node, interfaces.Backend) []rpc.API
2021-06-26 04:27:09 +00:00
func GetAPIsFromLoader(pl *plugins.PluginLoader, stack *node.Node, backend interfaces.Backend) []rpc.API {
result := []rpc.API{}
fnList := pl.Lookup("GetAPIs", func(item interface{}) bool {
2021-06-26 04:27:09 +00:00
_, ok := item.(func(*node.Node, interfaces.Backend) []rpc.API)
return ok
})
for _, fni := range fnList {
2021-06-26 04:27:09 +00:00
if fn, ok := fni.(func(*node.Node, interfaces.Backend) []rpc.API); ok {
result = append(result, fn(stack, backend)...)
}
}
return result
}
2021-06-26 04:27:09 +00:00
func pluginGetAPIs(stack *node.Node, backend interfaces.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)
}