wsdcrdata

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2024 License: ISC Imports: 8 Imported by: 0

Documentation

Overview

Package wsdcrdata provides a client for managing dcrdata websocket subscriptions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDuplicateSub is emitted when attempting to subscribe to an
	// event that has already been subscribed to.
	ErrDuplicateSub = errors.New("duplicate subscription")

	// ErrSubNotFound is emitted when attempting to unsubscribe to an
	// event that has not yet been subscribed to.
	ErrSubNotFound = errors.New("subscription not found")

	// ErrReconnecting is emitted when attempting to use the Client
	// while it is in the process of reconnecting to dcrdata. All
	// subscribe/unsubscribe actions that are attempted while the
	// client is reconnecting are recorded and completed once the new
	// connection has been made.
	ErrReconnecting = errors.New("reconnecting to dcrdata")

	// ErrShutdown is emitted when attempting to use the Client after
	// it has already been shut down.
	ErrShutdown = errors.New("client is shutdown")
)

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using slog.

Types

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Client is a dcrdata websocket client for managing dcrdata websocket subscriptions.

func New

func New(dcrdataURL string) (*Client, error)

New returns a new Client.

func (*Client) AddressSubscribe

func (c *Client) AddressSubscribe(address string) error

AddressSubscribe subscribes to events for the provided address.

func (*Client) AddressUnsubscribe

func (c *Client) AddressUnsubscribe(address string) error

AddressUnsubscribe unsubscribes from events for the provided address.

func (*Client) Close

func (c *Client) Close() error

Close closes the dcrdata websocket client.

func (*Client) NewBlockSubscribe

func (c *Client) NewBlockSubscribe() error

NewBlockSubscribe subscibes to the new block event.

func (*Client) NewBlockUnsubscribe

func (c *Client) NewBlockUnsubscribe() error

NewBlockUnsubscribe unsubscibes from the new block event.

func (*Client) Receive

func (c *Client) Receive() <-chan *psclient.ClientMessage

Receive returns a new channel that receives websocket messages from the dcrdata server.

func (*Client) Reconnect

func (c *Client) Reconnect()

Reconnect creates a new websocket client and subscribes to the same subscriptions as the previous client. If a connection cannot be established, this function will continue to episodically attempt to reconnect until either a connection is made or the application is shut down. If any new subscribe/unsubscribe events are registered during this reconnection process, they are added to a pending events list and are replayed in the order in which they are received once a new connection has been established.

func (*Client) Status

func (c *Client) Status() StatusT

Status returns the websocket status.

type StatusT

type StatusT int
const (
	// Websocket statuses
	StatusInvalid      StatusT = 0 // Invalid status
	StatusOpen         StatusT = 1 // Websocket is open
	StatusReconnecting StatusT = 2 // Websocket is attempting to reconnect
	StatusShutdown     StatusT = 3 // Websocket client has been shutdown

)

Jump to

Keyboard shortcuts

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