rpc

package
v0.0.0-...-0b85bb3 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupHeartbeat

func SetupHeartbeat(ctx context.Context) (*rpc.Subscription, error)

SetupHeartbeat sets up the heartbeat for a subscription

Types

type Client

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

Client is a JSON RPC 2.0 client implementation over WebSockets. It can be used to communicate with a 0x Mesh node and add orders.

func NewClient

func NewClient(addr string) (*Client, error)

NewClient creates and returns a new client. addr is the address of the server (i.e. a 0x Mesh node) to dial.

func (*Client) AddOrders

func (c *Client) AddOrders(orders []*zeroex.SignedOrder, opts ...types.AddOrdersOpts) (*ordervalidator.ValidationResults, error)

AddOrders adds orders to the 0x Mesh node and broadcasts them throughout the 0x Mesh network.

func (*Client) AddPeer

func (c *Client) AddPeer(peerInfo peerstore.PeerInfo) error

AddPeer adds the peer to the node's list of peers. The node will attempt to connect to this new peer and return an error if it cannot.

func (*Client) GetOrders

func (c *Client) GetOrders(page, perPage int, snapshotID string) (*types.GetOrdersResponse, error)

GetOrders gets all orders stored on the Mesh node at a particular point in time in a paginated fashion

func (*Client) GetStats

func (c *Client) GetStats() (*types.Stats, error)

GetStats retrieves stats about the Mesh node

func (*Client) SubscribeToHeartbeat

func (c *Client) SubscribeToHeartbeat(ctx context.Context, ch chan<- string) (*rpc.ClientSubscription, error)

SubscribeToHeartbeat subscribes a stream of heartbeats in order to have certainty that the WS connection is still alive.

Slow subscribers will be dropped eventually. Client buffers up to 8000 notifications before considering the subscriber dead. The subscription Err channel will receive ErrSubscriptionQueueOverflow. Use a sufficiently large buffer on the channel or ensure that the channel usually has at least one reader to prevent this issue.

func (*Client) SubscribeToOrders

func (c *Client) SubscribeToOrders(ctx context.Context, ch chan<- []*zeroex.OrderEvent) (*rpc.ClientSubscription, error)

SubscribeToOrders subscribes a stream of order events

Slow subscribers will be dropped eventually. Client buffers up to 8000 notifications before considering the subscriber dead. The subscription Err channel will receive ErrSubscriptionQueueOverflow. Use a sufficiently large buffer on the channel or ensure that the channel usually has at least one reader to prevent this issue.

type HandlerType

type HandlerType uint8

HandlerType represents the type of handler to attach to the server

const (
	HTTPHandler HandlerType = iota
	WSHandler
)

HandlerType values

type RPCHandler

type RPCHandler interface {
	// AddOrders is called when the client sends an AddOrders request.
	AddOrders(signedOrdersRaw []*json.RawMessage, opts types.AddOrdersOpts) (*ordervalidator.ValidationResults, error)
	// GetOrders is called when the clients sends a GetOrders request
	GetOrders(page, perPage int, snapshotID string) (*types.GetOrdersResponse, error)
	// AddPeer is called when the client sends an AddPeer request.
	AddPeer(peerInfo peerstore.PeerInfo) error
	// GetStats is called when the client sends an GetStats request.
	GetStats() (*types.Stats, error)
	// SubscribeToOrders is called when a client sends a Subscribe to `orders` request
	SubscribeToOrders(ctx context.Context) (*rpc.Subscription, error)
}

RPCHandler is used to respond to incoming requests from the client.

type RPCService

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

RPCService is an /klaytn/klaytn/networks/rpc compatible service.

func (*RPCService) AddOrders

func (s *RPCService) AddOrders(signedOrdersRaw []*json.RawMessage, opts *types.AddOrdersOpts) (*ordervalidator.ValidationResults, error)

AddOrders calls rpcHandler.AddOrders and returns the validation results.

func (*RPCService) AddPeer

func (s *RPCService) AddPeer(peerID string, multiaddrs []string) error

AddPeer builds PeerInfo out of the given peer ID and multiaddresses and calls rpcHandler.AddPeer. If there is an error, it returns it.

func (*RPCService) GetOrders

func (s *RPCService) GetOrders(page, perPage int, snapshotID string) (*types.GetOrdersResponse, error)

GetOrders calls rpcHandler.GetOrders and returns the validation results.

func (*RPCService) GetStats

func (s *RPCService) GetStats() (*types.Stats, error)

GetStats calls rpcHandler.GetStats. If there is an error, it returns it.

func (*RPCService) Heartbeat

func (s *RPCService) Heartbeat(ctx context.Context) (*rpc.Subscription, error)

Heartbeat calls rpcHandler.SubscribeToHeartbeat and returns the rpc subscription.

func (*RPCService) Orders

func (s *RPCService) Orders(ctx context.Context) (*rpc.Subscription, error)

Orders calls rpcHandler.SubscribeToOrders and returns the rpc subscription.

type Server

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

Server is a JSON RPC 2.0 server implementation over WebSockets. It accepts requests from a client for adding orders to the 0x Mesh network.

func NewServer

func NewServer(addr string, rpcHandler RPCHandler) (*Server, error)

NewServer creates and returns a new server which will listen for new connections on the given addr and use the rpcHandler to handle incoming requests.

func (*Server) Addr

func (s *Server) Addr() net.Addr

Addr returns the address the server is listening on or nil if it has not yet started listening.

func (*Server) Listen

func (s *Server) Listen(ctx context.Context, handlerType HandlerType) error

Listen causes the server to listen for new WS connections. You can call Close to stop listening. Listen blocks until there is an error or the given context is canceled.

Jump to

Keyboard shortcuts

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