updated cmd/geth/plugin_hooks.go and plugins/plugin_loader.go to reflect changes re core.logger, updated go.mod and go.sum to address dependency issues
This commit is contained in:
parent
b36e63f184
commit
411a43e378
@ -1,80 +1,80 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/plugins"
|
||||
"github.com/ethereum/go-ethereum/plugins/wrappers"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/openrelayxyz/plugeth-utils/core"
|
||||
"github.com/openrelayxyz/plugeth-utils/restricted"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/plugins"
|
||||
"github.com/ethereum/go-ethereum/plugins/wrappers"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/openrelayxyz/plugeth-utils/core"
|
||||
"github.com/openrelayxyz/plugeth-utils/restricted"
|
||||
)
|
||||
|
||||
func apiTranslate(apis []core.API) []rpc.API {
|
||||
result := make([]rpc.API, len(apis))
|
||||
for i, api := range apis {
|
||||
result[i] = rpc.API{
|
||||
Namespace: api.Namespace,
|
||||
Version: api.Version,
|
||||
Service: api.Service,
|
||||
Public: api.Public,
|
||||
}
|
||||
}
|
||||
return result
|
||||
result := make([]rpc.API, len(apis))
|
||||
for i, api := range apis {
|
||||
result[i] = rpc.API{
|
||||
Namespace: api.Namespace,
|
||||
Version: api.Version,
|
||||
Service: api.Service,
|
||||
Public: api.Public,
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func GetAPIsFromLoader(pl *plugins.PluginLoader, stack *node.Node, backend restricted.Backend) []rpc.API {
|
||||
result := []core.API{}
|
||||
fnList := pl.Lookup("GetAPIs", func(item interface{}) bool {
|
||||
switch item.(type) {
|
||||
case func(core.Node, restricted.Backend) []core.API:
|
||||
return true
|
||||
case func(core.Node, core.Backend) []core.API:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
})
|
||||
for _, fni := range fnList {
|
||||
switch fn := fni.(type) {
|
||||
case func(core.Node, restricted.Backend) []core.API:
|
||||
result = append(result, fn(wrappers.NewNode(stack), backend)...)
|
||||
case func(core.Node, core.Backend) []core.API:
|
||||
result = append(result, fn(wrappers.NewNode(stack), backend)...)
|
||||
default:
|
||||
}
|
||||
}
|
||||
return apiTranslate(result)
|
||||
result := []core.API{}
|
||||
fnList := pl.Lookup("GetAPIs", func(item interface{}) bool {
|
||||
switch item.(type) {
|
||||
case func(core.Node, restricted.Backend) []core.API:
|
||||
return true
|
||||
case func(core.Node, core.Backend) []core.API:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
})
|
||||
for _, fni := range fnList {
|
||||
switch fn := fni.(type) {
|
||||
case func(core.Node, restricted.Backend) []core.API:
|
||||
result = append(result, fn(wrappers.NewNode(stack), backend)...)
|
||||
case func(core.Node, core.Backend) []core.API:
|
||||
result = append(result, fn(wrappers.NewNode(stack), backend)...)
|
||||
default:
|
||||
}
|
||||
}
|
||||
return apiTranslate(result)
|
||||
}
|
||||
|
||||
func pluginGetAPIs(stack *node.Node, backend restricted.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)
|
||||
}
|
||||
|
||||
func InitializeNode(pl *plugins.PluginLoader, stack *node.Node, backend restricted.Backend) {
|
||||
fnList := pl.Lookup("InitializeNode", func(item interface{}) bool {
|
||||
switch item.(type) {
|
||||
case func(core.Logger, core.Node, restricted.Backend):
|
||||
return true
|
||||
case func(core.Logger, core.Node, core.Backend):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
})
|
||||
for _, fni := range fnList {
|
||||
switch fn := fni.(type) {
|
||||
case func(core.Logger, core.Node, restricted.Backend):
|
||||
fn(log.Root(), wrappers.NewNode(stack), backend)
|
||||
case func(core.Logger, core.Node, core.Backend):
|
||||
fn(log.Root(), wrappers.NewNode(stack), backend)
|
||||
default:
|
||||
}
|
||||
}
|
||||
fnList := pl.Lookup("InitializeNode", func(item interface{}) bool {
|
||||
switch item.(type) {
|
||||
case func(core.Node, restricted.Backend):
|
||||
return true
|
||||
case func(core.Node, core.Backend):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
})
|
||||
for _, fni := range fnList {
|
||||
switch fn := fni.(type) {
|
||||
case func(core.Node, restricted.Backend):
|
||||
fn(wrappers.NewNode(stack), backend)
|
||||
case func(core.Node, core.Backend):
|
||||
fn(wrappers.NewNode(stack), backend)
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func pluginsInitializeNode(stack *node.Node, backend restricted.Backend) {
|
||||
|
4
go.mod
4
go.mod
@ -49,7 +49,7 @@ require (
|
||||
github.com/naoina/go-stringutil v0.1.0 // indirect
|
||||
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
|
||||
github.com/olekukonko/tablewriter v0.0.5
|
||||
github.com/openrelayxyz/plugeth-utils v0.0.3
|
||||
github.com/openrelayxyz/plugeth-utils v0.0.4
|
||||
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
|
||||
github.com/prometheus/tsdb v0.7.1
|
||||
github.com/rjeczalik/notify v0.9.1
|
||||
@ -71,4 +71,4 @@ require (
|
||||
gotest.tools v2.2.0+incompatible // indirect
|
||||
)
|
||||
|
||||
replace github.com/openrelayxyz/plugeth-utils => /home/philip/src/rivet/plugeth-utils
|
||||
//replace github.com/openrelayxyz/plugeth-utils => /home/philip/src/rivet/plugeth-utils
|
||||
|
2
go.sum
2
go.sum
@ -303,6 +303,8 @@ github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/openrelayxyz/plugeth-utils v0.0.4 h1:bRWY9ebYxon0fFEJgUWx1m9i6UjOIiu1CpEcEsi6LQI=
|
||||
github.com/openrelayxyz/plugeth-utils v0.0.4/go.mod h1:+FQQKFpUdNMHCbdg0Ug3/hSvEcSbhA5fN+7fM0RfN/U=
|
||||
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/opentracing/opentracing-go v1.0.3-0.20180606204148-bd9c31933947/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
|
||||
|
@ -1,30 +1,33 @@
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"github.com/openrelayxyz/plugeth-utils/core"
|
||||
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"plugin"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"gopkg.in/urfave/cli.v1"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"path"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
|
||||
type Subcommand func(*cli.Context, []string) error
|
||||
|
||||
|
||||
type PluginLoader struct{
|
||||
Plugins []*plugin.Plugin
|
||||
type PluginLoader struct {
|
||||
Plugins []*plugin.Plugin
|
||||
Subcommands map[string]Subcommand
|
||||
Flags []*flag.FlagSet
|
||||
Flags []*flag.FlagSet
|
||||
LookupCache map[string][]interface{}
|
||||
}
|
||||
|
||||
func (pl *PluginLoader) Lookup(name string, validate func(interface{}) bool) []interface{} {
|
||||
if v, ok := pl.LookupCache[name]; ok { return v }
|
||||
if v, ok := pl.LookupCache[name]; ok {
|
||||
return v
|
||||
}
|
||||
results := []interface{}{}
|
||||
for _, plugin := range pl.Plugins {
|
||||
if v, err := plugin.Lookup(name); err == nil {
|
||||
@ -45,16 +48,14 @@ func Lookup(name string, validate func(interface{}) bool) []interface{} {
|
||||
return DefaultPluginLoader.Lookup(name, validate)
|
||||
}
|
||||
|
||||
|
||||
var DefaultPluginLoader *PluginLoader
|
||||
|
||||
|
||||
func NewPluginLoader(target string) (*PluginLoader, error) {
|
||||
pl := &PluginLoader{
|
||||
Plugins: []*plugin.Plugin{},
|
||||
// RPCPlugins: []APILoader{},
|
||||
Subcommands: make(map[string]Subcommand),
|
||||
Flags: []*flag.FlagSet{},
|
||||
Flags: []*flag.FlagSet{},
|
||||
LookupCache: make(map[string][]interface{}),
|
||||
// CreateConsensusEngine: ethconfig.CreateConsensusEngine,
|
||||
// UpdateBlockchainVMConfig: func(cfg *vm.Config) {},
|
||||
@ -106,33 +107,41 @@ func NewPluginLoader(target string) (*PluginLoader, error) {
|
||||
|
||||
func Initialize(target string, ctx *cli.Context) (err error) {
|
||||
DefaultPluginLoader, err = NewPluginLoader(target)
|
||||
if err != nil { return err }
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
DefaultPluginLoader.Initialize(ctx)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pl *PluginLoader) Initialize(ctx *cli.Context) {
|
||||
fns := pl.Lookup("Initialize", func(i interface{}) bool {
|
||||
_, ok := i.(func(*cli.Context, core.PluginLoader))
|
||||
_, ok := i.(func(*cli.Context, core.PluginLoader, core.Logger))
|
||||
return ok
|
||||
})
|
||||
for _, fni := range fns {
|
||||
if fn, ok := fni.(func(*cli.Context, core.PluginLoader)); ok {
|
||||
fn(ctx, pl)
|
||||
if fn, ok := fni.(func(*cli.Context, core.PluginLoader, core.Logger)); ok {
|
||||
fn(ctx, pl, log.Root())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (pl *PluginLoader) RunSubcommand(ctx *cli.Context) (bool, error) {
|
||||
args := ctx.Args()
|
||||
if len(args) == 0 { return false, fmt.Errorf("No subcommand arguments")}
|
||||
if len(args) == 0 {
|
||||
return false, fmt.Errorf("no subcommand arguments")
|
||||
}
|
||||
subcommand, ok := pl.Subcommands[args[0]]
|
||||
if !ok { return false, fmt.Errorf("Subcommand %v does not exist", args[0])}
|
||||
if !ok {
|
||||
return false, fmt.Errorf("Subcommand %v does not exist", args[0])
|
||||
}
|
||||
return true, subcommand(ctx, args[1:])
|
||||
}
|
||||
|
||||
func RunSubcommand(ctx *cli.Context) (bool, error) {
|
||||
if DefaultPluginLoader == nil { return false, fmt.Errorf("Plugin loader not initialized") }
|
||||
if DefaultPluginLoader == nil {
|
||||
return false, fmt.Errorf("Plugin loader not initialized")
|
||||
}
|
||||
return DefaultPluginLoader.RunSubcommand(ctx)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user