Merge pull request #50 from openrelayxyz/feature/onshutdown

Add OnShutdown hook
This commit is contained in:
Philip Morlier 2022-07-29 14:32:56 -07:00 committed by GitHub
commit 1dfed7aed8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -362,6 +362,7 @@ func geth(ctx *cli.Context) error {
return err
}
defer stack.Close()
defer pluginsOnShutdown()
stack.RegisterAPIs(pluginGetAPIs(stack, wrapperBackend))
//end PluGeth code injection
startNode(ctx, stack, backend, false)

View File

@ -84,3 +84,21 @@ func pluginsInitializeNode(stack *node.Node, backend restricted.Backend) {
}
InitializeNode(plugins.DefaultPluginLoader, stack, backend)
}
func OnShutdown(pl *plugins.PluginLoader) {
fnList := pl.Lookup("OnShutdown", func(item interface{}) bool {
_, ok := item.(func())
return ok
})
for _, fni := range fnList {
fni.(func())()
}
}
func pluginsOnShutdown() {
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting OnShutdown, but default PluginLoader has not been initialized")
return
}
OnShutdown(plugins.DefaultPluginLoader)
}