forked from cerc-io/plugeth
Add state update hooks
This commit is contained in:
+2
-1
@@ -313,7 +313,7 @@ func prepare(ctx *cli.Context) {
|
||||
// It creates a default node based on the command line arguments and runs it in
|
||||
// blocking mode, waiting for it to be shut down.
|
||||
func geth(ctx *cli.Context) error {
|
||||
if err := plugins.Initialize(path.Join(ctx.GlobalString(utils.DataDirFlag.Name), "plugins")); err != nil { return err }
|
||||
if err := plugins.Initialize(path.Join(ctx.GlobalString(utils.DataDirFlag.Name), "plugins"), ctx); err != nil { return err }
|
||||
if ok, err := plugins.RunSubcommand(ctx); ok { return err }
|
||||
if !plugins.ParseFlags(ctx.Args()) {
|
||||
if args := ctx.Args(); len(args) > 0 {
|
||||
@@ -323,6 +323,7 @@ func geth(ctx *cli.Context) error {
|
||||
|
||||
prepare(ctx)
|
||||
stack, backend := makeFullNode(ctx)
|
||||
pluginsInitializeNode(stack, backend)
|
||||
defer stack.Close()
|
||||
stack.RegisterAPIs(pluginGetAPIs(stack, backend))
|
||||
|
||||
|
||||
@@ -31,3 +31,23 @@ func pluginGetAPIs(stack *node.Node, backend interfaces.Backend) []rpc.API {
|
||||
}
|
||||
return GetAPIsFromLoader(plugins.DefaultPluginLoader, stack, backend)
|
||||
}
|
||||
|
||||
func InitializeNode(pl *plugins.PluginLoader, stack *node.Node, backend interfaces.Backend) {
|
||||
fnList := pl.Lookup("InitializeNode", func(item interface{}) bool {
|
||||
_, ok := item.(func(*node.Node, interfaces.Backend))
|
||||
return ok
|
||||
})
|
||||
for _, fni := range fnList {
|
||||
if fn, ok := fni.(func(*node.Node, interfaces.Backend)); ok {
|
||||
fn(stack, backend)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func pluginsInitializeNode(stack *node.Node, backend interfaces.Backend) {
|
||||
if plugins.DefaultPluginLoader == nil {
|
||||
log.Warn("Attempting InitializeNode, but default PluginLoader has not been initialized")
|
||||
return
|
||||
}
|
||||
InitializeNode(plugins.DefaultPluginLoader, stack, backend)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user