-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of xplugeth injection and hooks in internal/cli/server/
- Loading branch information
1 parent
2a10448
commit 061ff1c
Showing
5 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/openrelayxyz/xplugeth" | ||
"github.com/openrelayxyz/xplugeth/types" | ||
|
||
"github.com/ethereum/go-ethereum/node" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
) | ||
|
||
type initializer interface { | ||
InitializeNode(*node.Node, types.Backend) | ||
} | ||
type shutdown interface { | ||
Shutdown() | ||
} | ||
type blockchain interface { | ||
Blockchain() | ||
} | ||
type getAPIs interface { | ||
GetAPIs(*node.Node, types.Backend) []rpc.API | ||
} | ||
|
||
func init() { | ||
xplugeth.RegisterHook[initializer]() | ||
xplugeth.RegisterHook[shutdown]() | ||
xplugeth.RegisterHook[blockchain]() | ||
xplugeth.RegisterHook[getAPIs]() | ||
} | ||
|
||
func pluginInitializeNode() { | ||
stack, ok := xplugeth.GetSingleton[*node.Node]() | ||
if !ok { | ||
panic("*node.Node singleton not set, xplugeth InitializeNode") | ||
} | ||
backend, ok := xplugeth.GetSingleton[types.Backend]() | ||
if !ok { | ||
panic("types.Backend singleton not set, xplugeth Initializenode") | ||
} | ||
for _, init := range xplugeth.GetModules[initializer]() { | ||
init.InitializeNode(stack, backend) | ||
} | ||
} | ||
|
||
func pluginGetAPIs() []rpc.API { | ||
result := []rpc.API{} | ||
|
||
stack, ok := xplugeth.GetSingleton[*node.Node]() | ||
if !ok { | ||
panic("*node.Node singleton not set, xplugeth GetAPIs") | ||
} | ||
backend, ok := xplugeth.GetSingleton[types.Backend]() | ||
if !ok { | ||
panic("types.Backend singleton not set xplugeth GetAPIs") | ||
} | ||
|
||
for _, a := range xplugeth.GetModules[getAPIs]() { | ||
result = append(result, a.GetAPIs(stack, backend)...) | ||
} | ||
|
||
return result | ||
} | ||
|
||
func pluginOnShutdown() { | ||
for _, shutdown := range xplugeth.GetModules[shutdown]() { | ||
shutdown.Shutdown() | ||
} | ||
} | ||
|
||
func pluginBlockchain() { | ||
for _, b := range xplugeth.GetModules[blockchain]() { | ||
b.Blockchain() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package server | ||
|
||
// +build example_plugin | ||
|
||
import ( | ||
_ "github.com/openrelayxyz/xplugeth/plugins/example" | ||
) |