From 80e02c90e34e7aa9bcafbb78304524ad0e2fb613 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Thu, 29 Jun 2023 04:44:54 +0000 Subject: [PATCH] Add --pluginsdir flag. (#1) Add a new flag, `--pluginsdir`, for setting the directory where plugins are stored. The default remains `$datadir/plugins`. Co-authored-by: Thomas E Lackey Reviewed-on: https://git.vdb.to/cerc-io/plugeth/pulls/1 --- cmd/geth/main.go | 12 +++++++++++- cmd/utils/flags.go | 7 +++++++ plugins/plugin_loader.go | 3 ++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 93c130478..4e6ba7b56 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -57,6 +57,9 @@ const ( var ( // flags that configure the node nodeFlags = flags.Merge([]cli.Flag{ + //begin PluGeth code injection + utils.PluginsDirFlag, + //end PluGeth code injection utils.IdentityFlag, utils.UnlockedAccountFlag, utils.PasswordFileFlag, @@ -339,7 +342,14 @@ func prepare(ctx *cli.Context) { // blocking mode, waiting for it to be shut down. func geth(ctx *cli.Context) error { //begin PluGeth code injection - if err := plugins.Initialize(path.Join(ctx.String(utils.DataDirFlag.Name), "plugins"), ctx); err != nil { + var pluginsDir string + if ctx.IsSet(utils.PluginsDirFlag.Name) { + pluginsDir = ctx.String(utils.PluginsDirFlag.Name) + } else { + pluginsDir = path.Join(ctx.String(utils.DataDirFlag.Name), "plugins") + } + + if err := plugins.Initialize(pluginsDir, ctx); err != nil { return err } prepare(ctx) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 08de71ee8..62bef192d 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -88,6 +88,13 @@ import ( var ( // General settings + //begin PluGeth code injection + PluginsDirFlag = &flags.DirectoryFlag{ + Name: "pluginsdir", + Usage: "Directory for plugins (default = datadir/plugins)", + Category: flags.EthCategory, + } + //end PluGeth code injection DataDirFlag = &flags.DirectoryFlag{ Name: "datadir", Usage: "Data directory for the databases and keystore", diff --git a/plugins/plugin_loader.go b/plugins/plugin_loader.go index 652988d9c..1e059d9bb 100644 --- a/plugins/plugin_loader.go +++ b/plugins/plugin_loader.go @@ -8,7 +8,7 @@ import ( "plugin" "reflect" "strings" - + "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" "github.com/openrelayxyz/plugeth-utils/core" @@ -58,6 +58,7 @@ func Lookup(name string, validate func(interface{}) bool) []interface{} { var DefaultPluginLoader *PluginLoader func NewPluginLoader(target string) (*PluginLoader, error) { + log.Info("Loading plugins from directory.", "path", target) pl := &PluginLoader{ Plugins: []pluginDetails{}, Subcommands: make(map[string]Subcommand),