|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "os" |
| 7 | + |
| 8 | + "github.com/base-org/blob-archiver/api/flags" |
| 9 | + "github.com/base-org/blob-archiver/api/metrics" |
| 10 | + "github.com/base-org/blob-archiver/api/service" |
| 11 | + "github.com/base-org/blob-archiver/common/beacon" |
| 12 | + "github.com/base-org/blob-archiver/common/storage" |
| 13 | + opservice "github.com/ethereum-optimism/optimism/op-service" |
| 14 | + "github.com/ethereum-optimism/optimism/op-service/cliapp" |
| 15 | + oplog "github.com/ethereum-optimism/optimism/op-service/log" |
| 16 | + opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics" |
| 17 | + "github.com/ethereum/go-ethereum/log" |
| 18 | + "github.com/urfave/cli/v2" |
| 19 | +) |
| 20 | + |
| 21 | +var ( |
| 22 | + Version = "v0.0.1" |
| 23 | + GitCommit = "" |
| 24 | + GitDate = "" |
| 25 | +) |
| 26 | + |
| 27 | +func main() { |
| 28 | + oplog.SetupDefaults() |
| 29 | + |
| 30 | + app := cli.NewApp() |
| 31 | + app.Flags = cliapp.ProtectFlags(flags.Flags) |
| 32 | + app.Version = opservice.FormatVersion(Version, GitCommit, GitDate, "") |
| 33 | + app.Name = "blob-api" |
| 34 | + app.Usage = "API service for Ethereum blobs" |
| 35 | + app.Description = "Service for fetching blob sidecars from a datastore" |
| 36 | + app.Action = cliapp.LifecycleCmd(Main()) |
| 37 | + |
| 38 | + err := app.Run(os.Args) |
| 39 | + if err != nil { |
| 40 | + log.Crit("Application failed", "message", err) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +// Main is the entrypoint into the API. |
| 45 | +// This method returns a cliapp.LifecycleAction, to create an op-service CLI-lifecycle-managed API Server. |
| 46 | +func Main() cliapp.LifecycleAction { |
| 47 | + return func(cliCtx *cli.Context, closeApp context.CancelCauseFunc) (cliapp.Lifecycle, error) { |
| 48 | + cfg := flags.ReadConfig(cliCtx) |
| 49 | + if err := cfg.Check(); err != nil { |
| 50 | + return nil, fmt.Errorf("config check failed: %w", err) |
| 51 | + } |
| 52 | + |
| 53 | + l := oplog.NewLogger(oplog.AppOut(cliCtx), cfg.LogConfig) |
| 54 | + oplog.SetGlobalLogHandler(l.GetHandler()) |
| 55 | + opservice.ValidateEnvVars(flags.EnvVarPrefix, flags.Flags, l) |
| 56 | + |
| 57 | + registry := opmetrics.NewRegistry() |
| 58 | + m := metrics.NewMetrics(registry) |
| 59 | + |
| 60 | + storageClient, err := storage.NewStorage(cfg.StorageConfig, l) |
| 61 | + if err != nil { |
| 62 | + return nil, err |
| 63 | + } |
| 64 | + |
| 65 | + beaconClient, err := beacon.NewBeaconClient(context.Background(), cfg.BeaconConfig) |
| 66 | + if err != nil { |
| 67 | + return nil, err |
| 68 | + } |
| 69 | + |
| 70 | + l.Info("Initializing API Service") |
| 71 | + return service.NewAPIService(l, storageClient, beaconClient, cfg, registry, m), nil |
| 72 | + } |
| 73 | +} |
0 commit comments