lotus/daemon/cmd.go

55 lines
1.1 KiB
Go
Raw Normal View History

2019-07-09 13:15:37 +00:00
// +build !nodaemon
package daemon
import (
2019-07-02 12:40:25 +00:00
"context"
2019-07-10 17:28:49 +00:00
"github.com/multiformats/go-multiaddr"
"gopkg.in/urfave/cli.v2"
2019-07-10 15:38:35 +00:00
"github.com/filecoin-project/go-lotus/node"
"github.com/filecoin-project/go-lotus/node/repo"
)
2019-07-02 13:05:43 +00:00
// Cmd is the `go-lotus daemon` command
var Cmd = &cli.Command{
Name: "daemon",
Usage: "Start a lotus daemon process",
2019-07-08 20:50:13 +00:00
Flags: []cli.Flag{
&cli.StringFlag{
Name: "api",
2019-07-10 17:28:49 +00:00
Value: "1234",
2019-07-08 20:50:13 +00:00
},
},
2019-07-02 12:40:25 +00:00
Action: func(cctx *cli.Context) error {
ctx := context.Background()
2019-07-10 17:10:19 +00:00
r, err := repo.NewFS(cctx.String("repo"))
if err != nil {
return err
}
if err := r.Init(); err != nil && err != repo.ErrRepoExists {
return err
}
2019-07-10 15:38:35 +00:00
api, err := node.New(ctx,
node.Online(),
2019-07-10 17:10:19 +00:00
node.Repo(r),
2019-07-10 17:28:49 +00:00
node.Override(node.SetApiEndpointKey, func(lr repo.LockedRepo) error {
apima, err := multiaddr.NewMultiaddr("/ip4/127.0.0.1/tcp/" + cctx.String("api"))
if err != nil {
return err
}
return lr.SetAPIEndpoint(apima)
}),
2019-07-10 15:38:35 +00:00
)
if err != nil {
return err
}
2019-07-11 11:57:04 +00:00
// TODO: properly parse api endpoint (or make it a URL)
return serveRPC(api, "127.0.0.1:"+cctx.String("api"))
},
}