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