eventlogger

package
v0.0.0-...-0908cd3 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name:  "event-logger",
	Flags: []cli.Flag{flags.ConfigFlag},
	Action: func(ctx *cli.Context) error {
		config, err := flags.ReadConfig[Config](ctx)
		if err != nil {
			return err
		}
		logger, err := config.NewLogger()
		if err != nil {
			return err
		}

		logger.Info("Set Filter Query from Config...")
		query, err := config.NewFilterQuery()
		if err != nil {
			return err
		}
		logger.Info("Dial ETH Client...")
		client, err := ethclient.DialContext(ctx.Context, config.Chain.URI)
		if err != nil {
			return err
		}
		defer client.Close()

		logger.Info("Connect Mongodb...")
		collection, err := config.ConnectDatabase()
		if err != nil {
			return err
		}
		defer collection.Database().Client().Disconnect(ctx.Context)

		stopCh := make(chan os.Signal, 1)
		signal.Notify(stopCh, syscall.SIGINT, syscall.SIGTERM)
		defer close(stopCh)

		logger.Info("Open Query Server...")
		return NewLoggerServer(stopCh, config.Server.Host, logger, client, collection, query)
	},
}

Functions

func NewLoggerServer

func NewLoggerServer(stopCh <-chan os.Signal, addr string, log *logrus.Logger, client Backend, collection *mongo.Collection, query *ethereum.FilterQuery) error

Types

type Backend

type Backend interface {
	// utils.Backend
	SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)
	FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([]types.Log, error)
}

type Config

type Config struct {
	Chain struct {
		URI string `toml:"uri"`
	} `toml:"chain"`
	Database struct {
		URI        string `toml:"uri"`
		Database   string `toml:"database"`
		Collection string `toml:"collection"`
	} `toml:"db"`
	Server struct {
		Host string `toml:"host"`
	} `toml:"server"`
	Logger struct {
		Level string `toml:"level"` // panic,fatal,error,warn,info,debug,trace
		File  string `toml:"file"`
	} `toml:"log"`
	FilterQuery struct {
		ScanBlock uint64           `toml:"scan-block"`
		Addresses []common.Address `toml:"addresses"`
	} `toml:"filter-query"`
}

func (*Config) ConnectDatabase

func (config *Config) ConnectDatabase() (*mongo.Collection, error)

func (*Config) NewFilterQuery

func (config *Config) NewFilterQuery() (*ethereum.FilterQuery, error)

func (*Config) NewLogger

func (config *Config) NewLogger() (*logrus.Logger, error)

Set Logger

type LoggerServer

type LoggerServer struct {
	logger.UnimplementedLoggerServer
	logger.UnimplementedAdminServer
	// contains filtered or unexported fields
}

func (*LoggerServer) Add

func (*LoggerServer) Connect

func (*LoggerServer) Info

func (*LoggerServer) Remove

func (*LoggerServer) Start

func (*LoggerServer) Stop

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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