daemonPkg

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

README

chifra daemon

chifra daemon manages chifra's API server. Each of the chifra commands along with all of its options, are provided not only by the command line, but also the API server. We call this process the flame server, which is written in Go. chifra serve is an alias for the chifra daemon command.

In the future, this daemon may also manage other long-running processes such as chifra scrape and chifra monitors, but for now, it's only managing the API server.

The --grpc option turns on a GRPC server that may speed up certain command such as chifra names, although this option is experimental and therefore not recommended for production use.

If the default port for the API server is in use, you may change it with the --port option.

To get help for any command, please see the API documentation on our website. But, you may also run chifra --help or chifra <cmd> --help on your command line to get help.

See below for an example of converting command line options to a call to the API. There's a one-to-one correspondence between the command line tools and options and the API routes and their options.

Purpose:
  Initialize and control long-running processes such as the API and the scrapers.

Usage:
  chifra daemon [flags]

Aliases:
  daemon, serve

Flags:
  -u, --url string   specify the API server's url and optionally its port (default "localhost:8080")
  -g, --grpc         run gRPC server to serve names
  -x, --fmt string   export format, one of [none|json*|txt|csv]
  -v, --verbose      enable verbose output
  -h, --help         display this help screen

Notes:
  - To start API open terminal window and run chifra daemon.
  - See the API documentation (https://trueblocks.io/api) for more information.

Data models produced by this tool:

  • none

notes

To convert the options for a command line tool to an API call, do the following:

  1. Any --snake_case argument to the command line should be converted to camelCase. For example, --no_header on the command line should be sent as &noHeader to the API server.
  2. Any switch on the command line, (i.e., options whose presence indicates true and whose absence indicates false) should be sent as a boolean to the API server. For example, --no_header on the command line should be sent as &noHeader=true to the API server. If the option is fales, you do not need to send it to the API server.
  3. Positionals such as the addresses, topics, and four-bytes for chifra export, must be prepended with their positional name. For example, chifra export <address> <topic> should be sent as &addrs=<address>&topics=<topic> to the API server. For some commands (experiment) you may send more than one value for a positional with %20 separating the entries or by sending multiple positionals (i.e., &addrs=<address1>&addrs=<address2>).

Chifra was built for the command line, a fact we purposefully take advantage of to ensure continued operation on small machines. As such, this tool is not intended to serve multiple end users in a cloud-based server environment. This is by design. Be forewarned.

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 daemonPkg handles the chifra daemon command. It manages chifra's API server. Each of the chifra commands along with all of its options, are provided not only by the command line, but also the API server. We call this process the flame server, which is written in Go. chifra serve is an alias for the command. In the future, this daemon may also manage other long-running processes such as chifra scrape and chifra monitors, but for now, it's only managing the API server. The --grpc option turns on a GRPC server that may speed up certain command such as chifra names, although this option is experimental and therefore not recommended for production use. If the default port for the API server is in use, you may change it with the --port option. To get help for any command, please see the API documentation on our website. But, you may also run chifra --help or chifra <cmd> --help on your command line to get help. See below for an example of converting command line options to a call to the API. There's a one-to-one correspondence between the command line tools and options and the API routes and their options.

Index

Constants

This section is empty.

Variables

View Source
var OptionsHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	addCorsHeaders(w)
})

Functions

func ContentTypeHandler

func ContentTypeHandler(next http.Handler) http.Handler

ContentTypeHandler sets correct Content-Type header on response

func CorsHandler

func CorsHandler(next http.Handler) http.Handler

CorsHandler handles CORS requests

func HandleWebsockets

func HandleWebsockets(pool *ConnectionPool, w http.ResponseWriter, r *http.Request)

HandleWebsockets handles web sockets

func Index

func Index(w http.ResponseWriter, r *http.Request)

func Logger

func Logger(inner http.Handler, name string) http.Handler

Logger sends information to the server's console

func NewRouter

func NewRouter() *mux.Router

NewRouter Creates a new router given the routes array

func ResetOptions

func ResetOptions(testMode bool)

func RespondWithError

func RespondWithError(w http.ResponseWriter, httpStatus int, err error)

RespondWithError marshals an err into JSON and returns the bytes back to the caller httpStatus HTTP error status code

func RouteAbis

func RouteAbis(w http.ResponseWriter, r *http.Request)

RouteAbis Fetches the ABI for a smart contract.

func RouteBlocks

func RouteBlocks(w http.ResponseWriter, r *http.Request)

RouteBlocks Retrieve one or more blocks from the chain or local cache.

func RouteChunks

func RouteChunks(w http.ResponseWriter, r *http.Request)

RouteChunks Manage, investigate, and display the Unchained Index.

func RouteConfig

func RouteConfig(w http.ResponseWriter, r *http.Request)

RouteConfig Report on and edit the configuration of the TrueBlocks system.

func RouteExplore

func RouteExplore(w http.ResponseWriter, r *http.Request)

RouteExplore Open a local or remote explorer for one or more addresses, blocks, or transactions.

func RouteExport

func RouteExport(w http.ResponseWriter, r *http.Request)

RouteExport Export full details of transactions for one or more addresses.

func RouteInit

func RouteInit(w http.ResponseWriter, r *http.Request)

RouteInit Initialize the TrueBlocks system by downloading the Unchained Index from IPFS.

func RouteList

func RouteList(w http.ResponseWriter, r *http.Request)

RouteList List every appearance of an address anywhere on the chain.

func RouteLogs

func RouteLogs(w http.ResponseWriter, r *http.Request)

RouteLogs Retrieve logs for the given transaction(s).

func RouteMonitors

func RouteMonitors(w http.ResponseWriter, r *http.Request)

RouteMonitors Add, remove, clean, and list address monitors.

func RouteNames

func RouteNames(w http.ResponseWriter, r *http.Request)

RouteNames Query addresses or names of well-known accounts.

func RouteReceipts

func RouteReceipts(w http.ResponseWriter, r *http.Request)

RouteReceipts Retrieve receipts for the given transaction(s).

func RouteScrape

func RouteScrape(w http.ResponseWriter, r *http.Request)

RouteScrape Scan the chain and update the TrueBlocks index of appearances.

func RouteSlurp

func RouteSlurp(w http.ResponseWriter, r *http.Request)

RouteSlurp Fetch data from Etherscan for any address.

func RouteState

func RouteState(w http.ResponseWriter, r *http.Request)

RouteState Retrieve account balance(s) for one or more addresses at given block(s).

func RouteStatus

func RouteStatus(w http.ResponseWriter, r *http.Request)

RouteStatus Report on the state of the internal binary caches.

func RouteTokens

func RouteTokens(w http.ResponseWriter, r *http.Request)

RouteTokens Retrieve token balance(s) for one or more addresses at given block(s).

func RouteTraces

func RouteTraces(w http.ResponseWriter, r *http.Request)

RouteTraces Retrieve traces for the given transaction(s).

func RouteTransactions

func RouteTransactions(w http.ResponseWriter, r *http.Request)

RouteTransactions Retrieve one or more transactions from the chain or local cache.

func RouteWhen

func RouteWhen(w http.ResponseWriter, r *http.Request)

RouteWhen Find block(s) based on date, blockNum, timestamp, or 'special'.

func RunDaemon

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

RunDaemon handles the daemon command for the command line. Returns error only as per cobra.

func RunWebsocketPool

func RunWebsocketPool()

RunWebsocketPool runs the websocket pool

func ServeDaemon

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

ServeDaemon handles the daemon command for the API. Returns an error.

Types

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

Connection is a structure representing a websocket connection

func (*Connection) Log

func (c *Connection) Log(s string, args ...interface{})

Log writes a log messages to the server's stderr

func (*Connection) RemoteAddr

func (c *Connection) RemoteAddr() net.Addr

RemoteAddr is the other end of the connection

type ConnectionPool

type ConnectionPool struct {
	// contains filtered or unexported fields
}

ConnectionPool is the collection of all connections

type DaemonOptions

type DaemonOptions struct {
	Url     string                `json:"url,omitempty"`     // Specify the API server's url and optionally its port
	Api     string                `json:"api,omitempty"`     // Instruct the node to start the API server
	Scrape  string                `json:"scrape,omitempty"`  // Start the scraper, initialize it with either just blooms or entire index, generate for new blocks
	Monitor bool                  `json:"monitor,omitempty"` // Instruct the node to start the monitors tool
	Grpc    bool                  `json:"grpc,omitempty"`    // Run gRPC server to serve names
	Port    string                `json:"port,omitempty"`    // Deprecated please use --url flag instead
	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

}

DaemonOptions provides all command options for the chifra daemon command.

func GetDaemonOptions

func GetDaemonOptions(args []string, g *globals.GlobalOptions) *DaemonOptions

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

func GetOptions

func GetOptions() *DaemonOptions

func (*DaemonOptions) DaemonInternal

func (opts *DaemonOptions) DaemonInternal() error

DaemonInternal handles the internal workings of the daemon command. Returns an error.

func (*DaemonOptions) HandleGrpc

func (opts *DaemonOptions) HandleGrpc() error

func (*DaemonOptions) HandleMonitor

func (opts *DaemonOptions) HandleMonitor() error

HandleMonitor starts and manages the monitor process

func (*DaemonOptions) HandleScraper

func (opts *DaemonOptions) HandleScraper() error

HandleScraper starts and manages the scraper process

func (*DaemonOptions) String

func (opts *DaemonOptions) String() string

String implements the Stringer interface

type Message

type Message struct {
	Action  MessageType `json:"action"`
	ID      string      `json:"id"`
	Content string      `json:"content"`
}

Message is a structure used to send messages via websockets

type MessageType

type MessageType string

MessageType is a message carried in a string

const (
	// CommandErrorMessage is a message send when the server encounters an error
	CommandErrorMessage MessageType = "command_error"
	// CommandOutputMessage is currently not used, but may in the future carry the actual data
	CommandOutputMessage MessageType = "output"
	// ProgressMessage is a message carried on the stderr stream
	ProgressMessage MessageType = "progress"
)

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

Route A structure to hold the API's routes

type Routes

type Routes []Route

Routes An array of Route structures

Jump to

Keyboard shortcuts

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