plugeth/core/plugin_hooks.go
Austin Roberts 03808de29a Refactor plugin system
When the plugin loader itself had to know the types in the arguments
and return values of the plugin functions, it was very difficult to
avoid import loops, given that the types were often defined in the
same package that needed to invoke the plugins.

Under this model, the plugin loader has much less knowledge of the
plugins themselves, and within each package we define functions to
interact with the plugins.
2021-06-25 22:46:17 -05:00

63 lines
1.9 KiB
Go

package core
import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/plugins"
)
func pluginPreProcessBlock(block *types.Block) {
fnList := plugins.Lookup("ProcessBlock", func(item interface{}) bool {
_, ok := item.(func(*types.Block))
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func(*types.Block)); ok {
fn(block)
}
}
}
func pluginPreProcessTransaction(tx *types.Transaction, block *types.Block, i int) {
fnList := plugins.Lookup("ProcessTransaction", func(item interface{}) bool {
_, ok := item.(func(*types.Transaction, *types.Block, int))
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func(*types.Transaction, *types.Block, int)); ok {
fn(tx, block, i)
}
}
}
func pluginBlockProcessingError(tx *types.Transaction, block *types.Block, err error) {
fnList := plugins.Lookup("ProcessingError", func(item interface{}) bool {
_, ok := item.(func(*types.Transaction, *types.Block, error))
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func(*types.Transaction, *types.Block, error)); ok {
fn(tx, block, err)
}
}
}
func pluginPostProcessTransaction(tx *types.Transaction, block *types.Block, i int, receipt *types.Receipt) {
fnList := plugins.Lookup("ProcessTransaction", func(item interface{}) bool {
_, ok := item.(func(*types.Transaction, *types.Block, int, *types.Receipt))
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func(*types.Transaction, *types.Block, int, *types.Receipt)); ok {
fn(tx, block, i, receipt)
}
}
}
func pluginPostProcessBlock(block *types.Block) {
fnList := plugins.Lookup("ProcessBlock", func(item interface{}) bool {
_, ok := item.(func(*types.Block))
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func(*types.Block)); ok {
fn(block)
}
}
}