Make injectable versions of plugin calls
This commit is contained in:
parent
03808de29a
commit
b821bd9948
@ -3,10 +3,11 @@ package core
|
|||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/plugins"
|
"github.com/ethereum/go-ethereum/plugins"
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func pluginPreProcessBlock(block *types.Block) {
|
func PluginPreProcessBlock(pl *plugins.PluginLoader, block *types.Block) {
|
||||||
fnList := plugins.Lookup("ProcessBlock", func(item interface{}) bool {
|
fnList := pl.Lookup("ProcessBlock", func(item interface{}) bool {
|
||||||
_, ok := item.(func(*types.Block))
|
_, ok := item.(func(*types.Block))
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
@ -16,8 +17,15 @@ func pluginPreProcessBlock(block *types.Block) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func pluginPreProcessTransaction(tx *types.Transaction, block *types.Block, i int) {
|
func pluginPreProcessBlock(block *types.Block) {
|
||||||
fnList := plugins.Lookup("ProcessTransaction", func(item interface{}) bool {
|
if plugins.DefaultPluginLoader == nil {
|
||||||
|
log.Warn("Attempting PreProcessBlock, but default PluginLoader has not been initialized")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
PluginPreProcessBlock(plugins.DefaultPluginLoader, block) // TODO
|
||||||
|
}
|
||||||
|
func PluginPreProcessTransaction(pl *plugins.PluginLoader, tx *types.Transaction, block *types.Block, i int) {
|
||||||
|
fnList := pl.Lookup("ProcessTransaction", func(item interface{}) bool {
|
||||||
_, ok := item.(func(*types.Transaction, *types.Block, int))
|
_, ok := item.(func(*types.Transaction, *types.Block, int))
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
@ -27,8 +35,15 @@ func pluginPreProcessTransaction(tx *types.Transaction, block *types.Block, i in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func pluginBlockProcessingError(tx *types.Transaction, block *types.Block, err error) {
|
func pluginPreProcessTransaction(tx *types.Transaction, block *types.Block, i int) {
|
||||||
fnList := plugins.Lookup("ProcessingError", func(item interface{}) bool {
|
if plugins.DefaultPluginLoader == nil {
|
||||||
|
log.Warn("Attempting PreProcessTransaction, but default PluginLoader has not been initialized")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
PluginPreProcessTransaction(plugins.DefaultPluginLoader, tx, block, i)
|
||||||
|
}
|
||||||
|
func PluginBlockProcessingError(pl *plugins.PluginLoader, tx *types.Transaction, block *types.Block, err error) {
|
||||||
|
fnList := pl.Lookup("ProcessingError", func(item interface{}) bool {
|
||||||
_, ok := item.(func(*types.Transaction, *types.Block, error))
|
_, ok := item.(func(*types.Transaction, *types.Block, error))
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
@ -38,8 +53,15 @@ func pluginBlockProcessingError(tx *types.Transaction, block *types.Block, err e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func pluginPostProcessTransaction(tx *types.Transaction, block *types.Block, i int, receipt *types.Receipt) {
|
func pluginBlockProcessingError(tx *types.Transaction, block *types.Block, err error) {
|
||||||
fnList := plugins.Lookup("ProcessTransaction", func(item interface{}) bool {
|
if plugins.DefaultPluginLoader == nil {
|
||||||
|
log.Warn("Attempting BlockProcessingError, but default PluginLoader has not been initialized")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
PluginBlockProcessingError(plugins.DefaultPluginLoader, tx, block, err)
|
||||||
|
}
|
||||||
|
func PluginPostProcessTransaction(pl *plugins.PluginLoader, tx *types.Transaction, block *types.Block, i int, receipt *types.Receipt) {
|
||||||
|
fnList := pl.Lookup("ProcessTransaction", func(item interface{}) bool {
|
||||||
_, ok := item.(func(*types.Transaction, *types.Block, int, *types.Receipt))
|
_, ok := item.(func(*types.Transaction, *types.Block, int, *types.Receipt))
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
@ -49,8 +71,15 @@ func pluginPostProcessTransaction(tx *types.Transaction, block *types.Block, i i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func pluginPostProcessBlock(block *types.Block) {
|
func pluginPostProcessTransaction(tx *types.Transaction, block *types.Block, i int, receipt *types.Receipt) {
|
||||||
fnList := plugins.Lookup("ProcessBlock", func(item interface{}) bool {
|
if plugins.DefaultPluginLoader == nil {
|
||||||
|
log.Warn("Attempting PostProcessTransaction, but default PluginLoader has not been initialized")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
PluginPostProcessTransaction(plugins.DefaultPluginLoader, tx, block, i, receipt)
|
||||||
|
}
|
||||||
|
func PluginPostProcessBlock(pl *plugins.PluginLoader, block *types.Block) {
|
||||||
|
fnList := pl.Lookup("ProcessBlock", func(item interface{}) bool {
|
||||||
_, ok := item.(func(*types.Block))
|
_, ok := item.(func(*types.Block))
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
@ -60,3 +89,10 @@ func pluginPostProcessBlock(block *types.Block) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func pluginPostProcessBlock(block *types.Block) {
|
||||||
|
if plugins.DefaultPluginLoader == nil {
|
||||||
|
log.Warn("Attempting PostProcessBlock, but default PluginLoader has not been initialized")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
PluginPostProcessBlock(plugins.DefaultPluginLoader, block)
|
||||||
|
}
|
||||||
|
@ -9,11 +9,11 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||||
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func PluginCreateConsensusEngine(pl *plugins.PluginLoader, stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
|
||||||
func pluginCreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
|
fnList := pl.Lookup("CreateConsensusEngine", func(item interface{}) bool {
|
||||||
fnList := plugins.Lookup("CreateConsensusEngine", func(item interface{}) bool {
|
|
||||||
_, ok := item.(func(*node.Node, *params.ChainConfig, *ethash.Config, []string, bool, ethdb.Database) consensus.Engine)
|
_, ok := item.(func(*node.Node, *params.ChainConfig, *ethash.Config, []string, bool, ethdb.Database) consensus.Engine)
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
@ -24,7 +24,16 @@ import (
|
|||||||
}
|
}
|
||||||
return ethconfig.CreateConsensusEngine(stack, chainConfig, config, notify, noverify, db)
|
return ethconfig.CreateConsensusEngine(stack, chainConfig, config, notify, noverify, db)
|
||||||
}
|
}
|
||||||
func pluginUpdateBlockchainVMConfig(cfg *vm.Config) {
|
|
||||||
|
func pluginCreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
|
||||||
|
if plugins.DefaultPluginLoader == nil {
|
||||||
|
log.Warn("Attempting CreateConsensusEngine, but default PluginLoader has not been initialized")
|
||||||
|
return ethconfig.CreateConsensusEngine(stack, chainConfig, config, notify, noverify, db)
|
||||||
|
}
|
||||||
|
return PluginCreateConsensusEngine(plugins.DefaultPluginLoader, stack, chainConfig, config, notify, noverify, db)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PluginUpdateBlockchainVMConfig(pl *plugins.PluginLoader, cfg *vm.Config) {
|
||||||
fnList := plugins.Lookup("UpdateBlockchainVMConfig", func(item interface{}) bool {
|
fnList := plugins.Lookup("UpdateBlockchainVMConfig", func(item interface{}) bool {
|
||||||
_, ok := item.(func(*vm.Config))
|
_, ok := item.(func(*vm.Config))
|
||||||
return ok
|
return ok
|
||||||
@ -37,16 +46,11 @@ func pluginUpdateBlockchainVMConfig(cfg *vm.Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ce, err := plug.Lookup("CreateConsensusEngine")
|
|
||||||
// if err == nil {
|
func pluginUpdateBlockchainVMConfig(cfg *vm.Config) {
|
||||||
// cce, ok := ce.(func (stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine)
|
if plugins.DefaultPluginLoader == nil {
|
||||||
// if !ok {
|
log.Warn("Attempting CreateConsensusEngine, but default PluginLoader has not been initialized")
|
||||||
// log.Warn("Could not cast plugin.CreateConsensusEngine to appropriate function", "file", fpath)
|
return
|
||||||
// } else {
|
}
|
||||||
// if setConsensus {
|
PluginUpdateBlockchainVMConfig(plugins.DefaultPluginLoader, cfg)
|
||||||
// log.Warn("CreateConsensusEngine redeclared", "file", fpath)
|
}
|
||||||
// }
|
|
||||||
// pl.CreateConsensusEngine = cce
|
|
||||||
// setConsensus = true
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/plugins"
|
"github.com/ethereum/go-ethereum/plugins"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -12,8 +13,8 @@ type TracerResult interface {
|
|||||||
GetResult() (interface{}, error)
|
GetResult() (interface{}, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPluginTracer(name string) (func(*state.StateDB)TracerResult, bool) {
|
func GetPluginTracer(pl *plugins.PluginLoader, name string) (func(*state.StateDB)TracerResult, bool) {
|
||||||
tracers := plugins.Lookup("Tracers", func(item interface{}) bool {
|
tracers := pl.Lookup("Tracers", func(item interface{}) bool {
|
||||||
_, ok := item.(map[string]func(*state.StateDB)TracerResult)
|
_, ok := item.(map[string]func(*state.StateDB)TracerResult)
|
||||||
return ok
|
return ok
|
||||||
})
|
})
|
||||||
@ -26,3 +27,11 @@ func getPluginTracer(name string) (func(*state.StateDB)TracerResult, bool) {
|
|||||||
}
|
}
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getPluginTracer(name string) (func(*state.StateDB)TracerResult, bool) {
|
||||||
|
if plugins.DefaultPluginLoader == nil {
|
||||||
|
log.Warn("Attempting GetPluginTracer, but default PluginLoader has not been initialized")
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
return GetPluginTracer(plugins.DefaultPluginLoader, name)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user