otterscan/cmd/otter/main.go

44 lines
1.1 KiB
Go
Raw Normal View History

2022-10-25 01:58:24 +00:00
package main
import (
"os"
2022-10-25 10:20:17 +00:00
"github.com/go-chi/chi/v5"
2022-10-25 01:58:24 +00:00
"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra"
2022-10-25 10:20:17 +00:00
"github.com/wmitsuda/otterscan/cmd/otter/cli"
mycmds "github.com/wmitsuda/otterscan/cmd/otter/commands"
2022-10-25 01:58:24 +00:00
)
func main() {
cmd, cfg := cli.RootCommand()
rootCtx, rootCancel := common.RootContext()
cmd.RunE = func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
logger := log.New()
db, borDb, backend, txPool, mining, stateCache, blockReader, ff, agg, err := cli.RemoteServices(ctx, *cfg, logger, rootCancel)
if err != nil {
log.Error("Could not connect to DB", "err", err)
return nil
}
defer db.Close()
if borDb != nil {
defer borDb.Close()
}
2022-10-25 10:20:17 +00:00
r := chi.NewRouter()
RouteServer(r, *cfg)
2022-10-25 01:58:24 +00:00
apiList := mycmds.APIList(db, borDb, backend, txPool, mining, ff, stateCache, blockReader, agg, *cfg)
2022-10-25 10:20:17 +00:00
if err := cli.StartRpcServer(ctx, r, *cfg, apiList); err != nil {
2022-10-25 01:58:24 +00:00
log.Error(err.Error())
return nil
}
return nil
}
if err := cmd.ExecuteContext(rootCtx); err != nil {
log.Error(err.Error())
os.Exit(1)
}
}