Documentation ¶
Index ¶
- Variables
- type Event
- type MinuteResponse
- type Monitor
- func (m *Monitor) FactomdRequest(ctx context.Context) (*MinuteResponse, error)
- func (m *Monitor) GetCurrentMinute() (int64, int64, int64)
- func (m *Monitor) NewDBHeightListener() <-chan int64
- func (m *Monitor) NewErrorListener() <-chan error
- func (m *Monitor) NewHeightListener() <-chan int64
- func (m *Monitor) NewMinuteListener() <-chan Event
- func (m *Monitor) Stop()
Constants ¶
This section is empty.
Variables ¶
var Interval time.Duration = time.Second
Interval specifies the minimum time spent between API requests
var Timeout time.Duration = time.Second * 5
Timeout specifies the maximum time an API request can take
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct { // The most recent block saved in the node's database DBHeight int64 // The most recently completed block in the network Height int64 // The minute the network is currently working on Minute int64 }
Event contains the data sent to minute listeners.
type MinuteResponse ¶
type MinuteResponse struct { DBHeight int64 `json:"directoryblockheight"` LeaderHeight int64 `json:"leaderheight"` Minute int64 `json:"minute"` DBlockSeconds int64 `json:"directoryblockinseconds"` }
MinuteResponse is a struct formed after the response from the factomd API. Only contains relevant information. See: https://github.com/FactomProject/factomd/blob/0ff77090ab055d4c069612ca1a6814bde88155ab/wsapi/wsapiStructs.go#L68-L79
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor is responsible for polling the factom node and managing listeners
func NewMonitor ¶
NewMonitor creates a new monitor that begins polling the provided url immediately. If the initial request does not work, an error is returned. Starts a goroutine that can be stopped via monitor.Stop().
func (*Monitor) FactomdRequest ¶
func (m *Monitor) FactomdRequest(ctx context.Context) (*MinuteResponse, error)
FactomdRequest sends a "current-minute" API request to the configured node.
func (*Monitor) GetCurrentMinute ¶
GetCurrentMinute returns the most recent Height and Minute the monitor has received
func (*Monitor) NewDBHeightListener ¶
NewDBHeightListener spawns a new listener that receives events every time a new DBHeight is attained. Each reader must have its own listener.
func (*Monitor) NewErrorListener ¶
NewErrorListener spawns a new listener that receives error events from malfunctioning API requests. Single errors are usually recoverable and the monitor will continue to poll. A high frequency of errors means the monitor is unable to reach the node. Each reader must have its own listener.
func (*Monitor) NewHeightListener ¶
NewHeightListener spawns a new listener that receives events every time a new height is attained. Each reader must have its own listener.
func (*Monitor) NewMinuteListener ¶
NewMinuteListener spawns a new listener that receives events for every minute. Each reader must have its own listener.