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