2019-12-02 13:47:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2022-01-19 03:49:07 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/common"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/cli"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/commands"
|
2021-07-29 10:23:23 +00:00
|
|
|
"github.com/ledgerwatch/log/v3"
|
2020-08-19 11:46:20 +00:00
|
|
|
"github.com/spf13/cobra"
|
2019-12-02 13:47:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-08-19 11:46:20 +00:00
|
|
|
cmd, cfg := cli.RootCommand()
|
2022-01-19 03:49:07 +00:00
|
|
|
rootCtx, rootCancel := common.RootContext()
|
2020-08-19 11:46:20 +00:00
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
2022-02-12 12:47:19 +00:00
|
|
|
ctx := cmd.Context()
|
2021-07-28 02:47:38 +00:00
|
|
|
logger := log.New()
|
2022-09-18 10:41:01 +00:00
|
|
|
db, borDb, backend, txPool, mining, stateCache, blockReader, ff, agg, err := cli.RemoteServices(ctx, *cfg, logger, rootCancel)
|
2020-08-19 11:46:20 +00:00
|
|
|
if err != nil {
|
2022-03-01 15:40:51 +00:00
|
|
|
log.Error("Could not connect to DB", "err", err)
|
2020-08-19 11:46:20 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-10-10 06:06:54 +00:00
|
|
|
defer db.Close()
|
2022-02-14 12:00:54 +00:00
|
|
|
if borDb != nil {
|
|
|
|
defer borDb.Close()
|
|
|
|
}
|
2019-12-02 13:47:00 +00:00
|
|
|
|
2022-09-18 10:41:01 +00:00
|
|
|
apiList := commands.APIList(db, borDb, backend, txPool, mining, ff, stateCache, blockReader, agg, *cfg)
|
2022-08-01 15:12:35 +00:00
|
|
|
if err := cli.StartRpcServer(ctx, *cfg, apiList, nil); err != nil {
|
2021-03-25 06:42:45 +00:00
|
|
|
log.Error(err.Error())
|
|
|
|
return nil
|
|
|
|
}
|
2022-01-25 16:44:35 +00:00
|
|
|
|
2021-03-25 06:42:45 +00:00
|
|
|
return nil
|
2019-12-02 13:47:00 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 12:39:34 +00:00
|
|
|
if err := cmd.ExecuteContext(rootCtx); err != nil {
|
2020-08-19 11:46:20 +00:00
|
|
|
log.Error(err.Error())
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2019-12-02 13:47:00 +00:00
|
|
|
}
|