monitor

package
v0.0.0-...-3f8eaf4 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: GPL-3.0 Imports: 26 Imported by: 1

Documentation

Overview

Package monitor provides access to monitored addresses

Index

Constants

View Source
const (
	Ext = ".mon.bin"
)

Variables

This section is empty.

Functions

func ListMonitors

func ListMonitors(chain, watchList string, monitorChan chan<- Monitor)

ListMonitors puts a list of Monitors into the monitorChannel. The list of monitors is built from a file called addresses.tsv in the current folder or, if not present, from existing monitors

Types

type Header struct {
	Magic       uint16 `json:"-"`
	Unused      bool   `json:"-"`
	Deleted     bool   `json:"deleted,omitempty"`
	LastScanned uint32 `json:"lastScanned,omitempty"`
}

Header is the header of the Monitor file. Note that it's the same width as an index.AppearanceRecord therefor one should not change its size

type Monitor

type Monitor struct {
	Address base.Address `json:"address"`
	Staged  bool         `json:"-"`
	Chain   string       `json:"-"`
	ReadFp  *os.File     `json:"-"`
	Header
}

Monitor carries information about a Monitor file and its header

func GetMonitorMap

func GetMonitorMap(chain string) (map[base.Address]*Monitor, []*Monitor)

func NewMonitor

func NewMonitor(chain string, addr base.Address, create bool) (Monitor, error)

NewMonitor returns a Monitor (but has not yet read in the AppearanceRecords). If 'create' is sent, create the Monitor if it does not already exist

func NewMonitorStaged

func NewMonitorStaged(chain, addr string) (Monitor, error)

NewMonitorStaged returns a Monitor whose path is in the 'staging' folder

func (*Monitor) Close

func (mon *Monitor) Close()

Close closes an open Monitor if it's open, does nothing otherwise

func (*Monitor) Count

func (mon *Monitor) Count() int64

func (*Monitor) Delete

func (mon *Monitor) Delete() (prev bool)

Delete marks the file's delete flag, but does not physically remove the file

func (*Monitor) IsDeleted

func (mon *Monitor) IsDeleted() bool

IsDeleted returns true if the monitor has been deleted but not removed

func (*Monitor) IsOpen

func (mon *Monitor) IsOpen() bool

IsOpen returns true if the underlying monitor file is opened.

func (*Monitor) MoveToProduction

func (mon *Monitor) MoveToProduction() error

MoveToProduction moves a previously staged monitor to the monitors folder.

func (*Monitor) Path

func (mon *Monitor) Path() (path string)

Path returns the path to the Monitor file

func (*Monitor) ReadAndFilterAppearances

func (mon *Monitor) ReadAndFilterAppearances(filt *filter.AppearanceFilter, withCount bool) (apps []types.SimpleAppearance, cnt int, err error)

func (*Monitor) ReadAppearanceAt

func (mon *Monitor) ReadAppearanceAt(idx int64, app *index.AppearanceRecord) (err error)

ReadAppearanceAt returns the appearance at the one-based index. The file remains open.

func (*Monitor) ReadMonitorHeader

func (mon *Monitor) ReadMonitorHeader() (err error)

ReadMonitorHeader reads the monitor's header and returns without closing the file

func (*Monitor) Reload

func (mon *Monitor) Reload(create bool) (int64, error)

Reload loads information about the monitor such as the file's size and record count

func (*Monitor) Remove

func (mon *Monitor) Remove() (bool, error)

Remove removes a previously deleted file, does nothing if the file is not deleted

func (*Monitor) RemoveDups

func (mon *Monitor) RemoveDups() (int64, int64, error)

func (Monitor) String

func (mon Monitor) String() string

func (*Monitor) TruncateTo

func (mon *Monitor) TruncateTo(chain string, num uint32) (bool, error)

func (*Monitor) UnDelete

func (mon *Monitor) UnDelete() (prev bool)

UnDelete unmarks the file's delete flag

func (*Monitor) WriteAppearances

func (mon *Monitor) WriteAppearances(apps []index.AppearanceRecord, append bool) (int64, error)

WriteAppearances writes appearances to a Monitor

func (*Monitor) WriteAppearancesAppend

func (mon *Monitor) WriteAppearancesAppend(lastScanned uint32, apps *[]index.AppearanceRecord) error

WriteAppearancesAppend appends appearances to the end of the file, updates the header with lastScanned (if later) and returns the number of records written. Note that we should be writing to a temporary file.

func (*Monitor) WriteMonHeader

func (mon *Monitor) WriteMonHeader(deleted bool, lastScanned uint32, force bool) (err error)

WriteMonHeader writes the monitor's header

type MonitorUpdate

type MonitorUpdate struct {
	MaxTasks      int
	MonitorMap    map[base.Address]*Monitor
	Chain         string
	PublisherAddr base.Address
	TestMode      bool
	Silent        bool
	FirstBlock    uint64
	Addrs         []string
}

MonitorUpdate stores the original 'chifra list' command line options plus

func NewUpdater

func NewUpdater(chain string, testMode, silent bool, addrs []string) MonitorUpdate

func (*MonitorUpdate) FreshenMonitors

func (updater *MonitorUpdate) FreshenMonitors(monitorArray *[]Monitor) (bool, error)

Jump to

Keyboard shortcuts

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