Merge remote-tracking branch 'laconic/add-plugindir-flag' into laconic-merge

This commit is contained in:
philip-morlier 2023-09-07 18:21:23 -07:00
commit 3ca53046eb
3 changed files with 22 additions and 3 deletions

View File

@ -20,7 +20,7 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path/filepath"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@ -57,6 +57,9 @@ const (
var ( var (
// flags that configure the node // flags that configure the node
nodeFlags = flags.Merge([]cli.Flag{ nodeFlags = flags.Merge([]cli.Flag{
//begin PluGeth code injection
utils.PluginsDirFlag,
//end PluGeth code injection
utils.IdentityFlag, utils.IdentityFlag,
utils.UnlockedAccountFlag, utils.UnlockedAccountFlag,
utils.PasswordFileFlag, utils.PasswordFileFlag,
@ -322,7 +325,14 @@ func prepare(ctx *cli.Context) {
// blocking mode, waiting for it to be shut down. // blocking mode, waiting for it to be shut down.
func geth(ctx *cli.Context) error { func geth(ctx *cli.Context) error {
//begin PluGeth code injection //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 = filepath.Join(ctx.String(utils.DataDirFlag.Name), "plugins")
}
if err := plugins.Initialize(pluginsDir, ctx); err != nil {
return err return err
} }
prepare(ctx) prepare(ctx)

View File

@ -88,6 +88,14 @@ import (
var ( var (
// General settings // General settings
//begin PluGeth code injection
PluginsDirFlag = &flags.DirectoryFlag{
Name: "pluginsdir",
Usage: "Directory for plugins",
Value: flags.DirectoryString(filepath.Join("<datadir>", "plugins")),
Category: flags.EthCategory,
}
//end PluGeth code injection
DataDirFlag = &flags.DirectoryFlag{ DataDirFlag = &flags.DirectoryFlag{
Name: "datadir", Name: "datadir",
Usage: "Data directory for the databases and keystore", Usage: "Data directory for the databases and keystore",

View File

@ -8,7 +8,7 @@ import (
"plugin" "plugin"
"reflect" "reflect"
"strings" "strings"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/openrelayxyz/plugeth-utils/core" "github.com/openrelayxyz/plugeth-utils/core"
@ -58,6 +58,7 @@ func Lookup(name string, validate func(interface{}) bool) []interface{} {
var DefaultPluginLoader *PluginLoader var DefaultPluginLoader *PluginLoader
func NewPluginLoader(target string) (*PluginLoader, error) { func NewPluginLoader(target string) (*PluginLoader, error) {
log.Info("Loading plugins from directory", "path", target)
pl := &PluginLoader{ pl := &PluginLoader{
Plugins: []pluginDetails{}, Plugins: []pluginDetails{},
Subcommands: make(map[string]Subcommand), Subcommands: make(map[string]Subcommand),