forked from mantlenetworkio/mantle-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (57 loc) · 1.74 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
package main
import (
"fmt"
"os"
"github.com/ethereum-optimism/optimism/gas-oracle/flags"
ometrics "github.com/ethereum-optimism/optimism/gas-oracle/metrics"
"github.com/ethereum-optimism/optimism/gas-oracle/oracle"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/urfave/cli"
)
var (
GitVersion = ""
GitCommit = ""
GitDate = ""
)
func main() {
app := cli.NewApp()
app.Flags = flags.Flags
app.Version = GitVersion + "-" + params.VersionWithCommit(GitCommit, GitDate)
app.Name = "gas-oracle"
app.Usage = "Remotely Control the Optimism Gas Price"
app.Description = "Configure with a private key and an Optimism HTTP endpoint " +
"to send transactions that update the L2 gas price."
// Configure the logging
app.Before = func(ctx *cli.Context) error {
loglevel := ctx.GlobalUint64(flags.LogLevelFlag.Name)
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(loglevel), log.StreamHandler(os.Stdout, log.TerminalFormat(true))))
return nil
}
// Define the functionality of the application
app.Action = func(ctx *cli.Context) error {
if args := ctx.Args(); len(args) > 0 {
return fmt.Errorf("invalid command: %q", args[0])
}
config := oracle.NewConfig(ctx)
gpo, err := oracle.NewGasPriceOracle(config)
if err != nil {
return err
}
if config.MetricsEnabled {
address := fmt.Sprintf("%s:%d", config.MetricsHTTP, config.MetricsPort)
log.Info("Enabling stand-alone metrics HTTP endpoint", "address", address)
ometrics.Setup(address)
ometrics.InitAndRegisterStats(ometrics.DefaultRegistry)
}
if err := gpo.Start(); err != nil {
return err
}
gpo.Wait()
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Crit("application failed", "message", err)
}
}