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:
philip-morlier 2021-09-09 12:51:13 -07:00
parent b36e63f184
commit 411a43e378
No known key found for this signature in database
GPG Key ID: 0323A143B7B6F663
4 changed files with 93 additions and 82 deletions

View File

@ -1,11 +1,11 @@
package main
import (
"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/ethereum/go-ethereum/log"
"github.com/openrelayxyz/plugeth-utils/core"
"github.com/openrelayxyz/plugeth-utils/restricted"
)
@ -58,9 +58,9 @@ func pluginGetAPIs(stack *node.Node, backend restricted.Backend) []rpc.API {
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):
case func(core.Node, restricted.Backend):
return true
case func(core.Logger, core.Node, core.Backend):
case func(core.Node, core.Backend):
return true
default:
return false
@ -68,10 +68,10 @@ func InitializeNode(pl *plugins.PluginLoader, stack *node.Node, backend restrict
})
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)
case func(core.Node, restricted.Backend):
fn(wrappers.NewNode(stack), backend)
case func(core.Node, core.Backend):
fn(wrappers.NewNode(stack), backend)
default:
}
}

4
go.mod
View File

@ -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
View File

@ -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=

View File

@ -1,21 +1,22 @@
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
Subcommands map[string]Subcommand
@ -24,7 +25,9 @@ type PluginLoader struct{
}
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,10 +48,8 @@ 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{},
@ -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)
}