2023-03-24 00:03:08 +00:00
|
|
|
package ethconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
"github.com/ethereum/go-ethereum/plugins"
|
2023-03-24 19:46:45 +00:00
|
|
|
"github.com/ethereum/go-ethereum/plugins/wrappers"
|
|
|
|
wengine "github.com/ethereum/go-ethereum/plugins/wrappers/engine"
|
|
|
|
"github.com/ethereum/go-ethereum/plugins/wrappers/backendwrapper"
|
2023-03-24 04:59:14 +00:00
|
|
|
"github.com/openrelayxyz/plugeth-utils/core"
|
|
|
|
"github.com/openrelayxyz/plugeth-utils/restricted"
|
2023-03-24 00:03:08 +00:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/consensus"
|
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
|
|
|
|
|
pconsensus "github.com/openrelayxyz/plugeth-utils/restricted/consensus"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-03-24 04:59:14 +00:00
|
|
|
|
2023-03-24 00:03:08 +00:00
|
|
|
func PluginGetEngine(pl *plugins.PluginLoader, stack *node.Node, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
|
2023-03-24 04:59:14 +00:00
|
|
|
fnList := pl.Lookup("CreateEngine", func(item interface{}) bool {
|
2023-03-24 19:46:45 +00:00
|
|
|
_, ok := item.(func(core.Node, []string, bool, restricted.Database) pconsensus.Engine)
|
2023-03-24 00:03:08 +00:00
|
|
|
return ok
|
|
|
|
})
|
|
|
|
for _, fni := range fnList {
|
2023-03-24 19:46:45 +00:00
|
|
|
if fn, ok := fni.(func(core.Node, []string, bool, restricted.Database) pconsensus.Engine); ok {
|
|
|
|
if engine := fn(wrappers.NewNode(stack), notify, noverify, backendwrapper.NewDB(db)); engine != nil {
|
|
|
|
wrappedEngine := wengine.NewWrappedEngine(engine)
|
|
|
|
return wrappedEngine
|
|
|
|
}
|
|
|
|
|
2023-03-24 00:03:08 +00:00
|
|
|
}
|
|
|
|
}
|
2023-03-24 19:46:45 +00:00
|
|
|
return nil
|
2023-03-24 00:03:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func pluginGetEngine(stack *node.Node, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
|
|
|
|
if plugins.DefaultPluginLoader == nil {
|
|
|
|
log.Warn("Attempting GetEngine, but default PluginLoader has not been initialized")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return PluginGetEngine(plugins.DefaultPluginLoader, stack, notify, noverify, db)
|
|
|
|
}
|