jsonrpc

package
v4.14.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RPCClient

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

RPCClient is a generic json rpc client, which is able to invoke remote methods and subscribe to remote notifications.

func NewRPCClient

func NewRPCClient(backends []rpc.Backend, onError func(error), log *logrus.Entry) *RPCClient

NewRPCClient creates a new RPCClient. conn is used for transport (e.g. a tcp/tls connection). onError is called for unexpected errors like malformed server responses.

func (*RPCClient) Close

func (client *RPCClient) Close()

Close shuts down the connection.

func (*RPCClient) ConnectionStatus

func (client *RPCClient) ConnectionStatus() rpc.Status

ConnectionStatus returns the current connection status of this client to the backend(s).

func (*RPCClient) IsClosed

func (client *RPCClient) IsClosed() bool

IsClosed returns true if the client is closed and false otherwise.

func (*RPCClient) Method

func (client *RPCClient) Method(
	success func([]byte) error,
	setupAndTeardown func() func(error),
	method string,
	params ...interface{},
)

Method sends invokes the remote method with the provided parameters. Before the request is send, the setupAndTeardown callback is executed and the return value is stored as cleanup callback with the pending request. The success callback is called with the response. cleanup is called afterwards.

func (*RPCClient) MethodSync

func (client *RPCClient) MethodSync(response interface{}, method string, params ...interface{}) error

MethodSync is the same as method, but blocks until the response is available. The result is json-deserialized into response.

func (*RPCClient) OnConnect

func (client *RPCClient) OnConnect(callback func() error)

OnConnect executed the given callback whenever a new connection is established

func (*RPCClient) RegisterHeartbeat

func (client *RPCClient) RegisterHeartbeat(
	method string,
	params ...interface{},
)

RegisterHeartbeat registers the heartbeat method and parameters that are sent to the backend to keep the connection alive

func (*RPCClient) RegisterOnConnectionStatusChangedEvent

func (client *RPCClient) RegisterOnConnectionStatusChangedEvent(onConnectionStatusChangedEvent func(rpc.Status))

RegisterOnConnectionStatusChangedEvent registers an event that is fired if the connection status changes. After registration it fires the event to notify the holder of the callback about the current status. TODO: eventually return a de-register method that deletes the callback. Will be required once we allow the user to manage their accounts fully.

func (*RPCClient) SubscribeNotifications

func (client *RPCClient) SubscribeNotifications(method string, callback func([]byte))

SubscribeNotifications installs a callback for a method which is called with notifications from the server.

type ResponseError

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

ResponseError indicates an error when parsing the response from the server.

func (*ResponseError) Error

func (err *ResponseError) Error() string

type SocketError

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

SocketError indicates an error when reading from or writing to a network socket.

func (*SocketError) Error

func (err *SocketError) Error() string

Jump to

Keyboard shortcuts

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