Documentation ¶
Index ¶
- func SetupHeartbeat(ctx context.Context) (*ethrpc.Subscription, error)
- type AddOrdersOpts
- type Client
- func (c *Client) AddOrders(orders []*zeroex.SignedOrder, opts ...AddOrdersOpts) (*ordervalidator.ValidationResults, error)
- func (c *Client) AddPeer(peerInfo peerstore.PeerInfo) error
- func (c *Client) GetOrders(page, perPage int, snapshotID string) (*GetOrdersResponse, error)
- func (c *Client) GetStats() (*GetStatsResponse, error)
- func (c *Client) SubscribeToHeartbeat(ctx context.Context, ch chan<- string) (*rpc.ClientSubscription, error)
- func (c *Client) SubscribeToOrders(ctx context.Context, ch chan<- []*zeroex.OrderEvent) (*rpc.ClientSubscription, error)
- type GetOrdersResponse
- type GetStatsResponse
- type LatestBlock
- type OrderInfo
- type RPCHandler
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetupHeartbeat ¶
func SetupHeartbeat(ctx context.Context) (*ethrpc.Subscription, error)
SetupHeartbeat sets up the heartbeat for a subscription
Types ¶
type AddOrdersOpts ¶
type AddOrdersOpts struct { // Pinned determines whether or not the added orders should be pinned. Pinned // orders will not be affected by any DDoS prevention or incentive mechanisms // and will always stay in storage until they are no longer fillable. Defaults // to true. Pinned bool `json:"pinned"` }
AddOrdersOpts is a set of options for the AddOrders RPC method.
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 ¶
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 ...AddOrdersOpts) (*ordervalidator.ValidationResults, error)
AddOrders adds orders to the 0x Mesh node and broadcasts them throughout the 0x Mesh network.
func (*Client) AddPeer ¶
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) (*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() (*GetStatsResponse, 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. Note copied from `go-ethereum` codebase: 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 Note copied from `go-ethereum` codebase: 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 GetOrdersResponse ¶
type GetOrdersResponse struct { SnapshotID string `json:"snapshotID"` SnapshotTimestamp time.Time `json:"snapshotTimestamp"` OrdersInfos []*OrderInfo `json:"ordersInfos"` }
GetOrdersResponse is the response returned for an RPC request to mesh_getOrders
type GetStatsResponse ¶
type GetStatsResponse struct { Version string `json:"version"` PubSubTopic string `json:"pubSubTopic"` Rendezvous string `json:"rendervous"` PeerID string `json:"peerID"` EthereumChainID int `json:"ethereumChainID"` LatestBlock LatestBlock `json:"latestBlock"` NumPeers int `json:"numPeers"` NumOrders int `json:"numOrders"` NumOrdersIncludingRemoved int `json:"numOrdersIncludingRemoved"` NumPinnedOrders int `json:"numPinnedOrders"` MaxExpirationTime string `json:"maxExpirationTime"` StartOfCurrentUTCDay time.Time `json:"startOfCurrentUTCDay"` EthRPCRequestsSentInCurrentUTCDay int `json:"ethRPCRequestsSentInCurrentUTCDay"` EthRPCRateLimitExpiredRequests int64 `json:"ethRPCRateLimitExpiredRequests"` }
GetStatsResponse is the response returned for an RPC request to mesh_getStats
type LatestBlock ¶
LatestBlock is the latest block processed by the Mesh node
type OrderInfo ¶
type OrderInfo struct { OrderHash common.Hash `json:"orderHash"` SignedOrder *zeroex.SignedOrder `json:"signedOrder"` FillableTakerAssetAmount *big.Int `json:"fillableTakerAssetAmount"` }
OrderInfo represents an fillable order and how much it could be filled for
func (OrderInfo) MarshalJSON ¶
MarshalJSON is a custom Marshaler for OrderInfo
func (*OrderInfo) UnmarshalJSON ¶
UnmarshalJSON implements a custom JSON unmarshaller for the OrderEvent type
type RPCHandler ¶
type RPCHandler interface { // AddOrders is called when the client sends an AddOrders request. AddOrders(signedOrdersRaw []*json.RawMessage, opts AddOrdersOpts) (*ordervalidator.ValidationResults, error) // GetOrders is called when the clients sends a GetOrders request GetOrders(page, perPage int, snapshotID string) (*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() (*GetStatsResponse, 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 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.