2021-06-26 03:38:04 +00:00
|
|
|
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"
|
2021-06-26 03:38:04 +00:00
|
|
|
"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 03:38:04 +00:00
|
|
|
|
2021-06-26 04:27:09 +00:00
|
|
|
func GetAPIsFromLoader(pl *plugins.PluginLoader, stack *node.Node, backend interfaces.Backend) []rpc.API {
|
2021-06-26 03:38:04 +00:00
|
|
|
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)
|
2021-06-26 03:38:04 +00:00
|
|
|
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 {
|
2021-06-26 03:38:04 +00:00
|
|
|
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 {
|
2021-06-26 03:38:04 +00:00
|
|
|
if plugins.DefaultPluginLoader == nil {
|
|
|
|
log.Warn("Attempting GetAPIs, but default PluginLoader has not been initialized")
|
|
|
|
return []rpc.API{}
|
|
|
|
}
|
|
|
|
return GetAPIsFromLoader(plugins.DefaultPluginLoader, stack, backend)
|
|
|
|
}
|