eth-blob-indexer/main.go

70 lines
1.6 KiB
Go
Raw Normal View History

package main
import (
"context"
"flag"
"log/slog"
"os"
indexer "github.com/cerc-io/eth-blob-indexer/pkg"
"github.com/go-redis/redis/v8"
"github.com/lmittmann/tint"
)
const (
defaultBeaconAddr = "https://localhost:5052"
defaultRedisAddr = "localhost:6379"
defaultRedisPassword = ""
)
var (
logLevelVar slog.LevelVar
)
func init() {
h := tint.NewHandler(os.Stderr, &tint.Options{Level: &logLevelVar})
slog.SetDefault(slog.New(h))
}
func main() {
// Parse command line arguments
var beaconAddress, redisAddress string
var redisPassword string
var logLevel flagLevel
var flags = flag.NewFlagSet("blob-indexer", flag.ExitOnError)
flags.StringVar(&beaconAddress, "beacon-addr", defaultBeaconAddr, "Address of the beacon node")
flags.StringVar(&redisAddress, "redis-addr", defaultRedisAddr, "Address of the Redis server")
flags.StringVar(&redisPassword, "redis-password", defaultRedisPassword, "Password for the Redis server")
flags.Var(&logLevel, "log-level", "Log level (default INFO)")
err := flags.Parse(os.Args[1:])
if err != nil {
panic(err)
}
logLevelVar.Set(logLevel.Level)
beacon := &indexer.BeaconClient{URL: beaconAddress}
rdb := redis.NewClient(&redis.Options{
Addr: redisAddress,
})
db := indexer.NewRedisStorage(rdb)
// db := indexer.NewMapStorage()
slog.Info("Starting indexer", "beacon", beaconAddress, "redis", redisAddress)
err = beacon.CollectBlobs(context.Background(), db)
if err != nil {
panic(err)
}
}
type flagLevel struct{ slog.Level }
func (fl *flagLevel) Set(value string) error {
return fl.UnmarshalText([]byte(value))
}