forked from cerc-io/plugeth
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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/plugins"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/plugins/wrappers"
|
"github.com/ethereum/go-ethereum/plugins"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/plugins/wrappers"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/openrelayxyz/plugeth-utils/core"
|
"github.com/openrelayxyz/plugeth-utils/core"
|
||||||
"github.com/openrelayxyz/plugeth-utils/restricted"
|
"github.com/openrelayxyz/plugeth-utils/restricted"
|
||||||
)
|
)
|
||||||
|
|
||||||
func apiTranslate(apis []core.API) []rpc.API {
|
func apiTranslate(apis []core.API) []rpc.API {
|
||||||
result := make([]rpc.API, len(apis))
|
result := make([]rpc.API, len(apis))
|
||||||
for i, api := range apis {
|
for i, api := range apis {
|
||||||
result[i] = rpc.API{
|
result[i] = rpc.API{
|
||||||
Namespace: api.Namespace,
|
Namespace: api.Namespace,
|
||||||
Version: api.Version,
|
Version: api.Version,
|
||||||
Service: api.Service,
|
Service: api.Service,
|
||||||
Public: api.Public,
|
Public: api.Public,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAPIsFromLoader(pl *plugins.PluginLoader, stack *node.Node, backend restricted.Backend) []rpc.API {
|
func GetAPIsFromLoader(pl *plugins.PluginLoader, stack *node.Node, backend restricted.Backend) []rpc.API {
|
||||||
result := []core.API{}
|
result := []core.API{}
|
||||||
fnList := pl.Lookup("GetAPIs", func(item interface{}) bool {
|
fnList := pl.Lookup("GetAPIs", func(item interface{}) bool {
|
||||||
switch item.(type) {
|
switch item.(type) {
|
||||||
case func(core.Node, restricted.Backend) []core.API:
|
case func(core.Node, restricted.Backend) []core.API:
|
||||||
return true
|
return true
|
||||||
case func(core.Node, core.Backend) []core.API:
|
case func(core.Node, core.Backend) []core.API:
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
for _, fni := range fnList {
|
for _, fni := range fnList {
|
||||||
switch fn := fni.(type) {
|
switch fn := fni.(type) {
|
||||||
case func(core.Node, restricted.Backend) []core.API:
|
case func(core.Node, restricted.Backend) []core.API:
|
||||||
result = append(result, fn(wrappers.NewNode(stack), backend)...)
|
result = append(result, fn(wrappers.NewNode(stack), backend)...)
|
||||||
case func(core.Node, core.Backend) []core.API:
|
case func(core.Node, core.Backend) []core.API:
|
||||||
result = append(result, fn(wrappers.NewNode(stack), backend)...)
|
result = append(result, fn(wrappers.NewNode(stack), backend)...)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return apiTranslate(result)
|
return apiTranslate(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
func pluginGetAPIs(stack *node.Node, backend restricted.Backend) []rpc.API {
|
func pluginGetAPIs(stack *node.Node, backend restricted.Backend) []rpc.API {
|
||||||
if plugins.DefaultPluginLoader == nil {
|
if plugins.DefaultPluginLoader == nil {
|
||||||
log.Warn("Attempting GetAPIs, but default PluginLoader has not been initialized")
|
log.Warn("Attempting GetAPIs, but default PluginLoader has not been initialized")
|
||||||
return []rpc.API{}
|
return []rpc.API{}
|
||||||
}
|
}
|
||||||
return GetAPIsFromLoader(plugins.DefaultPluginLoader, stack, backend)
|
return GetAPIsFromLoader(plugins.DefaultPluginLoader, stack, backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitializeNode(pl *plugins.PluginLoader, stack *node.Node, backend restricted.Backend) {
|
func InitializeNode(pl *plugins.PluginLoader, stack *node.Node, backend restricted.Backend) {
|
||||||
fnList := pl.Lookup("InitializeNode", func(item interface{}) bool {
|
fnList := pl.Lookup("InitializeNode", func(item interface{}) bool {
|
||||||
switch item.(type) {
|
switch item.(type) {
|
||||||
case func(core.Logger, core.Node, restricted.Backend):
|
case func(core.Node, restricted.Backend):
|
||||||
return true
|
return true
|
||||||
case func(core.Logger, core.Node, core.Backend):
|
case func(core.Node, core.Backend):
|
||||||
return true
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
for _, fni := range fnList {
|
for _, fni := range fnList {
|
||||||
switch fn := fni.(type) {
|
switch fn := fni.(type) {
|
||||||
case func(core.Logger, core.Node, restricted.Backend):
|
case func(core.Node, restricted.Backend):
|
||||||
fn(log.Root(), wrappers.NewNode(stack), backend)
|
fn(wrappers.NewNode(stack), backend)
|
||||||
case func(core.Logger, core.Node, core.Backend):
|
case func(core.Node, core.Backend):
|
||||||
fn(log.Root(), wrappers.NewNode(stack), backend)
|
fn(wrappers.NewNode(stack), backend)
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func pluginsInitializeNode(stack *node.Node, backend restricted.Backend) {
|
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/go-stringutil v0.1.0 // indirect
|
||||||
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
|
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
|
||||||
github.com/olekukonko/tablewriter v0.0.5
|
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/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
|
||||||
github.com/prometheus/tsdb v0.7.1
|
github.com/prometheus/tsdb v0.7.1
|
||||||
github.com/rjeczalik/notify v0.9.1
|
github.com/rjeczalik/notify v0.9.1
|
||||||
@ -71,4 +71,4 @@ require (
|
|||||||
gotest.tools v2.2.0+incompatible // indirect
|
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.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 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
|
||||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
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.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.0.3-0.20180606204148-bd9c31933947/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||||
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
|
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
|
||||||
|
@ -1,30 +1,33 @@
|
|||||||
package plugins
|
package plugins
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/openrelayxyz/plugeth-utils/core"
|
||||||
|
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"path"
|
||||||
"plugin"
|
"plugin"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"gopkg.in/urfave/cli.v1"
|
"gopkg.in/urfave/cli.v1"
|
||||||
"flag"
|
|
||||||
"io/ioutil"
|
|
||||||
"strings"
|
|
||||||
"path"
|
|
||||||
"fmt"
|
|
||||||
"reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type Subcommand func(*cli.Context, []string) error
|
type Subcommand func(*cli.Context, []string) error
|
||||||
|
|
||||||
|
type PluginLoader struct {
|
||||||
type PluginLoader struct{
|
Plugins []*plugin.Plugin
|
||||||
Plugins []*plugin.Plugin
|
|
||||||
Subcommands map[string]Subcommand
|
Subcommands map[string]Subcommand
|
||||||
Flags []*flag.FlagSet
|
Flags []*flag.FlagSet
|
||||||
LookupCache map[string][]interface{}
|
LookupCache map[string][]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pl *PluginLoader) Lookup(name string, validate func(interface{}) bool) []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{}{}
|
results := []interface{}{}
|
||||||
for _, plugin := range pl.Plugins {
|
for _, plugin := range pl.Plugins {
|
||||||
if v, err := plugin.Lookup(name); err == nil {
|
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)
|
return DefaultPluginLoader.Lookup(name, validate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var DefaultPluginLoader *PluginLoader
|
var DefaultPluginLoader *PluginLoader
|
||||||
|
|
||||||
|
|
||||||
func NewPluginLoader(target string) (*PluginLoader, error) {
|
func NewPluginLoader(target string) (*PluginLoader, error) {
|
||||||
pl := &PluginLoader{
|
pl := &PluginLoader{
|
||||||
Plugins: []*plugin.Plugin{},
|
Plugins: []*plugin.Plugin{},
|
||||||
// RPCPlugins: []APILoader{},
|
// RPCPlugins: []APILoader{},
|
||||||
Subcommands: make(map[string]Subcommand),
|
Subcommands: make(map[string]Subcommand),
|
||||||
Flags: []*flag.FlagSet{},
|
Flags: []*flag.FlagSet{},
|
||||||
LookupCache: make(map[string][]interface{}),
|
LookupCache: make(map[string][]interface{}),
|
||||||
// CreateConsensusEngine: ethconfig.CreateConsensusEngine,
|
// CreateConsensusEngine: ethconfig.CreateConsensusEngine,
|
||||||
// UpdateBlockchainVMConfig: func(cfg *vm.Config) {},
|
// UpdateBlockchainVMConfig: func(cfg *vm.Config) {},
|
||||||
@ -106,33 +107,41 @@ func NewPluginLoader(target string) (*PluginLoader, error) {
|
|||||||
|
|
||||||
func Initialize(target string, ctx *cli.Context) (err error) {
|
func Initialize(target string, ctx *cli.Context) (err error) {
|
||||||
DefaultPluginLoader, err = NewPluginLoader(target)
|
DefaultPluginLoader, err = NewPluginLoader(target)
|
||||||
if err != nil { return err }
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
DefaultPluginLoader.Initialize(ctx)
|
DefaultPluginLoader.Initialize(ctx)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pl *PluginLoader) Initialize(ctx *cli.Context) {
|
func (pl *PluginLoader) Initialize(ctx *cli.Context) {
|
||||||
fns := pl.Lookup("Initialize", func(i interface{}) bool {
|
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
|
return ok
|
||||||
})
|
})
|
||||||
for _, fni := range fns {
|
for _, fni := range fns {
|
||||||
if fn, ok := fni.(func(*cli.Context, core.PluginLoader)); ok {
|
if fn, ok := fni.(func(*cli.Context, core.PluginLoader, core.Logger)); ok {
|
||||||
fn(ctx, pl)
|
fn(ctx, pl, log.Root())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pl *PluginLoader) RunSubcommand(ctx *cli.Context) (bool, error) {
|
func (pl *PluginLoader) RunSubcommand(ctx *cli.Context) (bool, error) {
|
||||||
args := ctx.Args()
|
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]]
|
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:])
|
return true, subcommand(ctx, args[1:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunSubcommand(ctx *cli.Context) (bool, error) {
|
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)
|
return DefaultPluginLoader.RunSubcommand(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user