plugeth/trie/plugin_hooks.go
philip-morlier 27810f60ad Added hook into trie.Database.Commit() in the trie package.
The hook enables a pre and post commit plugin to report on the status of the commit and expose this information to plugins.
2023-03-08 09:59:47 -08:00

46 lines
1.2 KiB
Go

package trie
import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/plugins"
)
func PluginPreTrieCommit(pl *plugins.PluginLoader, node common.Hash) {
fnList := pl.Lookup("PreTrieCommit", func(item interface{}) bool {
_, ok := item.(func(common.Hash))
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func(common.Hash)); ok {
fn(node)
}
}
}
func pluginPreTrieCommit(node common.Hash,) {
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting PreTrieCommit, but default PluginLoader has not been initialized")
return
}
PluginPreTrieCommit(plugins.DefaultPluginLoader, node)
}
func PluginPostTrieCommit(pl *plugins.PluginLoader, node common.Hash) {
fnList := pl.Lookup("PostTrieCommit", func(item interface{}) bool {
_, ok := item.(func(common.Hash))
return ok
})
for _, fni := range fnList {
if fn, ok := fni.(func(common.Hash)); ok {
fn(node)
}
}
}
func pluginPostTrieCommit(node common.Hash,) {
if plugins.DefaultPluginLoader == nil {
log.Warn("Attempting PostTrieCommit, but default PluginLoader has not been initialized")
return
}
PluginPostTrieCommit(plugins.DefaultPluginLoader, node)
}