2021-07-12 19:45:42 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2021-09-01 20:34:03 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
"github.com/ethereum/go-ethereum/plugins"
|
|
|
|
"github.com/opoenrelayxyz/plugeth-utils/core"
|
2021-07-12 19:45:42 +00:00
|
|
|
)
|
|
|
|
|
2021-08-31 20:51:41 +00:00
|
|
|
// TODO (philip): change common.Hash to core.Hash,
|
|
|
|
|
2021-09-01 20:34:03 +00:00
|
|
|
func PluginStateUpdate(pl *plugins.PluginLoader, blockRoot, parentRoot core.Hash, destructs map[core.Hash]struct{}, accounts map[core.Hash][]byte, storage map[core.Hash]map[core.Hash][]byte) {
|
|
|
|
fnList := pl.Lookup("StateUpdate", func(item interface{}) bool {
|
|
|
|
_, ok := item.(func(core.Hash, core.Hash, map[core.Hash]struct{}, map[core.Hash][]byte, map[core.Hash]map[core.Hash][]byte))
|
|
|
|
return ok
|
|
|
|
})
|
|
|
|
for _, fni := range fnList {
|
|
|
|
if fn, ok := fni.(func(core.Hash, core.Hash, map[core.Hash]struct{}, map[core.Hash][]byte, map[core.Hash]map[core.Hash][]byte)); ok {
|
|
|
|
fn(blockRoot, parentRoot, destructs, accounts, storage)
|
|
|
|
}
|
|
|
|
}
|
2021-07-12 19:45:42 +00:00
|
|
|
}
|
|
|
|
|
2021-09-01 20:34:03 +00:00
|
|
|
func pluginStateUpdate(blockRoot, parentRoot core.Hash, destructs map[core.Hash]struct{}, accounts map[core.Hash][]byte, storage map[core.Hash]map[core.Hash][]byte) {
|
2021-07-12 19:45:42 +00:00
|
|
|
if plugins.DefaultPluginLoader == nil {
|
|
|
|
log.Warn("Attempting StateUpdate, but default PluginLoader has not been initialized")
|
2021-09-01 20:34:03 +00:00
|
|
|
return
|
|
|
|
}
|
2021-07-12 19:45:42 +00:00
|
|
|
PluginStateUpdate(plugins.DefaultPluginLoader, blockRoot, parentRoot, destructs, accounts, storage)
|
|
|
|
}
|