server

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package server provides the server implementation.

Index

Constants

View Source
const BlockHeaders = "block:headers"

BlockHeaders is the channel name for block headers.

View Source
const BlockSync = "block:sync:"

BlockSync is the channel name for block sync.

View Source
const Filter = "filter"

Filter is the verb for filtering.

View Source
const MempoolTransactions = "mempool:transactions"

MempoolTransactions is the channel name for mempool transactions.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockHeadersChannel

type BlockHeadersChannel struct {
	Client *centrifuge.Client
	Node   *centrifuge.Node
}

BlockHeadersChannel is the channel for block headers.

func (*BlockHeadersChannel) ProcessPublish

func (c *BlockHeadersChannel) ProcessPublish(_ centrifuge.PublishEvent) ([]byte, error)

ProcessPublish is called when a client publishes to this channel.

func (*BlockHeadersChannel) ProcessSubscribe

func (c *BlockHeadersChannel) ProcessSubscribe(_ centrifuge.SubscribeEvent) ([]byte, error)

ProcessSubscribe is called when a client subscribes to this channel.

type BlockSyncChannel

type BlockSyncChannel struct {
	Client    *centrifuge.Client
	Processor chainstate.MonitorProcessor
	Node      *centrifuge.Node
}

BlockSyncChannel is the channel for block sync.

func (*BlockSyncChannel) ProcessPublish

func (c *BlockSyncChannel) ProcessPublish(e centrifuge.PublishEvent) ([]byte, error)

ProcessPublish is called when a client publishes to this channel.

func (*BlockSyncChannel) ProcessSubscribe

func (c *BlockSyncChannel) ProcessSubscribe(e centrifuge.SubscribeEvent) ([]byte, error)

ProcessSubscribe is called when a client subscribes to this channel.

type BlockSyncSubscriber

type BlockSyncSubscriber struct {
	Channel      string    `json:"channel"`
	From         string    `json:"from"`
	To           string    `json:"to"`
	Transactions []node.Tx `json:"transactions"`
	Block        *node.Block
	Synced       bool `json:"synced"`
	Processor    chainstate.MonitorProcessor
	Node         *centrifuge.Node
}

BlockSyncSubscriber is the subscriber for block sync.

func (*BlockSyncSubscriber) GetTransactions

func (b *BlockSyncSubscriber) GetTransactions() ([]node.Tx, error)

GetTransactions returns the transactions.

func (*BlockSyncSubscriber) Publish

func (b *BlockSyncSubscriber) Publish(data []byte) error

Publish publishes the block to the centrifuge node.

func (*BlockSyncSubscriber) Subscribe

func (b *BlockSyncSubscriber) Subscribe() error

Subscribe subscribes to the block sync channel.

type Channel

type Channel interface {
	ProcessPublish(e centrifuge.PublishEvent) ([]byte, error)
	ProcessSubscribe(e centrifuge.SubscribeEvent) ([]byte, error)
}

Channel is an interface that must be implemented by all channels.

type ConnectedClient

type ConnectedClient struct {
	LastSeen int64  `json:"last_seen"`
	ID       string `json:"id"`
}

ConnectedClient is a client that is connected to the server.

type FilterChannel

type FilterChannel struct {
	Client    *centrifuge.Client
	Processor chainstate.MonitorProcessor
	Node      *centrifuge.Node
}

FilterChannel is the channel for filters.

func (*FilterChannel) ProcessPublish

func (c *FilterChannel) ProcessPublish(e centrifuge.PublishEvent) ([]byte, error)

ProcessPublish is called when a client publishes to this channel.

func (*FilterChannel) ProcessSubscribe

func (c *FilterChannel) ProcessSubscribe(e centrifuge.SubscribeEvent) ([]byte, error)

ProcessSubscribe is called when a client subscribes to this channel.

type MempoolTransactionsChannel

type MempoolTransactionsChannel struct {
	Client *centrifuge.Client
	Node   *centrifuge.Node
}

MempoolTransactionsChannel is the channel for mempool transactions.

func (*MempoolTransactionsChannel) ProcessPublish

func (c *MempoolTransactionsChannel) ProcessPublish(_ centrifuge.PublishEvent) ([]byte, error)

ProcessPublish is called when a client publishes to this channel.

func (*MempoolTransactionsChannel) ProcessSubscribe

func (c *MempoolTransactionsChannel) ProcessSubscribe(_ centrifuge.SubscribeEvent) ([]byte, error)

ProcessSubscribe is called when a client subscribes to this channel.

type ProcessorNode

type ProcessorNode struct {
	Processor chainstate.MonitorProcessor
	Node      *centrifuge.Node
}

ProcessorNode is the struct that wraps the centrifuge node and the processor.

type Server

type Server struct {
	Node               *centrifuge.Node
	Client             *centrifuge.Client
	Processor          chainstate.MonitorProcessor
	ClientMap          map[string]*ConnectedClient
	MempoolClient      *centrifugeClient.Client
	BlockHeadersClient *centrifugeClient.Client
}

Server represents a server.

func (*Server) GetChannel

func (s *Server) GetChannel(client *centrifuge.Client, channelName string) Channel

GetChannel returns the channel for the given channel name.

func (*Server) Start

func (s *Server) Start(cfg *config.Config)

Start starts the server.

func (*Server) StartBlockHeadersListener

func (s *Server) StartBlockHeadersListener() error

StartBlockHeadersListener starts the block headers listener

func (*Server) StartMempoolListener

func (s *Server) StartMempoolListener() error

StartMempoolListener starts the mempool listener

func (*Server) StopBlockHeadersListener

func (s *Server) StopBlockHeadersListener() error

StopBlockHeadersListener stops the block headers listener

func (*Server) StopMempoolListener

func (s *Server) StopMempoolListener() error

StopMempoolListener stops the mempool listener

type Subscriber

type Subscriber interface {
	Subscribe() error
	Publish() error
	GetTransactions() ([]string, error)
}

Subscriber is the interface that wraps the Subscribe and Publish methods.

Jump to

Keyboard shortcuts

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