From 25af69b8e2de8be52d92eb2d0fe61ec366396e0a Mon Sep 17 00:00:00 2001 From: philip-morlier Date: Thu, 16 Sep 2021 14:03:50 -0700 Subject: [PATCH] Missing rpc call hook and test --- rpc/getRPCcall_test.go | 28 ++++++++++++++++++++++++++++ rpc/plugin_hooks.go | 26 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 rpc/getRPCcall_test.go create mode 100644 rpc/plugin_hooks.go diff --git a/rpc/getRPCcall_test.go b/rpc/getRPCcall_test.go new file mode 100644 index 000000000..c536a76e4 --- /dev/null +++ b/rpc/getRPCcall_test.go @@ -0,0 +1,28 @@ +package rpc + +import ( + "testing" + + "github.com/ethereum/go-ethereum/plugins" +) + +func TestGetRPCCalls(t *testing.T) { + invoked := false + done := plugins.HookTester("GetRPCCalls", func(id, method, params string) { + invoked = true + if id == "" { + t.Errorf("Expected id to be non-nil") + } + if method == "" { + t.Errorf("Expected method to be non-nil") + } + if params == "" { + t.Errorf("Expected params to be non-nil") + } + }) + defer done() + TestClientResponseType(t) + if !invoked { + t.Errorf("Expected plugin invocation") + } +} diff --git a/rpc/plugin_hooks.go b/rpc/plugin_hooks.go new file mode 100644 index 000000000..16db041ca --- /dev/null +++ b/rpc/plugin_hooks.go @@ -0,0 +1,26 @@ +package rpc + +import ( + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/plugins" +) + +func PluginGetRPCCalls(pl *plugins.PluginLoader, id, method, params string) { + fnList := pl.Lookup("GetRPCCalls", func(item interface{}) bool { + _, ok := item.(func(string, string, string)) + return ok + }) + for _, fni := range fnList { + if fn, ok := fni.(func(string, string, string)); ok { + fn(id, method, params) + } + } +} + +func pluginGetRPCCalls(id, method, params string) { + if plugins.DefaultPluginLoader == nil { + log.Warn("Attempting GerRPCCalls, but default PluginLoader has not been initialized") + return + } + PluginGetRPCCalls(plugins.DefaultPluginLoader, id, method, params) +}