websocket

package
v1.10.8 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodSubscribe   = "subscribe"
	MethodUnsubscribe = "unsubscribe"
)

methods

View Source
const (
	ChannelHead     = "head"
	ChannelBlocks   = "blocks"
	ChannelGasPrice = "gas_price"
)

channels

Variables

View Source
var (
	ErrUnknownMethod     = errors.New("unknown method")
	ErrUnknownChannel    = errors.New("unknown channel")
	ErrUnavailableFilter = errors.New("unknown filter value")
)

Functions

This section is empty.

Types

type BlockFilter added in v1.4.0

type BlockFilter struct{}

func (BlockFilter) Filter added in v1.4.0

func (f BlockFilter) Filter(c client, msg Notification[*responses.Block]) bool

type Channel

type Channel[I any, M INotification] struct {
	// contains filtered or unexported fields
}

func NewChannel

func NewChannel[I any, M INotification](processor processor[I, M], filters Filterable[M]) *Channel[I, M]

func (*Channel[I, M]) AddClient

func (channel *Channel[I, M]) AddClient(c client)

func (*Channel[I, M]) RemoveClient

func (channel *Channel[I, M]) RemoveClient(id uint64)

type Client

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

func (*Client) ApplyFilters

func (c *Client) ApplyFilters(msg Subscribe) error

func (*Client) Close

func (c *Client) Close() error

func (*Client) DetachFilters

func (c *Client) DetachFilters(msg Unsubscribe) error

func (*Client) Filters

func (c *Client) Filters() *Filters

func (*Client) Id

func (c *Client) Id() uint64

func (*Client) Notify

func (c *Client) Notify(msg any)

func (*Client) ReadMessages

func (c *Client) ReadMessages(ctx context.Context, ws *websocket.Conn, log echo.Logger)

func (*Client) WriteMessages

func (c *Client) WriteMessages(ctx context.Context, ws *websocket.Conn, log echo.Logger)

type ClientHandler added in v1.9.9

type ClientHandler func(string, *Client)

type Filterable

type Filterable[M INotification] interface {
	Filter(c client, msg Notification[M]) bool
}

type Filters

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

type GasPriceFilter added in v1.9.10

type GasPriceFilter struct{}

func (GasPriceFilter) Filter added in v1.9.10

func (f GasPriceFilter) Filter(c client, msg Notification[*responses.GasPrice]) bool

type HeadFilter

type HeadFilter struct{}

func (HeadFilter) Filter

func (f HeadFilter) Filter(c client, msg Notification[*responses.State]) bool

type INotification added in v1.4.0

type INotification interface {
	*responses.Block | *responses.State | *responses.GasPrice
}

type Manager

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

func NewManager

func NewManager(observer *bus.Observer) *Manager

func (*Manager) AddClientToChannel

func (manager *Manager) AddClientToChannel(channel string, client *Client)

func (*Manager) Close

func (manager *Manager) Close() error

func (*Manager) GasTrackerHandler added in v1.9.10

func (manager *Manager) GasTrackerHandler(_ context.Context, state gas.GasPrice) error

func (*Manager) Handle

func (manager *Manager) Handle(c echo.Context) error

Handle godoc

@Summary				Websocket API
@Description.markdown	websocket
@Tags					websocket
@ID						websocket
@x-internal				true
@Produce				json
@Router					/ws [get]

func (*Manager) RemoveClientFromChannel

func (manager *Manager) RemoveClientFromChannel(channel string, client *Client)

func (*Manager) Start

func (manager *Manager) Start(ctx context.Context)

type Message

type Message struct {
	Method string          `json:"method" validate:"required,oneof=subscribe,unsubscribe"`
	Body   json.RawMessage `json:"body"   validate:"required"`
}

type Notification added in v1.4.0

type Notification[T INotification] struct {
	Channel string `json:"channel"`
	Body    T      `json:"body"`
}

func NewBlockNotification added in v1.4.0

func NewBlockNotification(block responses.Block) Notification[*responses.Block]

func NewGasPriceNotification added in v1.9.10

func NewGasPriceNotification(value responses.GasPrice) Notification[*responses.GasPrice]

func NewStateNotification added in v1.4.0

func NewStateNotification(state responses.State) Notification[*responses.State]

type Subscribe

type Subscribe struct {
	Channel string          `json:"channel" validate:"required,oneof=head tx"`
	Filters json.RawMessage `json:"filters" validate:"required"`
}

type TransactionFilters

type TransactionFilters struct {
	Status   []string `json:"status,omitempty"`
	Messages []string `json:"msg_type,omitempty"`
}

type Unsubscribe

type Unsubscribe struct {
	Channel string `json:"channel" validate:"required,oneof=head tx"`
}

Jump to

Keyboard shortcuts

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