diff --git a/core/plugin_hooks.go b/core/plugin_hooks.go index c5636d9c7..ffd9ff1b9 100644 --- a/core/plugin_hooks.go +++ b/core/plugin_hooks.go @@ -13,7 +13,7 @@ func PluginPreProcessBlock(pl *plugins.PluginLoader, block *types.Block) { _, ok := item.(func([]byte)) return ok }) - encoded, _ = rlp.EncodeToBytes(block) + encoded, _ := rlp.EncodeToBytes(block) for _, fni := range fnList { if fn, ok := fni.(func([]byte)); ok { fn(encoded) diff --git a/plugins/plugin_loader.go b/plugins/plugin_loader.go index 19da5986a..7cd4abd31 100644 --- a/plugins/plugin_loader.go +++ b/plugins/plugin_loader.go @@ -53,12 +53,9 @@ var DefaultPluginLoader *PluginLoader func NewPluginLoader(target string) (*PluginLoader, error) { pl := &PluginLoader{ Plugins: []*plugin.Plugin{}, - // RPCPlugins: []APILoader{}, Subcommands: make(map[string]Subcommand), Flags: []*flag.FlagSet{}, LookupCache: make(map[string][]interface{}), - // CreateConsensusEngine: ethconfig.CreateConsensusEngine, - // UpdateBlockchainVMConfig: func(cfg *vm.Config) {}, } files, err := ioutil.ReadDir(target) if err != nil { diff --git a/plugins/wrappers/wrappers.go b/plugins/wrappers/wrappers.go index 14614f35e..894da0b2c 100644 --- a/plugins/wrappers/wrappers.go +++ b/plugins/wrappers/wrappers.go @@ -6,6 +6,8 @@ import ( "math/big" "sync" "time" + "reflect" + "fmt" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" @@ -22,6 +24,7 @@ import ( "github.com/ethereum/go-ethereum/rpc" "github.com/openrelayxyz/plugeth-utils/core" "github.com/openrelayxyz/plugeth-utils/restricted" + "github.com/openrelayxyz/plugeth-utils/restricted/params" ) type WrappedScopeContext struct { @@ -226,6 +229,7 @@ type Backend struct { pendingLogsOnce sync.Once removedLogsFeed event.Feed removedLogsOnce sync.Once + chainConfig *params.ChainConfig } func NewBackend(b interfaces.Backend) *Backend { @@ -563,3 +567,36 @@ func (b *Backend) SubscribeRemovedLogsEvent(ch chan<- []byte) core.Subscription }) return b.removedLogsFeed.Subscribe(ch) } // RLP encoded logs + +func convertAndSet(a, b reflect.Value) (err error) { + defer func() { + if recover() != nil { + fmt.Errorf("error converting: %v", err.Error()) + } + }() + a.Set(b.Convert(a.Type())) + return nil +} + +func (b *Backend) ChainConfig() *params.ChainConfig { + // We're using the reflect library to copy data from params.ChainConfig to + // pparams.ChainConfig, so this function shouldn't need to be touched for + // simple changes to ChainConfig (though pparams.ChainConfig may need to be + // updated). Note that this probably won't carry over consensus engine data. + if b.chainConfig != nil { return b.chainConfig } + b.chainConfig = ¶ms.ChainConfig{} + nval := reflect.ValueOf(b.b.ChainConfig()) + ntype := nval.Type() + lval := reflect.ValueOf(b.chainConfig) + for i := 0; i < nval.NumField(); i++ { + field := ntype.Field(i) + v := nval.FieldByName(field.Name) + lv := lval.FieldByName(field.Name) + if v.Type() == lv.Type() && lv.CanSet() { + lv.Set(v) + } else { + convertAndSet(lv, v) + } + } + return b.chainConfig +}