Documentation ¶
Overview ¶
monitorsPkg implements the chifra monitors command.
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:
[bash] 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:
[bash] 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.
Index ¶
- func GetExportFormat(cmd, def string) string
- func GetMonitorMap(chain string) (map[base.Address]*monitor.Monitor, []*monitor.Monitor)
- func ResetOptions(testMode bool)
- func RunMonitors(cmd *cobra.Command, args []string) error
- func ServeMonitors(w http.ResponseWriter, r *http.Request) error
- type Command
- type MonitorsOptions
- func (opts *MonitorsOptions) FreshenMonitorsForWatch(addrs []base.Address) (bool, error)
- func (opts *MonitorsOptions) HandleClean(rCtx *output.RenderCtx) error
- func (opts *MonitorsOptions) HandleCount(rCtx *output.RenderCtx) error
- func (opts *MonitorsOptions) HandleCrud(rCtx *output.RenderCtx) error
- func (opts *MonitorsOptions) HandleDecache(rCtx *output.RenderCtx) error
- func (opts *MonitorsOptions) HandleList(rCtx *output.RenderCtx) error
- func (opts *MonitorsOptions) HandleShow(rCtx *output.RenderCtx) error
- func (opts *MonitorsOptions) HandleWatch(rCtx *output.RenderCtx) error
- func (opts *MonitorsOptions) MonitorsInternal(rCtx *output.RenderCtx) error
- func (opts *MonitorsOptions) Refresh(monitors []monitor.Monitor) (bool, error)
- func (opts *MonitorsOptions) RunMonitorScraper(wg *sync.WaitGroup, s *Scraper)
- func (opts *MonitorsOptions) String() string
- type Scraper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetExportFormat ¶
func GetMonitorMap ¶
func ResetOptions ¶
func ResetOptions(testMode bool)
func RunMonitors ¶
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 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, optionally clear stage List bool `json:"list,omitempty"` // List monitors in the cache (--verbose for more detail) Count bool `json:"count,omitempty"` // Show the number of active monitors (included deleted but not removed monitors) Staged bool `json:"staged,omitempty"` // For --clean, --list, and --count options only, include staged monitors 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 MonitorsFinishParseInternal ¶
func MonitorsFinishParseInternal(w io.Writer, values url.Values) *MonitorsOptions
func (*MonitorsOptions) FreshenMonitorsForWatch ¶
func (opts *MonitorsOptions) FreshenMonitorsForWatch(addrs []base.Address) (bool, error)
func (*MonitorsOptions) HandleClean ¶
func (opts *MonitorsOptions) HandleClean(rCtx *output.RenderCtx) error
HandleClean handles the chifra monitors --clean command.
func (*MonitorsOptions) HandleCount ¶
func (opts *MonitorsOptions) HandleCount(rCtx *output.RenderCtx) error
HandleCount handles the chifra abis --count command.
func (*MonitorsOptions) HandleCrud ¶
func (opts *MonitorsOptions) HandleCrud(rCtx *output.RenderCtx) error
HandleCrud 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(rCtx *output.RenderCtx) error
func (*MonitorsOptions) HandleList ¶
func (opts *MonitorsOptions) HandleList(rCtx *output.RenderCtx) error
HandleList handles the chifra monitors --list command.
func (*MonitorsOptions) HandleShow ¶
func (opts *MonitorsOptions) HandleShow(rCtx *output.RenderCtx) error
func (*MonitorsOptions) HandleWatch ¶
func (opts *MonitorsOptions) HandleWatch(rCtx *output.RenderCtx) error
HandleWatch starts the monitor watcher
func (*MonitorsOptions) MonitorsInternal ¶
func (opts *MonitorsOptions) MonitorsInternal(rCtx *output.RenderCtx) 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