monitorsPkg

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: 28 Imported by: 0

README

chifra monitors

chifra monitors has two purposes: (1) to display information about the current set of monitors, and (2) to --watch a set of addresses. The --watch function allows one to "follow" an address (or set of addresses) and keep an off-chain database fresh.

Crud commands

chifra list creates a new monitor. See that tool's help file for more information.

The chifra monitors --delete command deletes (or --undelete if already deleted) an address but does not remove it from your hard drive. The monitor is marked as being deleted, making it invisible to other tools.

Use the --remove command to permanently remove a monitor from your computer. This is an irreversible operation and requires the monitor to have been previously deleted.

The --decache option will remove not only the monitor but all of the cached data associated with the monitor (for example, transactions or traces). This is an irreversible operation (except for the fact that the cache can be easily re-created with chifra list <address>). The monitor need not have been previously deleted.

Watching addresses

The --watch command is special. It starts a long-running process that continually reads the blockchain looking for appearances of the addresses it is instructed to watch. It command requires two additional parameters: --watchlist <filename> and --commands <filename>. The --watchlist file is simply a list of addresses or ENS names, one per line:

0x5e349eca2dc61abcd9dd99ce94d04136151a09ee
trueblocks.eth
0x855b26bc8ebabcdbefe82ee5e9d40d20a1a4c11f
etc.

You may monitor as many addresses as you wish, however, if the commands you specify take longer than the --sleep amount you specify (14 seconds by default), the results are undefined. (Adjust --sleep if necessary.)

The --commands file may contain a list of any valid chifra command that operates on addresses. (Currently export, list, state, tokens.) Each command in the --commands file is executed once for each address in the --watchlist file. The --commands file may contain any number of commands, one per line with the above proviso. For example:

chifra list [{ADDRESS}]
chifra export --logs [{ADDRESS}]
etc.

The [{ADDRESS}] token is a stand-in for all addresses in the --watchlist. Addresses are processed in groups of batch_size (default 8).

Invalid commands or invalid addresses are ignored. If a command fails, the process continues with the next command. If a command fails for a particular address, the process continues with the next address. A warning is generated.

Purpose:
  Add, remove, clean, and list address monitors.

Usage:
  chifra monitors [flags] <address> [address...]

Arguments:
  addrs - one or more addresses (0x...) to process

Flags:
      --delete             delete a monitor, but do not remove it
      --undelete           undelete a previously deleted monitor
      --remove             remove a previously deleted monitor
  -C, --clean              clean (i.e. remove duplicate appearances) from monitors
  -l, --list               list monitors in the cache (--verbose for more detail)
  -w, --watch              continually scan for new blocks and extract data as per the command file
  -a, --watchlist string   available with --watch option only, a file containing the addresses to watch
  -c, --commands string    available with --watch option only, the file containing the list of commands to apply to each watched address
  -b, --batch_size uint    available with --watch option only, the number of monitors to process in each batch (default 8)
  -s, --sleep float        available with --watch option only, the number of seconds to sleep between runs (default 14)
  -D, --decache            removes related items from the cache
  -x, --fmt string         export format, one of [none|json*|txt|csv]
  -v, --verbose            enable verbose output
  -h, --help               display this help screen

Notes:
  - An address must be either an ENS name or start with '0x' and be forty-two characters long.
  - If no address is presented to the --clean command, all existing monitors will be cleaned.
  - The --watch option requires two additional parameters to be specified: --watchlist and --commands.
  - Addresses provided on the command line are ignored in --watch mode.
  - Providing the value existing to the --watchlist monitors all existing monitor files (see --list).

Data models produced by this tool:

Other Options

All tools accept the following additional flags, although in some cases, they have no meaning.

  -v, --version         display the current version of the tool
      --output string   write the results to file 'fn' and return the filename
      --append          for --output command only append to instead of replace contents of file
      --file string     specify multiple sets of command line options in a file

Note: For the --file string option, you may place a series of valid command lines in a file using any valid flags. In some cases, this may significantly improve performance. A semi-colon at the start of any line makes it a comment.

Note: If you use --output --append option and at the same time the --file option, you may not switch export formats in the command file. For example, a command file with two different commands, one with --fmt csv and the other with --fmt json will produce both invalid CSV and invalid JSON.

Documentation

Overview

Package monitorsPkg handles the chifra monitors command. It has two purposes: (1) to display information about the current set of monitors, and (2) to --watch a set of addresses. The --watch function allows one to "follow" an address (or set of addresses) and keep an off-chain database fresh. ### Crud commands chifra list creates a new monitor. See that tool's help file for more information. The chifra monitors --delete command deletes (or --undelete if already deleted) an address but does not remove it from your hard drive. The monitor is marked as being deleted, making it invisible to other tools. Use the --remove command to permanently remove a monitor from your computer. This is an irreversible operation and requires the monitor to have been previously deleted. The --decache option will remove not only the monitor but all of the cached data associated with the monitor (for example, transactions or traces). This is an irreversible operation (except for the fact that the cache can be easily re-created with chifra list <address>). The monitor need not have been previously deleted. ### Watching addresses The --watch command is special. It starts a long-running process that continually reads the blockchain looking for appearances of the addresses it is instructed to watch. It command requires two additional parameters: --watchlist <filename> and --commands <filename>. The --watchlist file is simply a list of addresses or ENS names, one per line: chifra export --logs etc. The token is a stand-in for all addresses in the --watchlist. Addresses are processed in groups of batch_size (default 8). Invalid commands or invalid addresses are ignored. If a command fails, the process continues with the next command. If a command fails for a particular address, the process continues with the next address. A warning is generated.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExportFormat

func GetExportFormat(cmd, def string) string

func ResetOptions

func ResetOptions(testMode bool)

func RunMonitors

func RunMonitors(cmd *cobra.Command, args []string) error

RunMonitors handles the monitors command for the command line. Returns error only as per cobra.

func ServeMonitors

func ServeMonitors(w http.ResponseWriter, r *http.Request) error

ServeMonitors handles the monitors command for the API. Returns an error.

Types

type Command

type Command struct {
	Fmt    string `json:"fmt"`
	Folder string `json:"folder"`
	Cmd    string `json:"cmd"`
	Cache  bool   `json:"cache"`
}

func (*Command) String

func (c *Command) String() string

type MonitorsOptions

type MonitorsOptions struct {
	Addrs     []string              `json:"addrs,omitempty"`     // One or more addresses (0x...) to process
	Delete    bool                  `json:"delete,omitempty"`    // Delete a monitor, but do not remove it
	Undelete  bool                  `json:"undelete,omitempty"`  // Undelete a previously deleted monitor
	Remove    bool                  `json:"remove,omitempty"`    // Remove a previously deleted monitor
	Clean     bool                  `json:"clean,omitempty"`     // Clean (i.e. remove duplicate appearances) from monitors
	List      bool                  `json:"list,omitempty"`      // List monitors in the cache (--verbose for more detail)
	Watch     bool                  `json:"watch,omitempty"`     // Continually scan for new blocks and extract data as per the command file
	Watchlist string                `json:"watchlist,omitempty"` // Available with --watch option only, a file containing the addresses to watch
	Commands  string                `json:"commands,omitempty"`  // Available with --watch option only, the file containing the list of commands to apply to each watched address
	BatchSize uint64                `json:"batchSize,omitempty"` // Available with --watch option only, the number of monitors to process in each batch
	RunCount  uint64                `json:"runCount,omitempty"`  // Available with --watch option only, run the monitor this many times, then quit
	Sleep     float64               `json:"sleep,omitempty"`     // Available with --watch option only, the number of seconds to sleep between runs
	Globals   globals.GlobalOptions `json:"globals,omitempty"`   // The global options
	Conn      *rpc.Connection       `json:"conn,omitempty"`      // The connection to the RPC server
	BadFlag   error                 `json:"badFlag,omitempty"`   // An error flag if needed

}

MonitorsOptions provides all command options for the chifra monitors command.

func GetMonitorsOptions

func GetMonitorsOptions(args []string, g *globals.GlobalOptions) *MonitorsOptions

GetMonitorsOptions returns the options for this tool so other tools may use it.

func GetOptions

func GetOptions() *MonitorsOptions

func (*MonitorsOptions) FreshenMonitorsForWatch

func (opts *MonitorsOptions) FreshenMonitorsForWatch(addrs []base.Address) (bool, error)

func (*MonitorsOptions) HandleClean

func (opts *MonitorsOptions) HandleClean() error

HandleClean handles the chifra monitors --clean command.

func (*MonitorsOptions) HandleCrudCommands

func (opts *MonitorsOptions) HandleCrudCommands() error

HandleCrudCommands handles the chifra monitors delete, undelete, remove and decache commands.

[State] | Delete | Undelete | Remove | ------------|--------|-------------------| Not Deleted | Delete | Error | Error | Deleted | Error | Undelete | Remove | ------------|--------|-------------------|

func (*MonitorsOptions) HandleDecache

func (opts *MonitorsOptions) HandleDecache() error

func (*MonitorsOptions) HandleList

func (opts *MonitorsOptions) HandleList() error

HandleList handles the chifra monitors --list command.

func (*MonitorsOptions) HandleWatch

func (opts *MonitorsOptions) HandleWatch() error

HandleWatch starts the monitor watcher

func (*MonitorsOptions) MonitorsInternal

func (opts *MonitorsOptions) MonitorsInternal() error

MonitorsInternal handles the internal workings of the monitors command. Returns an error.

func (*MonitorsOptions) Refresh

func (opts *MonitorsOptions) Refresh(monitors []monitor.Monitor) (bool, error)

func (*MonitorsOptions) RunMonitorScraper

func (opts *MonitorsOptions) RunMonitorScraper(wg *sync.WaitGroup, s *Scraper)

RunMonitorScraper runs continually, never stopping and freshens any existing monitors

func (*MonitorsOptions) String

func (opts *MonitorsOptions) String() string

String implements the Stringer interface

type Scraper

type Scraper struct {
	Running   bool    `json:"Running"`
	SleepSecs float64 `json:"SleepSecs"`
	Name      string  `json:"Name"`
}

func NewScraper

func NewScraper(color, name string, secs float64, logLev uint64) Scraper

func (*Scraper) ChangeState

func (scraper *Scraper) ChangeState(onOff bool, tmpPath string) bool

func (*Scraper) Pause

func (scraper *Scraper) Pause()

Jump to

Keyboard shortcuts

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