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"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/filters"
|
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 {
|
2021-07-28 02:47:38 +00:00
|
|
|
logger := log.New()
|
2022-02-07 21:30:46 +00:00
|
|
|
db, borDb, backend, txPool, mining, starknet, stateCache, blockReader, err := cli.RemoteServices(cmd.Context(), *cfg, logger, rootCancel)
|
2020-08-19 11:46:20 +00:00
|
|
|
if err != nil {
|
2020-10-25 08:39:09 +00:00
|
|
|
log.Error("Could not connect to DB", "error", err)
|
2020-08-19 11:46:20 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-10-10 06:06:54 +00:00
|
|
|
defer db.Close()
|
2019-12-02 13:47:00 +00:00
|
|
|
|
2020-11-17 19:13:41 +00:00
|
|
|
var ff *filters.Filters
|
|
|
|
if backend != nil {
|
2021-05-17 12:15:19 +00:00
|
|
|
ff = filters.New(rootCtx, backend, txPool, mining)
|
2020-11-17 19:13:41 +00:00
|
|
|
} else {
|
|
|
|
log.Info("filters are not supported in chaindata mode")
|
|
|
|
}
|
|
|
|
|
2022-02-07 21:30:46 +00:00
|
|
|
if err := cli.StartRpcServer(cmd.Context(), *cfg, commands.APIList(cmd.Context(), db, borDb, backend, txPool, mining, starknet, ff, stateCache, blockReader, *cfg, 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
|
|
|
}
|