Updated plugin loader, mod, and sum to reflect changes made in utils v0.0.21.

This commit is contained in:
philip-morlier
2022-12-08 11:40:22 -08:00
parent 1805f477ae
commit c0530b8313
3 changed files with 12 additions and 13 deletions
+9 -10
View File
@@ -1,8 +1,6 @@
package plugins
import (
"github.com/openrelayxyz/plugeth-utils/core"
"flag"
"fmt"
"io/ioutil"
@@ -10,13 +8,14 @@ import (
"plugin"
"reflect"
"strings"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/openrelayxyz/plugeth-utils/core"
"github.com/urfave/cli/v2"
)
type Subcommand func(*cli.Context, []string) error
type Subcommand func(core.Context, []string) error
type pluginDetails struct {
p *plugin.Plugin
@@ -93,9 +92,9 @@ func NewPluginLoader(target string) (*PluginLoader, error) {
}
sb, err := plug.Lookup("Subcommands")
if err == nil {
subcommands, ok := sb.(*map[string]func(*cli.Context, []string) error)
subcommands, ok := sb.(*map[string]func(core.Context, []string) error)
if !ok {
log.Warn("Could not cast plugin.Subcommands to `map[string]func(*cli.Context, []string) error`", "file", fpath, "type", reflect.TypeOf(sb))
log.Warn("Could not cast plugin.Subcommands to `map[string]func(core.Context, []string) error`", "file", fpath, "type", reflect.TypeOf(sb))
} else {
for k, v := range *subcommands {
if _, ok := pl.Subcommands[k]; ok {
@@ -110,7 +109,7 @@ func NewPluginLoader(target string) (*PluginLoader, error) {
return pl, nil
}
func Initialize(target string, ctx *cli.Context) (err error) {
func Initialize(target string, ctx core.Context) (err error) {
DefaultPluginLoader, err = NewPluginLoader(target)
if err != nil {
return err
@@ -119,13 +118,13 @@ func Initialize(target string, ctx *cli.Context) (err error) {
return nil
}
func (pl *PluginLoader) Initialize(ctx *cli.Context) {
func (pl *PluginLoader) Initialize(ctx core.Context) {
fns := pl.Lookup("Initialize", func(i interface{}) bool {
_, ok := i.(func(*cli.Context, core.PluginLoader, core.Logger))
_, ok := i.(func(core.Context, core.PluginLoader, core.Logger))
return ok
})
for _, fni := range fns {
if fn, ok := fni.(func(*cli.Context, core.PluginLoader, core.Logger)); ok {
if fn, ok := fni.(func(core.Context, core.PluginLoader, core.Logger)); ok {
fn(ctx, pl, log.Root())
}
}