scan

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoEventSignature       = errors.New("no event signature")
	ErrInvalidEventID         = errors.New("invalid eventID exists")
	ErrEventSignatureMismatch = errors.New("event signature mismatch")
	ErrNonTargetedEvent       = errors.New("non-targeted event")
)
View Source
var Command = &cli.Command{
	Name:  "scanner",
	Flags: []cli.Flag{flags.ConfigFlag},
	Action: func(ctx *cli.Context) error {

		log := logrus.New()
		log.SetFormatter(&logrus.TextFormatter{
			ForceColors:      true,
			DisableColors:    false,
			DisableTimestamp: false,
			TimestampFormat:  "2006-01-02 15:04:05",
		})

		log.SetLevel(logrus.TraceLevel)
		log.SetOutput(os.Stdout)

		log.Info("Read Config...")
		config, err := flags.ReadConfig[Config](ctx)
		if err != nil {
			return err
		}

		log.Info("Connect Database...")
		db, err := gorm.Open(postgres.Open(config.GetPostgreDns()), &gorm.Config{})
		if err != nil {
			return err
		}

		log.Info("Connect EventLogger...")
		conn, err := grpc.NewClient(config.EventLogger.URI, grpc.WithTransportCredentials(insecure.NewCredentials()))
		if err != nil {
			return err
		}

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

		go func() {
			log.Info("Open Rest Api...", "listen", "0.0.0.0:8090")

			engine := gin.Default()
			v1 := engine.Group("/api/v1")
			for _, api := range []interface {
				RegisterApi(*gin.RouterGroup) error
			}{
				NewERC20Api(db), NewERC1155Api(db), NewFaucetApi(db), NewGovernorApi(db),
			} {
				if err := api.RegisterApi(v1); err != nil {
					log.WithField("message", err.Error()).Panic("fail to register api")
				}
			}
			if err := engine.Run("0.0.0.0:8090"); err != nil {
				stopCh <- os.Interrupt
			}
		}()

		return Scan(ctx.Context, stopCh, config.Contracts, db, logger.NewLoggerClient(conn), log)
	},
	Subcommands: []*cli.Command{
		{
			Name:  "init",
			Flags: []cli.Flag{flags.ConfigFlag},
			Action: func(ctx *cli.Context) error {
				config, err := flags.ReadConfig[Config](ctx)
				if err != nil {
					return err
				}

				db, err := gorm.Open(postgres.Open(config.GetPostgreDns()), &gorm.Config{})
				if err != nil {
					return err
				}

				err = db.AutoMigrate(dbtypes.AllTables...)
				if err == nil {
					fmt.Println("Scanner Init Successed!")
				}
				return err
			},
		},
	},
}

Functions

func Scan

func Scan(
	ctx context.Context, stop chan os.Signal,
	config ContractConfig,
	db *gorm.DB, client logger.LoggerClient,
	log *logrus.Logger,
) error

Types

type BmErc1155TransferBatch

type BmErc1155TransferBatch gov.BmErc1155TransferBatch

func (*BmErc1155TransferBatch) Do

func (event *BmErc1155TransferBatch) Do(log types.Log) func(db *gorm.DB) error

type BmErc1155TransferSingle

type BmErc1155TransferSingle gov.BmErc1155TransferSingle

func (*BmErc1155TransferSingle) Do

func (event *BmErc1155TransferSingle) Do(log types.Log) func(db *gorm.DB) error

type BmErc20Transfer

type BmErc20Transfer gov.BmErc20Transfer

func (*BmErc20Transfer) Do

func (event *BmErc20Transfer) Do(log types.Log) func(db *gorm.DB) error

type BmGovernorProposalCanceled

type BmGovernorProposalCanceled gov.BmGovernorProposalCanceled

func (*BmGovernorProposalCanceled) Do

func (event *BmGovernorProposalCanceled) Do(log types.Log) func(db *gorm.DB) error

type BmGovernorProposalCreated

type BmGovernorProposalCreated gov.BmGovernorProposalCreated

func (*BmGovernorProposalCreated) Do

func (event *BmGovernorProposalCreated) Do(log types.Log) func(db *gorm.DB) error

type BmGovernorProposalExecuted

type BmGovernorProposalExecuted gov.BmGovernorProposalExecuted

func (*BmGovernorProposalExecuted) Do

func (event *BmGovernorProposalExecuted) Do(log types.Log) func(db *gorm.DB) error

type Config

type Config struct {
	EventLogger struct {
		URI string `toml:"uri"`
	} `toml:"event-logger"`
	Contracts ContractConfig `toml:"contracts"`
	Database  struct {
		DBName   string `toml:"name"`
		Host     string `toml:"host"`
		Port     int    `toml:"port"`
		User     string `toml:"user"`
		Password string `toml:"passowrd"`
	} `toml:"db"`
}

func GetConfig

func GetConfig(ctx *cli.Context) (*Config, error)

func (*Config) GetPostgreDns

func (cfg *Config) GetPostgreDns() string

type ContractConfig

type ContractConfig struct {
	FromBlock  uint64         `toml:"from"` // 블록을 스캔할 시작 블럭
	Faucet     common.Address `toml:"faucet"`
	ERC20      common.Address `toml:"erc20"`
	ERC1155    common.Address `toml:"erc1155"`
	Governance common.Address `toml:"governance"`
}

type ERC1155Api

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

func NewERC1155Api

func NewERC1155Api(db *gorm.DB) *ERC1155Api

func (*ERC1155Api) RegisterApi

func (api *ERC1155Api) RegisterApi(engine *gin.RouterGroup) error

type ERC1155Scanner

type ERC1155Scanner struct {
	Scanner
}

func NewERC1155Scanner

func NewERC1155Scanner(address common.Address, logger *logrus.Logger) (*ERC1155Scanner, error)

type ERC20Api

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

func NewERC20Api

func NewERC20Api(db *gorm.DB) *ERC20Api

func (*ERC20Api) RegisterApi

func (api *ERC20Api) RegisterApi(engine *gin.RouterGroup) error

type ERC20Scanner

type ERC20Scanner struct {
	Scanner
}

func NewERC20Scanner

func NewERC20Scanner(address common.Address, logentry *logrus.Logger) (*ERC20Scanner, error)

type FaucetApi

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

func NewFaucetApi

func NewFaucetApi(db *gorm.DB) *FaucetApi

func (*FaucetApi) RegisterApi

func (api *FaucetApi) RegisterApi(engine *gin.RouterGroup) error

type FaucetClaimed

type FaucetClaimed gov.FaucetClaimed

func (*FaucetClaimed) Do

func (event *FaucetClaimed) Do(log types.Log) func(db *gorm.DB) error

type FaucetScanner

type FaucetScanner struct {
	Scanner
}

func NewFaucetScanner

func NewFaucetScanner(address common.Address, logger *logrus.Logger) (*FaucetScanner, error)

type GovernorApi

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

func NewGovernorApi

func NewGovernorApi(db *gorm.DB) *GovernorApi

func (*GovernorApi) RegisterApi

func (api *GovernorApi) RegisterApi(engine *gin.RouterGroup) error

type GovernorScanner

type GovernorScanner struct {
	Scanner
}

func NewGovernorScanner

func NewGovernorScanner(address common.Address, logger *logrus.Logger) (*GovernorScanner, error)

type IScanner

type IScanner interface {
	Scan(ctx context.Context, client logger.LoggerClient, fromBlock uint64, tx chan<- func(db *gorm.DB) error) error
}

type Scanner

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

func (*Scanner) Scan

func (s *Scanner) Scan(ctx context.Context, client logger.LoggerClient, fromBlock uint64, tx chan<- func(db *gorm.DB) error) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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