common

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 18 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadResult  = errors.New("bad result in JSON-RPC response")
	ErrClientQuit = errors.New("client is closed")
	ErrNoResult   = errors.New("JSON-RPC response has no result")
)
View Source
var ParkedCallbacks map[string]bool = map[string]bool{
	"start":       true,
	"stop":        true,
	"connectCore": true,
	"configure":   true,
	"cliCommand":  true,
}

Should not be accessible over communication channels

Functions

func ContextRequestTimeout

func ContextRequestTimeout(ctx context.Context) (time.Duration, bool)

ContextRequestTimeout returns the request timeout derived from the given context.

Types

type Callback

type Callback struct {
	// contains filtered or unexported fields
}

callback is a method callback which was registered in the core

type Client

type Client struct {
	// contains filtered or unexported fields
}

func ClientFromContext

func ClientFromContext(ctx context.Context) (*Client, bool)

func NewClient

func NewClient(
	initctx context.Context,
	serviceName string,
	serviceCallbacks map[string]*Callback,
	knownCallbacks map[string]bool,
) (string, *Client, *commChannels, error)

func (*Client) Call

func (c *Client) Call(result interface{}, method string, notifyAll bool, notificationExclusion []string, args ...interface{}) error

Call performs a JSON-RPC call with the given arguments and unmarshals into result if no error occurred.

The result must be a pointer so that package json can unmarshal into it. You can also pass nil, in which case the result is ignored.

func (*Client) CallContext

func (c *Client) CallContext(ctx context.Context, result interface{}, method string, notifyAll bool, notificationExclusion []string, args ...interface{}) error

CallContext performs a JSON-RPC call with the given arguments. If the context is canceled before the call has successfully returned, CallContext returns immediately.

The result must be a pointer so that package json can unmarshal into it. You can also pass nil, in which case the result is ignored.

func (*Client) Close

func (c *Client) Close()

Close closes the client, aborting any in-flight requests.

func (*Client) Notify

func (c *Client) Notify(ctx context.Context, method string, notifyAll bool, notificationExclusion []string, args ...interface{}) error

Notify sends a notification, i.e. a method call that doesn't expect a response.

func (*Client) Ping

func (c *Client) Ping(message string) error

type JsonRPCMessage

type JsonRPCMessage struct {
	Version         string          `json:"jsonrpc,omitempty"`
	ID              json.RawMessage `json:"id,omitempty"`
	Method          string          `json:"method,omitempty"`
	Params          json.RawMessage `json:"params,omitempty"`
	Error           *jsonError      `json:"error,omitempty"`
	Result          json.RawMessage `json:"result,omitempty"`
	NotifyAll       bool            `json:"notifyAll"`
	NotifyExclusion []string        `json:"notifyExclusion,omitempty"`
	Origin          string          `json:"origin,omitempty"`
}

func ErrorMessage

func ErrorMessage(err error) *JsonRPCMessage

func (*JsonRPCMessage) ErrorResponse

func (msg *JsonRPCMessage) ErrorResponse(err error) *JsonRPCMessage

func (*JsonRPCMessage) HasValidID

func (msg *JsonRPCMessage) HasValidID() bool

func (*JsonRPCMessage) HasValidVersion

func (msg *JsonRPCMessage) HasValidVersion() bool

func (*JsonRPCMessage) IsCall

func (msg *JsonRPCMessage) IsCall() bool

func (*JsonRPCMessage) IsNotification

func (msg *JsonRPCMessage) IsNotification() bool

func (*JsonRPCMessage) IsResponse

func (msg *JsonRPCMessage) IsResponse() bool

func (*JsonRPCMessage) MethodName

func (msg *JsonRPCMessage) MethodName() string

func (*JsonRPCMessage) Namespace

func (msg *JsonRPCMessage) Namespace() string

func (*JsonRPCMessage) Response

func (msg *JsonRPCMessage) Response(result interface{}) *JsonRPCMessage

func (*JsonRPCMessage) String

func (msg *JsonRPCMessage) String() string

type Module

type Module struct {
	Name         string
	Service      Service
	ServiceAlive bool
	Callbacks    map[string]*Callback
}

type ModuleCommChannels

type ModuleCommChannels struct {
	Incoming chan JsonRPCMessage
	Outgoing chan JsonRPCMessage
}

type ModuleRegistry

type ModuleRegistry struct {
	// contains filtered or unexported fields
}

func (*ModuleRegistry) ModuleNames

func (r *ModuleRegistry) ModuleNames() []string

func (*ModuleRegistry) Modules

func (r *ModuleRegistry) Modules() []Module

func (*ModuleRegistry) RegisterName

func (r *ModuleRegistry) RegisterName(name string, rcvr Service) error

func (*ModuleRegistry) StartModuleServices

func (r *ModuleRegistry) StartModuleServices() (started []string, err error)

func (*ModuleRegistry) StopModuleServices

func (r *ModuleRegistry) StopModuleServices() (stopped []string, err error)

type Service

type Service interface {
	// Any attached service must implement these method.
	Name() string
	Start() error
	Stop() error
	ConnectCore(coreClient *Client, pingId string) error
	Configure(moduleFlags common.ModuleFlags) error
	CliCommand() *cli.Command // Returns the cli command for the service in order for MEV Plus to parse the flags
}

Service represents a service that meets the requirements of the MEV Plus application

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL