subscriber

package
Version: v0.0.0-...-c8a5385 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package subscriber holds logic to communicate between the external initiator service and the external endpoints it subscribes to.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event []byte

Event is the individual event that occurs during the subscription.

type IParser

type IParser interface {
	ParseResponse(data []byte) ([]Event, bool)
}

IParser holds the interface for parsing data from the external endpoint into an array of Events based on the blockchain's parser.

type ISubscriber

type ISubscriber interface {
	// SubscribeToEvents subscribes to events using the endpoint and configuration
	// as set in ISubscriber. All events will be sent in the channel. If anything is
	// passed as a param after channel, it will not expect to receive any confirmation
	// message after opening the initial subscription.
	SubscribeToEvents(channel chan<- Event, runtimeConfig store.RuntimeConfig) (ISubscription, error)
	// Test attempts to open a connection using the endpoint and configuration
	// as set in ISubscriber. If connection is succesful, it sends GetTestJson() as a payload
	// and attempts to parse response with ParseTestResponse().
	Test() error
}

ISubscriber holds the interface for interacting with a not-yet-active subscription.

type ISubscription

type ISubscription interface {
	// Unsubscribe closes the connection to the external endpoint
	// and stops any processes related to this subscription.
	Unsubscribe()
}

ISubscription holds the interface for interacting with an active subscription.

type JsonManager

type JsonManager interface {
	// Get JSON payload to send when opening a new subscription
	GetTriggerJson() []byte
	// Parse the response returned after sending GetTriggerJson()
	ParseResponse(data []byte) ([]Event, bool)
	// Get JSON payload to send when testing a connection
	GetTestJson() []byte
	// Parse the response returned after sending GetTestJson()
	ParseTestResponse(data []byte) error
}

JsonManager holds the interface for generating blockchain specific payloads and parsing the response for the appropriate blockchain.

type RpcSubscriber

type RpcSubscriber struct {
	Endpoint string
	Interval time.Duration
	Manager  JsonManager
}

RpcSubscriber holds the configuration for a not-yet-active RPC subscription.

func (RpcSubscriber) SubscribeToEvents

func (rpc RpcSubscriber) SubscribeToEvents(channel chan<- Event, _ store.RuntimeConfig) (ISubscription, error)

func (RpcSubscriber) Test

func (rpc RpcSubscriber) Test() error

Test sends a POST request using GetTestJson() as payload, and returns the error from calling ParseTestResponse() on the response.

type SubConfig

type SubConfig struct {
	Endpoint string
}

SubConfig holds the configuration required to connect to the external endpoint.

type Type

type Type int

Type holds the connection type for the subscription

const (
	// WS are connections made over WebSocket
	WS Type = iota
	// RPC are connections made by POSTing a JSON payload
	// to the external endpoint.
	RPC
	// Client are connections encapsulated in its
	// entirety by the blockchain implementation.
	Client
	// Unknown is just a placeholder for when
	// it cannot be determined how connections
	// should be made. When this is returned,
	// it should be considered an error.
	Unknown
)

type WebsocketSubscriber

type WebsocketSubscriber struct {
	Endpoint string
	Manager  JsonManager
}

WebsocketSubscriber holds the configuration for a not-yet-active WS subscription.

func (WebsocketSubscriber) SubscribeToEvents

func (wss WebsocketSubscriber) SubscribeToEvents(channel chan<- Event, _ store.RuntimeConfig) (ISubscription, error)

func (WebsocketSubscriber) Test

func (wss WebsocketSubscriber) Test() error

Test sends a opens a WS connection to the endpoint.

Jump to

Keyboard shortcuts

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