diff --git a/build/tools.go b/build/tools.go index 55bdec18b57..ad45397bb37 100644 --- a/build/tools.go +++ b/build/tools.go @@ -3,7 +3,7 @@ package build import ( - _ "github.com/golang/mock/mockgen" _ "github.com/GeertJohan/go.rice/rice" + _ "github.com/golang/mock/mockgen" _ "github.com/whyrusleeping/bencher" ) diff --git a/cli/auth.go b/cli/auth.go index ba20b2bccf6..3c95edafc5c 100644 --- a/cli/auth.go +++ b/cli/auth.go @@ -2,6 +2,7 @@ package cli import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -32,13 +33,13 @@ var authCreateAdminToken = &cli.Command{ }, Action: func(cctx *cli.Context) error { - napi, closer, err := GetAPI(cctx) + napi, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.IsSet("perm") { return xerrors.New("--perm flag not set") @@ -80,13 +81,13 @@ var authApiInfoToken = &cli.Command{ }, Action: func(cctx *cli.Context) error { - napi, closer, err := GetAPI(cctx) + napi, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.IsSet("perm") { return xerrors.New("--perm flag not set") @@ -120,14 +121,14 @@ var authApiInfoToken = &cli.Command{ log.Errorf("repoType type does not match the type of repo.RepoType") } - ainfo, err := GetAPIInfo(cctx, t) + ainfo, err := cliutil.GetAPIInfo(cctx, t) if err != nil { return xerrors.Errorf("could not get API info: %w", err) } // TODO: Log in audit log when it is implemented - fmt.Printf("%s=%s:%s\n", envForRepo(t), string(token), ainfo.Addr) + fmt.Printf("%s=%s:%s\n", cliutil.EnvForRepo(t), string(token), ainfo.Addr) return nil }, } diff --git a/cli/backup.go b/cli/backup.go index 1ee4157278c..620e969ca3f 100644 --- a/cli/backup.go +++ b/cli/backup.go @@ -3,6 +3,7 @@ package cli import ( "context" "fmt" + "github.com/filecoin-project/lotus/cli/util" "os" logging "github.com/ipfs/go-log/v2" @@ -84,7 +85,7 @@ func BackupCmd(repoFlag string, rt repo.RepoType, getApi BackupApiFn) *cli.Comma } defer closer() - err = api.CreateBackup(ReqContext(cctx), cctx.Args().First()) + err = api.CreateBackup(cliutil.ReqContext(cctx), cctx.Args().First()) if err != nil { return err } diff --git a/cli/chain.go b/cli/chain.go index e86cac9b339..e37529ec68d 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -7,6 +7,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "os" "os/exec" "path" @@ -66,12 +67,12 @@ var chainHeadCmd = &cli.Command{ Name: "head", Usage: "Print chain head", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) head, err := api.ChainHead(ctx) if err != nil { @@ -96,12 +97,12 @@ var chainGetBlock = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must pass cid of block to print") @@ -181,12 +182,12 @@ var chainReadObjCmd = &cli.Command{ Usage: "Read the raw bytes of an object", ArgsUsage: "[objectCid]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) c, err := cid.Decode(cctx.Args().First()) if err != nil { @@ -214,12 +215,12 @@ var chainDeleteObjCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) c, err := cid.Decode(cctx.Args().First()) if err != nil { @@ -256,12 +257,12 @@ var chainStatObjCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) obj, err := cid.Decode(cctx.Args().First()) if err != nil { @@ -296,12 +297,12 @@ var chainGetMsgCmd = &cli.Command{ return fmt.Errorf("must pass a cid of a message to get") } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) c, err := cid.Decode(cctx.Args().First()) if err != nil { @@ -350,12 +351,12 @@ var chainSetHeadCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var ts *types.TipSet @@ -405,12 +406,12 @@ var chainInspectUsage = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ts, err := LoadTipSet(ctx, cctx, api) if err != nil { @@ -547,12 +548,12 @@ var chainListCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var head *types.TipSet @@ -706,12 +707,12 @@ var chainGetCmd = &cli.Command{ - account-state `, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) p := path.Clean(cctx.Args().First()) if strings.HasPrefix(p, "/pstate") { @@ -923,12 +924,12 @@ var chainBisectCmd = &cli.Command{ For special path elements see 'chain get' help `, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() < 4 { return xerrors.New("need at least 4 args") @@ -1045,12 +1046,12 @@ var chainExportCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must specify filename to export chain to") @@ -1121,12 +1122,12 @@ var slashConsensusFault = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) c1, err := cid.Parse(cctx.Args().Get(0)) if err != nil { @@ -1231,12 +1232,12 @@ var chainGasPriceCmd = &cli.Command{ Name: "gas-price", Usage: "Estimate gas prices", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) nb := []int{1, 2, 3, 5, 10, 20, 50, 100, 300} for _, nblocks := range nb { @@ -1277,12 +1278,12 @@ var chainDecodeParamsCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() != 3 { return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments")) @@ -1357,12 +1358,12 @@ var chainEncodeParamsCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() != 3 { return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments")) diff --git a/cli/client.go b/cli/client.go index 98f4b022927..6f49c470882 100644 --- a/cli/client.go +++ b/cli/client.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/filecoin-project/lotus/cli/util" "io" "math" "math/rand" @@ -115,12 +116,12 @@ var clientImportCmd = &cli.Command{ &CidBaseFlag, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.NArg() != 1 { return xerrors.New("expected input path as the only arg") @@ -163,12 +164,12 @@ var clientDropCmd = &cli.Command{ return xerrors.Errorf("no imports specified") } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var ids []multistore.StoreID for i, s := range cctx.Args().Slice() { @@ -198,12 +199,12 @@ var clientCommPCmd = &cli.Command{ &CidBaseFlag, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() != 1 { return fmt.Errorf("usage: commP ") @@ -230,12 +231,12 @@ var clientCarGenCmd = &cli.Command{ Usage: "Generate a car file from input", ArgsUsage: "[inputPath outputPath]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() != 2 { return fmt.Errorf("usage: generate-car ") @@ -262,12 +263,12 @@ var clientLocalCmd = &cli.Command{ &CidBaseFlag, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) list, err := api.ClientListImports(ctx) if err != nil { @@ -341,12 +342,12 @@ var clientDealCmd = &cli.Command{ return interactiveDeal(cctx) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) afmt := NewAppFmt(cctx.App) if cctx.NArg() != 4 { @@ -474,12 +475,12 @@ var clientDealCmd = &cli.Command{ } func interactiveDeal(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ctx, cancel := context.WithCancel(ctx) defer cancel() afmt := NewAppFmt(cctx.App) @@ -901,12 +902,12 @@ var clientFindCmd = &cli.Command{ return err } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) // Check if we already have this data locally @@ -978,12 +979,12 @@ var clientRetrieveCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("incorrect number of arguments")) } - fapi, closer, err := GetFullNodeAPI(cctx) + fapi, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) afmt := NewAppFmt(cctx.App) var payer address.Address @@ -1123,12 +1124,12 @@ var clientDealStatsCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) localDeals, err := api.ClientListDeals(ctx) if err != nil { @@ -1202,12 +1203,12 @@ var clientListAsksCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) asks, err := GetAsks(ctx, api) if err != nil { @@ -1417,12 +1418,12 @@ var clientQueryAskCmd = &cli.Command{ return err } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var pid peer.ID if pidstr := cctx.String("peerid"); pidstr != "" { @@ -1496,12 +1497,12 @@ var clientListDeals = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) verbose := cctx.Bool("verbose") color := cctx.Bool("color") @@ -1717,12 +1718,12 @@ var clientGetDealCmd = &cli.Command{ return cli.ShowCommandHelp(cctx, cctx.Command.Name) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) propcid, err := cid.Decode(cctx.Args().First()) if err != nil { @@ -1766,12 +1767,12 @@ var clientBalancesCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var addr address.Address if clientFlag := cctx.String("client"); clientFlag != "" { @@ -1820,12 +1821,12 @@ var clientStat = &cli.Command{ Usage: "Print information about a locally stored file (piece size, etc)", ArgsUsage: "", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() || cctx.NArg() != 1 { return fmt.Errorf("must specify cid of data") @@ -1866,12 +1867,12 @@ var clientRestartTransfer = &cli.Command{ if !cctx.Args().Present() { return cli.ShowCommandHelp(cctx, cctx.Command.Name) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) transferUint, err := strconv.ParseUint(cctx.Args().First(), 10, 64) if err != nil { @@ -1931,12 +1932,12 @@ var clientCancelTransfer = &cli.Command{ if !cctx.Args().Present() { return cli.ShowCommandHelp(cctx, cctx.Command.Name) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) transferUint, err := strconv.ParseUint(cctx.Args().First(), 10, 64) if err != nil { @@ -2003,12 +2004,12 @@ var clientListTransfers = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) channels, err := api.ClientListDataTransfers(ctx) if err != nil { diff --git a/cli/cmd.go b/cli/cmd.go index 53ad11bc4d5..75fdf1c1566 100644 --- a/cli/cmd.go +++ b/cli/cmd.go @@ -1,34 +1,15 @@ package cli import ( - "context" - "fmt" - "net/http" - "net/url" - "os" - "os/signal" - "strings" - "syscall" - - logging "github.com/ipfs/go-log/v2" - "github.com/mitchellh/go-homedir" - "github.com/urfave/cli/v2" - "golang.org/x/xerrors" - - "github.com/filecoin-project/go-jsonrpc" - "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/api/client" cliutil "github.com/filecoin-project/lotus/cli/util" - "github.com/filecoin-project/lotus/node/repo" + logging "github.com/ipfs/go-log/v2" + "github.com/urfave/cli/v2" + "strings" ) var log = logging.Logger("cli") -const ( - metadataTraceContext = "traceContext" -) - // custom CLI error type ErrCmdFailed struct { @@ -46,173 +27,12 @@ func NewCliError(s string) error { // ApiConnector returns API instance type ApiConnector func() api.FullNode -// The flag passed on the command line with the listen address of the API -// server (only used by the tests) -func flagForAPI(t repo.RepoType) string { - switch t { - case repo.FullNode: - return "api-url" - case repo.StorageMiner: - return "miner-api-url" - case repo.Worker: - return "worker-api-url" - default: - panic(fmt.Sprintf("Unknown repo type: %v", t)) - } -} - -func flagForRepo(t repo.RepoType) string { - switch t { - case repo.FullNode: - return "repo" - case repo.StorageMiner: - return "miner-repo" - case repo.Worker: - return "worker-repo" - default: - panic(fmt.Sprintf("Unknown repo type: %v", t)) - } -} - -func envForRepo(t repo.RepoType) string { - switch t { - case repo.FullNode: - return "FULLNODE_API_INFO" - case repo.StorageMiner: - return "MINER_API_INFO" - case repo.Worker: - return "WORKER_API_INFO" - default: - panic(fmt.Sprintf("Unknown repo type: %v", t)) - } -} - -// TODO remove after deprecation period -func envForRepoDeprecation(t repo.RepoType) string { - switch t { - case repo.FullNode: - return "FULLNODE_API_INFO" - case repo.StorageMiner: - return "STORAGE_API_INFO" - case repo.Worker: - return "WORKER_API_INFO" - default: - panic(fmt.Sprintf("Unknown repo type: %v", t)) - } -} - -func GetAPIInfo(ctx *cli.Context, t repo.RepoType) (cliutil.APIInfo, error) { - // Check if there was a flag passed with the listen address of the API - // server (only used by the tests) - apiFlag := flagForAPI(t) - if ctx.IsSet(apiFlag) { - strma := ctx.String(apiFlag) - strma = strings.TrimSpace(strma) - - return cliutil.APIInfo{Addr: strma}, nil - } - - envKey := envForRepo(t) - env, ok := os.LookupEnv(envKey) - if !ok { - // TODO remove after deprecation period - envKey = envForRepoDeprecation(t) - env, ok = os.LookupEnv(envKey) - if ok { - log.Warnf("Use deprecation env(%s) value, please use env(%s) instead.", envKey, envForRepo(t)) - } - } - if ok { - return cliutil.ParseApiInfo(env), nil - } - - repoFlag := flagForRepo(t) - - p, err := homedir.Expand(ctx.String(repoFlag)) - if err != nil { - return cliutil.APIInfo{}, xerrors.Errorf("could not expand home dir (%s): %w", repoFlag, err) - } - - r, err := repo.NewFS(p) - if err != nil { - return cliutil.APIInfo{}, xerrors.Errorf("could not open repo at path: %s; %w", p, err) - } - - ma, err := r.APIEndpoint() - if err != nil { - return cliutil.APIInfo{}, xerrors.Errorf("could not get api endpoint: %w", err) - } - - token, err := r.APIToken() - if err != nil { - log.Warnf("Couldn't load CLI token, capabilities may be limited: %v", err) - } - - return cliutil.APIInfo{ - Addr: ma.String(), - Token: token, - }, nil -} - -func GetRawAPI(ctx *cli.Context, t repo.RepoType) (string, http.Header, error) { - ainfo, err := GetAPIInfo(ctx, t) - if err != nil { - return "", nil, xerrors.Errorf("could not get API info: %w", err) - } - - addr, err := ainfo.DialArgs() - if err != nil { - return "", nil, xerrors.Errorf("could not get DialArgs: %w", err) - } - - return addr, ainfo.AuthHeader(), nil -} - -func GetAPI(ctx *cli.Context) (api.Common, jsonrpc.ClientCloser, error) { - ti, ok := ctx.App.Metadata["repoType"] - if !ok { - log.Errorf("unknown repo type, are you sure you want to use GetAPI?") - ti = repo.FullNode - } - t, ok := ti.(repo.RepoType) - if !ok { - log.Errorf("repoType type does not match the type of repo.RepoType") - } - - if tn, ok := ctx.App.Metadata["testnode-storage"]; ok { - return tn.(api.StorageMiner), func() {}, nil - } - if tn, ok := ctx.App.Metadata["testnode-full"]; ok { - return tn.(api.FullNode), func() {}, nil - } - - addr, headers, err := GetRawAPI(ctx, t) - if err != nil { - return nil, nil, err - } - - return client.NewCommonRPC(ctx.Context, addr, headers) -} - -func GetFullNodeAPI(ctx *cli.Context) (api.FullNode, jsonrpc.ClientCloser, error) { - if tn, ok := ctx.App.Metadata["testnode-full"]; ok { - return tn.(api.FullNode), func() {}, nil - } - - addr, headers, err := GetRawAPI(ctx, repo.FullNode) - if err != nil { - return nil, nil, err - } - - return client.NewFullNodeRPC(ctx.Context, addr, headers) -} - func GetFullNodeServices(ctx *cli.Context) (ServicesAPI, error) { if tn, ok := ctx.App.Metadata["test-services"]; ok { return tn.(ServicesAPI), nil } - api, c, err := GetFullNodeAPI(ctx) + api, c, err := cliutil.GetFullNodeAPI(ctx) if err != nil { return nil, err } @@ -220,93 +40,6 @@ func GetFullNodeServices(ctx *cli.Context) (ServicesAPI, error) { return &ServicesImpl{api: api, closer: c}, nil } -type GetStorageMinerOptions struct { - PreferHttp bool -} - -type GetStorageMinerOption func(*GetStorageMinerOptions) - -func StorageMinerUseHttp(opts *GetStorageMinerOptions) { - opts.PreferHttp = true -} - -func GetStorageMinerAPI(ctx *cli.Context, opts ...GetStorageMinerOption) (api.StorageMiner, jsonrpc.ClientCloser, error) { - var options GetStorageMinerOptions - for _, opt := range opts { - opt(&options) - } - - if tn, ok := ctx.App.Metadata["testnode-storage"]; ok { - return tn.(api.StorageMiner), func() {}, nil - } - - addr, headers, err := GetRawAPI(ctx, repo.StorageMiner) - if err != nil { - return nil, nil, err - } - - if options.PreferHttp { - u, err := url.Parse(addr) - if err != nil { - return nil, nil, xerrors.Errorf("parsing miner api URL: %w", err) - } - - switch u.Scheme { - case "ws": - u.Scheme = "http" - case "wss": - u.Scheme = "https" - } - - addr = u.String() - } - - return client.NewStorageMinerRPC(ctx.Context, addr, headers) -} - -func GetWorkerAPI(ctx *cli.Context) (api.WorkerAPI, jsonrpc.ClientCloser, error) { - addr, headers, err := GetRawAPI(ctx, repo.Worker) - if err != nil { - return nil, nil, err - } - - return client.NewWorkerRPC(ctx.Context, addr, headers) -} - -func GetGatewayAPI(ctx *cli.Context) (api.GatewayAPI, jsonrpc.ClientCloser, error) { - addr, headers, err := GetRawAPI(ctx, repo.FullNode) - if err != nil { - return nil, nil, err - } - - return client.NewGatewayRPC(ctx.Context, addr, headers) -} - -func DaemonContext(cctx *cli.Context) context.Context { - if mtCtx, ok := cctx.App.Metadata[metadataTraceContext]; ok { - return mtCtx.(context.Context) - } - - return context.Background() -} - -// ReqContext returns context for cli execution. Calling it for the first time -// installs SIGTERM handler that will close returned context. -// Not safe for concurrent execution. -func ReqContext(cctx *cli.Context) context.Context { - tCtx := DaemonContext(cctx) - - ctx, done := context.WithCancel(tCtx) - sigChan := make(chan os.Signal, 2) - go func() { - <-sigChan - done() - }() - signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP) - - return ctx -} - var CommonCommands = []*cli.Command{ netCmd, authCmd, diff --git a/cli/disputer.go b/cli/disputer.go index 7fb0bbb479e..9830546e26f 100644 --- a/cli/disputer.go +++ b/cli/disputer.go @@ -3,6 +3,7 @@ package cli import ( "context" "fmt" + "github.com/filecoin-project/lotus/cli/util" "strconv" "time" @@ -65,9 +66,9 @@ var disputerMsgCmd = &cli.Command{ return nil } - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } @@ -146,13 +147,13 @@ var disputerStartCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) fromAddr, err := getSender(ctx, api, cctx.String("from")) if err != nil { diff --git a/cli/log.go b/cli/log.go index a4aeaad5c5a..82dbb3662ce 100644 --- a/cli/log.go +++ b/cli/log.go @@ -2,6 +2,7 @@ package cli import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -20,13 +21,13 @@ var logList = &cli.Command{ Name: "list", Usage: "List log systems", Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) systems, err := api.LogList(ctx) if err != nil { @@ -71,12 +72,12 @@ var logSetLevel = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("level is required") diff --git a/cli/mpool.go b/cli/mpool.go index d74c7c9bacf..1f7be47f59b 100644 --- a/cli/mpool.go +++ b/cli/mpool.go @@ -3,6 +3,7 @@ package cli import ( "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" stdbig "math/big" "sort" "strconv" @@ -59,13 +60,13 @@ var mpoolPending = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var toa, froma address.Address if tos := cctx.String("to"); tos != "" { @@ -146,7 +147,7 @@ var mpoolClear = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } @@ -160,7 +161,7 @@ var mpoolClear = &cli.Command{ local := cctx.Bool("local") - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) return api.MpoolClear(ctx, local) }, } @@ -169,13 +170,13 @@ var mpoolSub = &cli.Command{ Name: "sub", Usage: "Subscribe to mpool changes", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) sub, err := api.MpoolSub(ctx) if err != nil { @@ -212,13 +213,13 @@ var mpoolStat = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ts, err := api.ChainHead(ctx) if err != nil { @@ -384,13 +385,13 @@ var mpoolReplaceCmd = &cli.Command{ ArgsUsage: " | ", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var from address.Address var nonce uint64 @@ -527,13 +528,13 @@ var mpoolFindCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) pending, err := api.MpoolPending(ctx, types.EmptyTSK) if err != nil { @@ -601,13 +602,13 @@ var mpoolConfig = &cli.Command{ return cli.ShowCommandHelp(cctx, cctx.Command.Name) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() == 0 { cfg, err := api.MpoolGetConfig(ctx) @@ -647,13 +648,13 @@ var mpoolGasPerfCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msgs, err := api.MpoolPending(ctx, types.EmptyTSK) if err != nil { diff --git a/cli/multisig.go b/cli/multisig.go index f6caa6ee034..cd6ab1be40e 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -5,6 +5,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "reflect" "sort" "strconv" @@ -95,12 +96,12 @@ var msigCreateCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("multisigs must have at least one signer")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var addrs []address.Address for _, a := range cctx.Args().Slice() { @@ -195,12 +196,12 @@ var msigInspectCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must specify address of multisig to inspect")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) store := adt.WrapStore(ctx, cbor.NewCborStore(blockstore.NewAPIBlockstore(api))) @@ -364,12 +365,12 @@ var msigProposeCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must either pass three or five arguments")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -481,12 +482,12 @@ var msigApproveCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("usage: msig approve [ ]")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -598,12 +599,12 @@ var msigRemoveProposeCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must pass multisig address and signer address")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -676,12 +677,12 @@ var msigAddProposeCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must pass multisig address and signer address")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -743,12 +744,12 @@ var msigAddApproveCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must pass multisig address, proposer address, transaction id, new signer address, whether to increase threshold")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -825,12 +826,12 @@ var msigAddCancelCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must pass multisig address, transaction id, new signer address, whether to increase threshold")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -902,12 +903,12 @@ var msigSwapProposeCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must pass multisig address, old signer address, new signer address")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -974,12 +975,12 @@ var msigSwapApproveCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must pass multisig address, proposer address, transaction id, old signer address, new signer address")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -1056,12 +1057,12 @@ var msigSwapCancelCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must pass multisig address, transaction id, old signer address, new signer address")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -1133,12 +1134,12 @@ var msigLockProposeCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must pass multisig address, start epoch, unlock duration, and amount")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -1220,12 +1221,12 @@ var msigLockApproveCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must pass multisig address, proposer address, tx id, start epoch, unlock duration, and amount")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -1317,12 +1318,12 @@ var msigLockCancelCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must pass multisig address, tx id, start epoch, unlock duration, and amount")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -1415,12 +1416,12 @@ var msigVestedCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must pass multisig address")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -1471,12 +1472,12 @@ var msigProposeThresholdCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must pass multisig address and new threshold value")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msig, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { diff --git a/cli/net.go b/cli/net.go index 56f0bf5f98f..2dae7c6ab4b 100644 --- a/cli/net.go +++ b/cli/net.go @@ -3,6 +3,7 @@ package cli import ( "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "os" "sort" "strings" @@ -50,12 +51,12 @@ var NetPeers = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) peers, err := api.NetPeers(ctx) if err != nil { return err @@ -93,12 +94,12 @@ var netScores = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) scores, err := api.NetPubsubScores(ctx) if err != nil { return err @@ -126,12 +127,12 @@ var NetListen = &cli.Command{ Name: "listen", Usage: "List listen addresses", Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) addrs, err := api.NetAddrsListen(ctx) if err != nil { @@ -150,12 +151,12 @@ var netConnect = &cli.Command{ Usage: "Connect to a peer", ArgsUsage: "[peerMultiaddr|minerActorAddress]", Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) pis, err := addrutil.ParseAddresses(ctx, cctx.Args().Slice()) if err != nil { @@ -164,7 +165,7 @@ var netConnect = &cli.Command{ return err } - na, fc, err := GetFullNodeAPI(cctx) + na, fc, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } @@ -216,13 +217,13 @@ var NetId = &cli.Command{ Name: "id", Usage: "Get node identity", Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) pid, err := api.ID(ctx) if err != nil { @@ -249,13 +250,13 @@ var netFindPeer = &cli.Command{ return err } - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) addrs, err := api.NetFindPeer(ctx, pid) @@ -272,13 +273,13 @@ var NetReachability = &cli.Command{ Name: "reachability", Usage: "Print information about reachability from the internet", Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) i, err := api.NetAutoNatStatus(ctx) if err != nil { @@ -307,13 +308,13 @@ var NetBandwidthCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) bypeer := cctx.Bool("by-peer") byproto := cctx.Bool("by-protocol") @@ -403,12 +404,12 @@ var NetBlockAddPeer = &cli.Command{ Usage: "Block a peer", ArgsUsage: " ...", Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var peers []peer.ID for _, s := range cctx.Args().Slice() { @@ -429,12 +430,12 @@ var NetBlockAddIP = &cli.Command{ Usage: "Block an IP address", ArgsUsage: " ...", Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) return api.NetBlockAdd(ctx, atypes.NetBlockList{IPAddrs: cctx.Args().Slice()}) }, @@ -445,12 +446,12 @@ var NetBlockAddSubnet = &cli.Command{ Usage: "Block an IP subnet", ArgsUsage: " ...", Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) return api.NetBlockAdd(ctx, atypes.NetBlockList{IPSubnets: cctx.Args().Slice()}) }, @@ -471,12 +472,12 @@ var NetBlockRemovePeer = &cli.Command{ Usage: "Unblock a peer", ArgsUsage: " ...", Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var peers []peer.ID for _, s := range cctx.Args().Slice() { @@ -497,12 +498,12 @@ var NetBlockRemoveIP = &cli.Command{ Usage: "Unblock an IP address", ArgsUsage: " ...", Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) return api.NetBlockRemove(ctx, atypes.NetBlockList{IPAddrs: cctx.Args().Slice()}) }, @@ -513,12 +514,12 @@ var NetBlockRemoveSubnet = &cli.Command{ Usage: "Unblock an IP subnet", ArgsUsage: " ...", Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) return api.NetBlockRemove(ctx, atypes.NetBlockList{IPSubnets: cctx.Args().Slice()}) }, @@ -528,12 +529,12 @@ var NetBlockListCmd = &cli.Command{ Name: "list", Usage: "list connection gating rules", Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) acl, err := api.NetBlockList(ctx) if err != nil { diff --git a/cli/params.go b/cli/params.go index 05c0a4cda7d..5ea8dde13ab 100644 --- a/cli/params.go +++ b/cli/params.go @@ -3,6 +3,7 @@ package cli import ( "github.com/docker/go-units" paramfetch "github.com/filecoin-project/go-paramfetch" + "github.com/filecoin-project/lotus/cli/util" "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -23,7 +24,7 @@ var fetchParamCmd = &cli.Command{ } sectorSize := uint64(sectorSizeInt) - err = paramfetch.GetParams(ReqContext(cctx), build.ParametersJSON(), sectorSize) + err = paramfetch.GetParams(cliutil.ReqContext(cctx), build.ParametersJSON(), sectorSize) if err != nil { return xerrors.Errorf("fetching proof parameters: %w", err) } diff --git a/cli/paych.go b/cli/paych.go index 1d5e304c383..f8d9400fdad 100644 --- a/cli/paych.go +++ b/cli/paych.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/base64" "fmt" + "github.com/filecoin-project/lotus/cli/util" "io" "sort" "strings" @@ -66,13 +67,13 @@ var paychAddFundsCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("parsing amount failed: %s", err)) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) // Send a message to chain to create channel / add funds to existing // channel @@ -104,7 +105,7 @@ var paychStatusByFromToCmd = &cli.Command{ if cctx.Args().Len() != 2 { return ShowHelp(cctx, fmt.Errorf("must pass two arguments: ")) } - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) from, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { @@ -116,7 +117,7 @@ var paychStatusByFromToCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("failed to parse to address: %s", err)) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } @@ -140,14 +141,14 @@ var paychStatusCmd = &cli.Command{ if cctx.Args().Len() != 1 { return ShowHelp(cctx, fmt.Errorf("must pass an argument: ")) } - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ch, err := address.NewFromString(cctx.Args().Get(0)) if err != nil { return ShowHelp(cctx, fmt.Errorf("failed to parse channel address: %s", err)) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } @@ -222,13 +223,13 @@ var paychListCmd = &cli.Command{ Name: "list", Usage: "List all locally registered payment channels", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) chs, err := api.PaychList(ctx) if err != nil { @@ -256,13 +257,13 @@ var paychSettleCmd = &cli.Command{ return fmt.Errorf("failed to parse payment channel address: %s", err) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) mcid, err := api.PaychSettle(ctx, ch) if err != nil { @@ -296,13 +297,13 @@ var paychCloseCmd = &cli.Command{ return fmt.Errorf("failed to parse payment channel address: %s", err) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) mcid, err := api.PaychCollect(ctx, ch) if err != nil { @@ -363,13 +364,13 @@ var paychVoucherCreateCmd = &cli.Command{ lane := cctx.Int("lane") - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) v, err := api.PaychVoucherCreate(ctx, ch, types.BigInt(amt), uint64(lane)) if err != nil { @@ -409,13 +410,13 @@ var paychVoucherCheckCmd = &cli.Command{ return err } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if err := api.PaychVoucherCheckValid(ctx, ch, sv); err != nil { return err @@ -445,13 +446,13 @@ var paychVoucherAddCmd = &cli.Command{ return err } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) // TODO: allow passing proof bytes if _, err := api.PaychVoucherAdd(ctx, ch, sv, nil, types.NewInt(0)); err != nil { @@ -482,13 +483,13 @@ var paychVoucherListCmd = &cli.Command{ return err } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) vouchers, err := api.PaychVoucherList(ctx, ch) if err != nil { @@ -527,13 +528,13 @@ var paychVoucherBestSpendableCmd = &cli.Command{ return err } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) vouchersByLane, err := paychmgr.BestSpendableByLane(ctx, api, ch) if err != nil { @@ -603,13 +604,13 @@ var paychVoucherSubmitCmd = &cli.Command{ return err } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) mcid, err := api.PaychVoucherSubmit(ctx, ch, sv, nil, nil) if err != nil { diff --git a/cli/pprof.go b/cli/pprof.go index dccb97f9a9f..e9b1c94e17f 100644 --- a/cli/pprof.go +++ b/cli/pprof.go @@ -1,6 +1,7 @@ package cli import ( + "github.com/filecoin-project/lotus/cli/util" "io" "net/http" "os" @@ -32,7 +33,7 @@ var PprofGoroutines = &cli.Command{ if !ok { log.Errorf("repoType type does not match the type of repo.RepoType") } - ainfo, err := GetAPIInfo(cctx, t) + ainfo, err := cliutil.GetAPIInfo(cctx, t) if err != nil { return xerrors.Errorf("could not get API info: %w", err) } diff --git a/cli/send.go b/cli/send.go index daf73ccad1b..7ba702122cf 100644 --- a/cli/send.go +++ b/cli/send.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "errors" "fmt" + "github.com/filecoin-project/lotus/cli/util" "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -73,7 +74,7 @@ var sendCmd = &cli.Command{ } defer srv.Close() //nolint:errcheck - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var params SendParams params.To, err = address.NewFromString(cctx.Args().Get(0)) diff --git a/cli/state.go b/cli/state.go index df64c7ddf88..04aeec822a3 100644 --- a/cli/state.go +++ b/cli/state.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "html/template" "io" "io/ioutil" @@ -81,13 +82,13 @@ var stateMinerInfo = &cli.Command{ Usage: "Retrieve miner information", ArgsUsage: "[minerAddress]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must specify miner to get information for") @@ -224,13 +225,13 @@ var statePowerCmd = &cli.Command{ Usage: "Query network or miner power", ArgsUsage: "[ (optional)]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var maddr address.Address if cctx.Args().Present() { @@ -268,13 +269,13 @@ var stateSectorsCmd = &cli.Command{ Usage: "Query the sector set of a miner", ArgsUsage: "[minerAddress]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must specify miner to list sectors for") @@ -308,13 +309,13 @@ var stateActiveSectorsCmd = &cli.Command{ Usage: "Query the active sector set of a miner", ArgsUsage: "[minerAddress]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must specify miner to list sectors for") @@ -357,13 +358,13 @@ var stateExecTraceCmd = &cli.Command{ return fmt.Errorf("message cid was invalid: %s", err) } - capi, closer, err := GetFullNodeAPI(cctx) + capi, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msg, err := capi.ChainGetMessage(ctx, mcid) if err != nil { @@ -436,13 +437,13 @@ var stateReplayCmd = &cli.Command{ return fmt.Errorf("message cid was invalid: %s", err) } - fapi, closer, err := GetFullNodeAPI(cctx) + fapi, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) res, err := fapi.StateReplay(ctx, types.EmptyTSK, mcid) if err != nil { @@ -481,13 +482,13 @@ var stateGetDealSetCmd = &cli.Command{ Usage: "View on-chain deal info", ArgsUsage: "[dealId]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must specify deal ID") @@ -528,13 +529,13 @@ var stateListMinersCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ts, err := LoadTipSet(ctx, cctx, api) if err != nil { @@ -594,13 +595,13 @@ var stateListActorsCmd = &cli.Command{ Name: "list-actors", Usage: "list all actors in the network", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ts, err := LoadTipSet(ctx, cctx, api) if err != nil { @@ -625,13 +626,13 @@ var stateGetActorCmd = &cli.Command{ Usage: "Print actor information", ArgsUsage: "[actorrAddress]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must pass address of actor to get") @@ -676,13 +677,13 @@ var stateLookupIDCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must pass address of actor to get") @@ -720,13 +721,13 @@ var stateSectorSizeCmd = &cli.Command{ Usage: "Look up miners sector size", ArgsUsage: "[minerAddress]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must pass miner's address") @@ -757,13 +758,13 @@ var stateReadStateCmd = &cli.Command{ Usage: "View a json representation of an actors state", ArgsUsage: "[actorAddress]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must pass address of actor to get") @@ -816,13 +817,13 @@ var stateListMessagesCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var toa, froma address.Address if tos := cctx.String("to"); tos != "" { @@ -941,13 +942,13 @@ var stateComputeStateCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ts, err := LoadTipSet(ctx, cctx, api) if err != nil { @@ -1380,13 +1381,13 @@ var stateWaitMsgCmd = &cli.Command{ return fmt.Errorf("must specify message cid to wait for") } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msg, err := cid.Decode(cctx.Args().First()) if err != nil { @@ -1416,13 +1417,13 @@ var stateSearchMsgCmd = &cli.Command{ return fmt.Errorf("must specify message cid to search for") } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msg, err := cid.Decode(cctx.Args().First()) if err != nil { @@ -1510,13 +1511,13 @@ var stateCallCmd = &cli.Command{ return fmt.Errorf("must specify at least actor and method to invoke") } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) toa, err := address.NewFromString(cctx.Args().First()) if err != nil { @@ -1703,13 +1704,13 @@ var stateCircSupplyCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ts, err := LoadTipSet(ctx, cctx, api) if err != nil { @@ -1746,13 +1747,13 @@ var stateSectorCmd = &cli.Command{ Usage: "Get miner sector info", ArgsUsage: "[miner address] [sector number]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() != 2 { return xerrors.Errorf("expected 2 params") @@ -1831,13 +1832,13 @@ var stateMarketBalanceCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("must specify address to print market balance for")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ts, err := LoadTipSet(ctx, cctx, api) if err != nil { @@ -1869,13 +1870,13 @@ var stateNtwkVersionCmd = &cli.Command{ return ShowHelp(cctx, fmt.Errorf("doesn't expect any arguments")) } - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ts, err := LoadTipSet(ctx, cctx, api) if err != nil { diff --git a/cli/sync.go b/cli/sync.go index ff7d4bd6598..b1b02974724 100644 --- a/cli/sync.go +++ b/cli/sync.go @@ -3,6 +3,7 @@ package cli import ( "context" "fmt" + "github.com/filecoin-project/lotus/cli/util" "time" "github.com/filecoin-project/lotus/chain/types" @@ -32,12 +33,12 @@ var syncStatusCmd = &cli.Command{ Name: "status", Usage: "check sync status", Action: func(cctx *cli.Context) error { - apic, closer, err := GetFullNodeAPI(cctx) + apic, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) state, err := apic.SyncState(ctx) if err != nil { @@ -91,12 +92,12 @@ var syncWaitCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - napi, closer, err := GetFullNodeAPI(cctx) + napi, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) return SyncWait(ctx, napi, cctx.Bool("watch")) }, @@ -107,12 +108,12 @@ var syncMarkBadCmd = &cli.Command{ Usage: "Mark the given block as bad, will prevent syncing to a chain that contains it", ArgsUsage: "[blockCid]", Action: func(cctx *cli.Context) error { - napi, closer, err := GetFullNodeAPI(cctx) + napi, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must specify block cid to mark") @@ -138,12 +139,12 @@ var syncUnmarkBadCmd = &cli.Command{ }, ArgsUsage: "[blockCid]", Action: func(cctx *cli.Context) error { - napi, closer, err := GetFullNodeAPI(cctx) + napi, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Bool("all") { return napi.SyncUnmarkAllBad(ctx) @@ -167,12 +168,12 @@ var syncCheckBadCmd = &cli.Command{ Usage: "check if the given block was marked bad, and for what reason", ArgsUsage: "[blockCid]", Action: func(cctx *cli.Context) error { - napi, closer, err := GetFullNodeAPI(cctx) + napi, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must specify block cid to check") @@ -209,12 +210,12 @@ var syncCheckpointCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - napi, closer, err := GetFullNodeAPI(cctx) + napi, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var ts *types.TipSet diff --git a/cli/util/api.go b/cli/util/api.go new file mode 100644 index 00000000000..e09af245fb7 --- /dev/null +++ b/cli/util/api.go @@ -0,0 +1,271 @@ +package cliutil + +import ( + "context" + "fmt" + "github.com/filecoin-project/go-jsonrpc" + "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/api/client" + "github.com/filecoin-project/lotus/node/repo" + "github.com/mitchellh/go-homedir" + "github.com/urfave/cli/v2" + "golang.org/x/xerrors" + "net/http" + "net/url" + "os" + "os/signal" + "strings" + "syscall" +) + +const ( + metadataTraceContext = "traceContext" +) + +// The flag passed on the command line with the listen address of the API +// server (only used by the tests) +func flagForAPI(t repo.RepoType) string { + switch t { + case repo.FullNode: + return "api-url" + case repo.StorageMiner: + return "miner-api-url" + case repo.Worker: + return "worker-api-url" + default: + panic(fmt.Sprintf("Unknown repo type: %v", t)) + } +} + +func flagForRepo(t repo.RepoType) string { + switch t { + case repo.FullNode: + return "repo" + case repo.StorageMiner: + return "miner-repo" + case repo.Worker: + return "worker-repo" + default: + panic(fmt.Sprintf("Unknown repo type: %v", t)) + } +} + +func EnvForRepo(t repo.RepoType) string { + switch t { + case repo.FullNode: + return "FULLNODE_API_INFO" + case repo.StorageMiner: + return "MINER_API_INFO" + case repo.Worker: + return "WORKER_API_INFO" + default: + panic(fmt.Sprintf("Unknown repo type: %v", t)) + } +} + +// TODO remove after deprecation period +func envForRepoDeprecation(t repo.RepoType) string { + switch t { + case repo.FullNode: + return "FULLNODE_API_INFO" + case repo.StorageMiner: + return "STORAGE_API_INFO" + case repo.Worker: + return "WORKER_API_INFO" + default: + panic(fmt.Sprintf("Unknown repo type: %v", t)) + } +} + +func GetAPIInfo(ctx *cli.Context, t repo.RepoType) (APIInfo, error) { + // Check if there was a flag passed with the listen address of the API + // server (only used by the tests) + apiFlag := flagForAPI(t) + if ctx.IsSet(apiFlag) { + strma := ctx.String(apiFlag) + strma = strings.TrimSpace(strma) + + return APIInfo{Addr: strma}, nil + } + + envKey := EnvForRepo(t) + env, ok := os.LookupEnv(envKey) + if !ok { + // TODO remove after deprecation period + envKey = envForRepoDeprecation(t) + env, ok = os.LookupEnv(envKey) + if ok { + log.Warnf("Use deprecation env(%s) value, please use env(%s) instead.", envKey, EnvForRepo(t)) + } + } + if ok { + return ParseApiInfo(env), nil + } + + repoFlag := flagForRepo(t) + + p, err := homedir.Expand(ctx.String(repoFlag)) + if err != nil { + return APIInfo{}, xerrors.Errorf("could not expand home dir (%s): %w", repoFlag, err) + } + + r, err := repo.NewFS(p) + if err != nil { + return APIInfo{}, xerrors.Errorf("could not open repo at path: %s; %w", p, err) + } + + ma, err := r.APIEndpoint() + if err != nil { + return APIInfo{}, xerrors.Errorf("could not get api endpoint: %w", err) + } + + token, err := r.APIToken() + if err != nil { + log.Warnf("Couldn't load CLI token, capabilities may be limited: %v", err) + } + + return APIInfo{ + Addr: ma.String(), + Token: token, + }, nil +} + +func GetRawAPI(ctx *cli.Context, t repo.RepoType) (string, http.Header, error) { + ainfo, err := GetAPIInfo(ctx, t) + if err != nil { + return "", nil, xerrors.Errorf("could not get API info: %w", err) + } + + addr, err := ainfo.DialArgs() + if err != nil { + return "", nil, xerrors.Errorf("could not get DialArgs: %w", err) + } + + return addr, ainfo.AuthHeader(), nil +} + +func GetAPI(ctx *cli.Context) (api.Common, jsonrpc.ClientCloser, error) { + ti, ok := ctx.App.Metadata["repoType"] + if !ok { + log.Errorf("unknown repo type, are you sure you want to use GetAPI?") + ti = repo.FullNode + } + t, ok := ti.(repo.RepoType) + if !ok { + log.Errorf("repoType type does not match the type of repo.RepoType") + } + + if tn, ok := ctx.App.Metadata["testnode-storage"]; ok { + return tn.(api.StorageMiner), func() {}, nil + } + if tn, ok := ctx.App.Metadata["testnode-full"]; ok { + return tn.(api.FullNode), func() {}, nil + } + + addr, headers, err := GetRawAPI(ctx, t) + if err != nil { + return nil, nil, err + } + + return client.NewCommonRPC(ctx.Context, addr, headers) +} + +func GetFullNodeAPI(ctx *cli.Context) (api.FullNode, jsonrpc.ClientCloser, error) { + if tn, ok := ctx.App.Metadata["testnode-full"]; ok { + return tn.(api.FullNode), func() {}, nil + } + + addr, headers, err := GetRawAPI(ctx, repo.FullNode) + if err != nil { + return nil, nil, err + } + + return client.NewFullNodeRPC(ctx.Context, addr, headers) +} + +type GetStorageMinerOptions struct { + PreferHttp bool +} + +type GetStorageMinerOption func(*GetStorageMinerOptions) + +func StorageMinerUseHttp(opts *GetStorageMinerOptions) { + opts.PreferHttp = true +} + +func GetStorageMinerAPI(ctx *cli.Context, opts ...GetStorageMinerOption) (api.StorageMiner, jsonrpc.ClientCloser, error) { + var options GetStorageMinerOptions + for _, opt := range opts { + opt(&options) + } + + if tn, ok := ctx.App.Metadata["testnode-storage"]; ok { + return tn.(api.StorageMiner), func() {}, nil + } + + addr, headers, err := GetRawAPI(ctx, repo.StorageMiner) + if err != nil { + return nil, nil, err + } + + if options.PreferHttp { + u, err := url.Parse(addr) + if err != nil { + return nil, nil, xerrors.Errorf("parsing miner api URL: %w", err) + } + + switch u.Scheme { + case "ws": + u.Scheme = "http" + case "wss": + u.Scheme = "https" + } + + addr = u.String() + } + + return client.NewStorageMinerRPC(ctx.Context, addr, headers) +} + +func GetWorkerAPI(ctx *cli.Context) (api.WorkerAPI, jsonrpc.ClientCloser, error) { + addr, headers, err := GetRawAPI(ctx, repo.Worker) + if err != nil { + return nil, nil, err + } + + return client.NewWorkerRPC(ctx.Context, addr, headers) +} + +func GetGatewayAPI(ctx *cli.Context) (api.GatewayAPI, jsonrpc.ClientCloser, error) { + addr, headers, err := GetRawAPI(ctx, repo.FullNode) + if err != nil { + return nil, nil, err + } + + return client.NewGatewayRPC(ctx.Context, addr, headers) +} + +func DaemonContext(cctx *cli.Context) context.Context { + if mtCtx, ok := cctx.App.Metadata[metadataTraceContext]; ok { + return mtCtx.(context.Context) + } + + return context.Background() +} + +// ReqContext returns context for cli execution. Calling it for the first time +// installs SIGTERM handler that will close returned context. +// Not safe for concurrent execution. +func ReqContext(cctx *cli.Context) context.Context { + tCtx := DaemonContext(cctx) + + ctx, done := context.WithCancel(tCtx) + sigChan := make(chan os.Signal, 2) + go func() { + <-sigChan + done() + }() + signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP) + + return ctx +} diff --git a/cli/version.go b/cli/version.go index 1cdc9c561b0..74167dd11ec 100644 --- a/cli/version.go +++ b/cli/version.go @@ -2,6 +2,7 @@ package cli import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "github.com/urfave/cli/v2" ) @@ -10,13 +11,13 @@ var VersionCmd = &cli.Command{ Name: "version", Usage: "Print version", Action: func(cctx *cli.Context) error { - api, closer, err := GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) // TODO: print more useful things v, err := api.Version(ctx) diff --git a/cli/wait.go b/cli/wait.go index ca8cdce3f56..4492dbf7c2d 100644 --- a/cli/wait.go +++ b/cli/wait.go @@ -2,6 +2,7 @@ package cli import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "time" "github.com/urfave/cli/v2" @@ -12,7 +13,7 @@ var waitApiCmd = &cli.Command{ Usage: "Wait for lotus api to come online", Action: func(cctx *cli.Context) error { for i := 0; i < 30; i++ { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { fmt.Printf("Not online yet... (%s)\n", err) time.Sleep(time.Second) @@ -20,7 +21,7 @@ var waitApiCmd = &cli.Command{ } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) _, err = api.ID(ctx) if err != nil { diff --git a/cli/wallet.go b/cli/wallet.go index 802d85702e8..c570827c618 100644 --- a/cli/wallet.go +++ b/cli/wallet.go @@ -5,6 +5,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "io/ioutil" "os" "strings" @@ -44,12 +45,12 @@ var walletNew = &cli.Command{ Usage: "Generate a new key of the given type", ArgsUsage: "[bls|secp256k1 (default secp256k1)]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) t := cctx.Args().First() if t == "" { @@ -88,12 +89,12 @@ var walletList = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) addrs, err := api.WalletList(ctx) if err != nil { @@ -175,12 +176,12 @@ var walletBalance = &cli.Command{ Usage: "Get account balance", ArgsUsage: "[address]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var addr address.Address if cctx.Args().First() != "" { @@ -211,12 +212,12 @@ var walletGetDefault = &cli.Command{ Name: "default", Usage: "Get default wallet address", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) addr, err := api.WalletDefaultAddress(ctx) if err != nil { @@ -233,12 +234,12 @@ var walletSetDefault = &cli.Command{ Usage: "Set default wallet address", ArgsUsage: "[address]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must pass address to set as default") @@ -258,12 +259,12 @@ var walletExport = &cli.Command{ Usage: "export keys", ArgsUsage: "[address]", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must specify key to export") @@ -305,12 +306,12 @@ var walletImport = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var inpdata []byte if !cctx.Args().Present() || cctx.Args().First() == "-" { @@ -391,12 +392,12 @@ var walletSign = &cli.Command{ Usage: "sign a message", ArgsUsage: " ", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() || cctx.NArg() != 2 { return fmt.Errorf("must specify signing address and message to sign") @@ -432,12 +433,12 @@ var walletVerify = &cli.Command{ Usage: "verify the signature of a message", ArgsUsage: " ", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() || cctx.NArg() != 3 { return fmt.Errorf("must specify signing address, message, and signature to verify") @@ -484,12 +485,12 @@ var walletDelete = &cli.Command{ Usage: "Delete an account from the wallet", ArgsUsage: "
", Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() || cctx.NArg() != 1 { return fmt.Errorf("must specify address to delete") @@ -530,12 +531,12 @@ var walletMarketWithdraw = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return xerrors.Errorf("getting node API: %w", err) } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var wallet address.Address if cctx.String("wallet") != "" { @@ -635,12 +636,12 @@ var walletMarketAdd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return xerrors.Errorf("getting node API: %w", err) } defer closer() - ctx := ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) // Get amount param if !cctx.Args().Present() { diff --git a/cmd/chain-noise/main.go b/cmd/chain-noise/main.go index 37d623ce2af..f54243325f8 100644 --- a/cmd/chain-noise/main.go +++ b/cmd/chain-noise/main.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "github.com/filecoin-project/lotus/cli/util" "math/rand" "os" "time" @@ -11,8 +12,6 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" - "github.com/urfave/cli/v2" ) @@ -55,12 +54,12 @@ var runCmd = &cli.Command{ return err } - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) rate := cctx.Int("rate") if rate <= 0 { diff --git a/cmd/lotus-bench/main.go b/cmd/lotus-bench/main.go index 81aa09a75de..b008b6d5e68 100644 --- a/cmd/lotus-bench/main.go +++ b/cmd/lotus-bench/main.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "io/ioutil" "math/big" "math/rand" @@ -23,7 +24,6 @@ import ( "github.com/filecoin-project/go-address" paramfetch "github.com/filecoin-project/go-paramfetch" "github.com/filecoin-project/go-state-types/abi" - lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper/basicfs" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" @@ -243,7 +243,7 @@ var sealBenchCmd = &cli.Command{ // Only fetch parameters if actually needed skipc2 := c.Bool("skip-commit2") if !skipc2 { - if err := paramfetch.GetParams(lcli.ReqContext(c), build.ParametersJSON(), uint64(sectorSize)); err != nil { + if err := paramfetch.GetParams(cliutil.ReqContext(c), build.ParametersJSON(), uint64(sectorSize)); err != nil { return xerrors.Errorf("getting params: %w", err) } } @@ -738,7 +738,7 @@ var proveCmd = &cli.Command{ return xerrors.Errorf("unmarshalling input file: %w", err) } - if err := paramfetch.GetParams(lcli.ReqContext(c), build.ParametersJSON(), c2in.SectorSize); err != nil { + if err := paramfetch.GetParams(cliutil.ReqContext(c), build.ParametersJSON(), c2in.SectorSize); err != nil { return xerrors.Errorf("getting params: %w", err) } diff --git a/cmd/lotus-chainwatch/run.go b/cmd/lotus-chainwatch/run.go index 64f242755ab..be0108f6aa3 100644 --- a/cmd/lotus-chainwatch/run.go +++ b/cmd/lotus-chainwatch/run.go @@ -3,6 +3,7 @@ package main import ( "database/sql" "fmt" + "github.com/filecoin-project/lotus/cli/util" "net/http" _ "net/http/pprof" "os" @@ -16,7 +17,6 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/lotus/api" - lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/cmd/lotus-chainwatch/processor" "github.com/filecoin-project/lotus/cmd/lotus-chainwatch/scheduler" "github.com/filecoin-project/lotus/cmd/lotus-chainwatch/syncer" @@ -58,13 +58,13 @@ var runCmd = &cli.Command{ return err } } else { - api, closer, err = lcli.GetFullNodeAPI(cctx) + api, closer, err = cliutil.GetFullNodeAPI(cctx) if err != nil { return err } } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) v, err := api.Version(ctx) if err != nil { diff --git a/cmd/lotus-fountain/main.go b/cmd/lotus-fountain/main.go index 79f08aa8392..0562b498a06 100644 --- a/cmd/lotus-fountain/main.go +++ b/cmd/lotus-fountain/main.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "github.com/filecoin-project/lotus/cli/util" "html/template" "net" "net/http" @@ -18,7 +19,6 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" ) var log = logging.Logger("main") @@ -80,12 +80,12 @@ var runCmd = &cli.Command{ return err } - nodeApi, closer, err := lcli.GetFullNodeAPI(cctx) + nodeApi, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) v, err := nodeApi.Version(ctx) if err != nil { diff --git a/cmd/lotus-gateway/main.go b/cmd/lotus-gateway/main.go index 23b743d7392..711a035c16a 100644 --- a/cmd/lotus-gateway/main.go +++ b/cmd/lotus-gateway/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "github.com/filecoin-project/lotus/cli/util" "net" "net/http" "os" @@ -12,7 +13,6 @@ import ( "go.opencensus.io/tag" "github.com/filecoin-project/lotus/build" - lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/lib/lotuslog" "github.com/filecoin-project/lotus/metrics" @@ -71,7 +71,7 @@ var runCmd = &cli.Command{ Action: func(cctx *cli.Context) error { log.Info("Starting lotus gateway") - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -82,7 +82,7 @@ var runCmd = &cli.Command{ log.Fatalf("Cannot register the view: %v", err) } - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } diff --git a/cmd/lotus-health/main.go b/cmd/lotus-health/main.go index e8a32a71946..1b9aebc47f2 100644 --- a/cmd/lotus-health/main.go +++ b/cmd/lotus-health/main.go @@ -3,6 +3,7 @@ package main import ( "context" "errors" + "github.com/filecoin-project/lotus/cli/util" "os" "os/signal" "syscall" @@ -17,7 +18,6 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" ) type CidWindow [][]cid.Cid @@ -100,7 +100,7 @@ var watchHeadCmd = &cli.Command{ return err } defer closer() - ctx := lcli.ReqContext(c) + ctx := cliutil.ReqContext(c) go func() { for { @@ -250,7 +250,7 @@ func waitForSyncComplete(ctx context.Context, a api.FullNode, r int, t time.Dura */ func getFullNodeAPI(ctx *cli.Context, r int, t time.Duration) (api.FullNode, jsonrpc.ClientCloser, error) { for i := 0; i < r; i++ { - api, closer, err := lcli.GetFullNodeAPI(ctx) + api, closer, err := cliutil.GetFullNodeAPI(ctx) if err != nil && i == (r-1) { return nil, nil, err } diff --git a/cmd/lotus-seal-worker/cli.go b/cmd/lotus-seal-worker/cli.go index b1501fca745..97a8d8749f2 100644 --- a/cmd/lotus-seal-worker/cli.go +++ b/cmd/lotus-seal-worker/cli.go @@ -1,10 +1,9 @@ package main import ( + "github.com/filecoin-project/lotus/cli/util" "github.com/urfave/cli/v2" "golang.org/x/xerrors" - - lcli "github.com/filecoin-project/lotus/cli" ) var setCmd = &cli.Command{ @@ -18,13 +17,13 @@ var setCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetWorkerAPI(cctx) + api, closer, err := cliutil.GetWorkerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if err := api.SetEnabled(ctx, cctx.Bool("enabled")); err != nil { return xerrors.Errorf("SetEnabled: %w", err) @@ -38,13 +37,13 @@ var waitQuietCmd = &cli.Command{ Name: "wait-quiet", Usage: "Block until all running tasks exit", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetWorkerAPI(cctx) + api, closer, err := cliutil.GetWorkerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) return api.WaitQuiet(ctx) }, diff --git a/cmd/lotus-seal-worker/info.go b/cmd/lotus-seal-worker/info.go index 6d5c2d64ebc..002ee8c4fa9 100644 --- a/cmd/lotus-seal-worker/info.go +++ b/cmd/lotus-seal-worker/info.go @@ -2,13 +2,13 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "sort" "github.com/urfave/cli/v2" "golang.org/x/xerrors" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" ) @@ -16,13 +16,13 @@ var infoCmd = &cli.Command{ Name: "info", Usage: "Print worker info", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetWorkerAPI(cctx) + api, closer, err := cliutil.GetWorkerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ver, err := api.Version(ctx) if err != nil { diff --git a/cmd/lotus-seal-worker/main.go b/cmd/lotus-seal-worker/main.go index 8a17a10a3c6..a1dc6d16af1 100644 --- a/cmd/lotus-seal-worker/main.go +++ b/cmd/lotus-seal-worker/main.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "io/ioutil" "net" "net/http" @@ -30,7 +31,6 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/apistruct" "github.com/filecoin-project/lotus/build" - lcli "github.com/filecoin-project/lotus/cli" sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" "github.com/filecoin-project/lotus/extern/sector-storage/stores" @@ -177,13 +177,13 @@ var runCmd = &cli.Command{ } // Connect to storage-miner - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var nodeApi api.StorageMiner var closer func() var err error for { - nodeApi, closer, err = lcli.GetStorageMinerAPI(cctx, lcli.StorageMinerUseHttp) + nodeApi, closer, err = cliutil.GetStorageMinerAPI(cctx, cliutil.StorageMinerUseHttp) if err == nil { _, err = nodeApi.Version(ctx) if err == nil { @@ -356,7 +356,7 @@ var runCmd = &cli.Command{ } // Setup remote sector store - sminfo, err := lcli.GetAPIInfo(cctx, repo.StorageMiner) + sminfo, err := cliutil.GetAPIInfo(cctx, repo.StorageMiner) if err != nil { return xerrors.Errorf("could not get api info: %w", err) } @@ -442,7 +442,7 @@ var runCmd = &cli.Command{ return xerrors.Errorf("setting api endpoint: %w", err) } - ainfo, err := lcli.GetAPIInfo(cctx, repo.StorageMiner) + ainfo, err := cliutil.GetAPIInfo(cctx, repo.StorageMiner) if err != nil { return xerrors.Errorf("could not get miner API info: %w", err) } diff --git a/cmd/lotus-seal-worker/storage.go b/cmd/lotus-seal-worker/storage.go index 39cd3ad5afb..e2104ba9558 100644 --- a/cmd/lotus-seal-worker/storage.go +++ b/cmd/lotus-seal-worker/storage.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "github.com/filecoin-project/lotus/cli/util" "io/ioutil" "os" "path/filepath" @@ -11,7 +12,6 @@ import ( "github.com/urfave/cli/v2" "golang.org/x/xerrors" - lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/extern/sector-storage/stores" ) @@ -48,12 +48,12 @@ var storageAttachCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetWorkerAPI(cctx) + nodeApi, closer, err := cliutil.GetWorkerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return xerrors.Errorf("must specify storage path to attach") diff --git a/cmd/lotus-seal-worker/tasks.go b/cmd/lotus-seal-worker/tasks.go index bafd9895158..0266f90445d 100644 --- a/cmd/lotus-seal-worker/tasks.go +++ b/cmd/lotus-seal-worker/tasks.go @@ -2,13 +2,13 @@ package main import ( "context" + "github.com/filecoin-project/lotus/cli/util" "strings" "github.com/urfave/cli/v2" "golang.org/x/xerrors" "github.com/filecoin-project/lotus/api" - lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" ) @@ -69,13 +69,13 @@ func taskAction(tf func(a api.WorkerAPI, ctx context.Context, tt sealtasks.TaskT return xerrors.Errorf("unknown task type '%s'", cctx.Args().First()) } - api, closer, err := lcli.GetWorkerAPI(cctx) + api, closer, err := cliutil.GetWorkerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) return tf(api, ctx, tt) } diff --git a/cmd/lotus-shed/balances.go b/cmd/lotus-shed/balances.go index 8c5bfefb8d6..1a32bbece6b 100644 --- a/cmd/lotus-shed/balances.go +++ b/cmd/lotus-shed/balances.go @@ -4,6 +4,7 @@ import ( "context" "encoding/csv" "fmt" + "github.com/filecoin-project/lotus/cli/util" "io" "os" "strconv" @@ -80,13 +81,13 @@ var chainBalanceCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ts, err := lcli.LoadTipSet(ctx, cctx, api) if err != nil { @@ -545,13 +546,13 @@ var fillBalancesCmd = &cli.Command{ Description: "fill out balances for addresses on dates in given spreadsheet", Flags: []cli.Flag{}, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) dates, addrs, err := parseCsv(cctx.Args().First()) if err != nil { diff --git a/cmd/lotus-shed/blockmsgid.go b/cmd/lotus-shed/blockmsgid.go index 85b786ec0e2..9b532ee9275 100644 --- a/cmd/lotus-shed/blockmsgid.go +++ b/cmd/lotus-shed/blockmsgid.go @@ -3,6 +3,7 @@ package main import ( "encoding/base64" "fmt" + "github.com/filecoin-project/lotus/cli/util" blake2b "github.com/minio/blake2b-simd" "github.com/urfave/cli/v2" @@ -10,7 +11,6 @@ import ( "github.com/ipfs/go-cid" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" ) var blockmsgidCmd = &cli.Command{ @@ -18,13 +18,13 @@ var blockmsgidCmd = &cli.Command{ Usage: "Print a block's pubsub message ID", ArgsUsage: " ...", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) for _, arg := range cctx.Args().Slice() { blkcid, err := cid.Decode(arg) diff --git a/cmd/lotus-shed/consensus.go b/cmd/lotus-shed/consensus.go index 1fe7756c1fa..c1d491eba1f 100644 --- a/cmd/lotus-shed/consensus.go +++ b/cmd/lotus-shed/consensus.go @@ -14,7 +14,6 @@ import ( "github.com/filecoin-project/lotus/api/client" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" cliutil "github.com/filecoin-project/lotus/cli/util" "github.com/libp2p/go-libp2p-core/peer" "github.com/multiformats/go-multiaddr" @@ -95,7 +94,7 @@ var consensusCheckCmd = &cli.Command{ } var nodes []*consensusItem - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) for { strma, errR := input.ReadString('\n') diff --git a/cmd/lotus-shed/election.go b/cmd/lotus-shed/election.go index ffe30d16367..c8948bc2ad8 100644 --- a/cmd/lotus-shed/election.go +++ b/cmd/lotus-shed/election.go @@ -3,10 +3,10 @@ package main import ( "encoding/binary" "fmt" + "github.com/filecoin-project/lotus/cli/util" "math/rand" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" "github.com/urfave/cli/v2" "golang.org/x/xerrors" ) @@ -35,7 +35,7 @@ var electionRunDummy = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) minerPow, err := types.BigFromString(cctx.String("miner-power")) if err != nil { return xerrors.Errorf("decoding miner-power: %w", err) diff --git a/cmd/lotus-shed/frozen-miners.go b/cmd/lotus-shed/frozen-miners.go index 6b843f0d6ba..380eaf9ef01 100644 --- a/cmd/lotus-shed/frozen-miners.go +++ b/cmd/lotus-shed/frozen-miners.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "github.com/filecoin-project/go-state-types/abi" lcli "github.com/filecoin-project/lotus/cli" @@ -24,12 +25,12 @@ var frozenMinersCmd = &cli.Command{ }, }, Action: func(c *cli.Context) error { - api, acloser, err := lcli.GetFullNodeAPI(c) + api, acloser, err := cliutil.GetFullNodeAPI(c) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(c) + ctx := cliutil.ReqContext(c) ts, err := lcli.LoadTipSet(ctx, c, api) if err != nil { diff --git a/cmd/lotus-shed/ledger.go b/cmd/lotus-shed/ledger.go index 8d42b0e55c8..7b147f55235 100644 --- a/cmd/lotus-shed/ledger.go +++ b/cmd/lotus-shed/ledger.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "strconv" "strings" @@ -15,7 +16,6 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/types" ledgerwallet "github.com/filecoin-project/lotus/chain/wallet/ledger" - lcli "github.com/filecoin-project/lotus/cli" ) var ledgerCmd = &cli.Command{ @@ -44,7 +44,7 @@ var ledgerListAddressesCmd = &cli.Command{ Action: func(cctx *cli.Context) error { var api api.FullNode if cctx.Bool("print-balances") { - a, closer, err := lcli.GetFullNodeAPI(cctx) + a, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } @@ -53,7 +53,7 @@ var ledgerListAddressesCmd = &cli.Command{ defer closer() } - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) fl, err := ledgerfil.FindLedgerFilecoinApp() if err != nil { diff --git a/cmd/lotus-shed/mempool-stats.go b/cmd/lotus-shed/mempool-stats.go index bc4a801f0eb..a136a95da55 100644 --- a/cmd/lotus-shed/mempool-stats.go +++ b/cmd/lotus-shed/mempool-stats.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "net/http" "sort" "time" @@ -19,7 +20,6 @@ import ( "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" ) var ( @@ -97,13 +97,13 @@ var mpoolStatsCmd = &cli.Command{ } }() - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) updates, err := api.MpoolSub(ctx) if err != nil { diff --git a/cmd/lotus-shed/mpool.go b/cmd/lotus-shed/mpool.go index d3660db6958..02c26819b53 100644 --- a/cmd/lotus-shed/mpool.go +++ b/cmd/lotus-shed/mpool.go @@ -2,10 +2,10 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" "github.com/urfave/cli/v2" ) @@ -27,13 +27,13 @@ var minerSelectMsgsCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) head, err := api.ChainHead(ctx) if err != nil { diff --git a/cmd/lotus-shed/msg.go b/cmd/lotus-shed/msg.go index 63cfc86b99f..8423b84fa94 100644 --- a/cmd/lotus-shed/msg.go +++ b/cmd/lotus-shed/msg.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "github.com/fatih/color" @@ -128,13 +129,13 @@ func printMessage(cctx *cli.Context, msg *types.Message) error { fmt.Println("Max Fees:", types.FIL(msg.RequiredFunds())) fmt.Println("Max Total Cost:", types.FIL(big.Add(msg.RequiredFunds(), msg.Value))) - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) toact, err := api.StateGetActor(ctx, msg.To, types.EmptyTSK) if err != nil { @@ -263,13 +264,13 @@ func messageFromBytes(cctx *cli.Context, msgb []byte) (types.ChainMsg, error) { } func messageFromCID(cctx *cli.Context, c cid.Cid) (types.ChainMsg, error) { - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return nil, err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msgb, err := api.ChainReadObj(ctx, c) if err != nil { diff --git a/cmd/lotus-shed/nonce-fix.go b/cmd/lotus-shed/nonce-fix.go index 8102fd8a93b..b7003aaa3fc 100644 --- a/cmd/lotus-shed/nonce-fix.go +++ b/cmd/lotus-shed/nonce-fix.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "math" "github.com/filecoin-project/go-address" @@ -10,7 +11,6 @@ import ( "github.com/urfave/cli/v2" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" ) var noncefix = &cli.Command{ @@ -40,13 +40,13 @@ var noncefix = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) addr, err := address.NewFromString(cctx.String("addr")) if err != nil { diff --git a/cmd/lotus-shed/params.go b/cmd/lotus-shed/params.go index 3f7e7b6fb7e..b4b286eebf0 100644 --- a/cmd/lotus-shed/params.go +++ b/cmd/lotus-shed/params.go @@ -3,7 +3,7 @@ package main import ( "github.com/docker/go-units" paramfetch "github.com/filecoin-project/go-paramfetch" - lcli "github.com/filecoin-project/lotus/cli" + "github.com/filecoin-project/lotus/cli/util" "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -25,7 +25,7 @@ var fetchParamCmd = &cli.Command{ return err } sectorSize := uint64(sectorSizeInt) - err = paramfetch.GetParams(lcli.ReqContext(cctx), build.ParametersJSON(), sectorSize) + err = paramfetch.GetParams(cliutil.ReqContext(cctx), build.ParametersJSON(), sectorSize) if err != nil { return xerrors.Errorf("fetching proof parameters: %w", err) } diff --git a/cmd/lotus-shed/postfind.go b/cmd/lotus-shed/postfind.go index 83006fd09fb..170828f277c 100644 --- a/cmd/lotus-shed/postfind.go +++ b/cmd/lotus-shed/postfind.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" @@ -36,12 +37,12 @@ var postFindCmd = &cli.Command{ }, }, Action: func(c *cli.Context) error { - api, acloser, err := lcli.GetFullNodeAPI(c) + api, acloser, err := cliutil.GetFullNodeAPI(c) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(c) + ctx := cliutil.ReqContext(c) verbose := c.Bool("verbose") withpower := c.Bool("withpower") diff --git a/cmd/lotus-shed/rpc.go b/cmd/lotus-shed/rpc.go index fe81e5a62b2..efe2d9a954c 100644 --- a/cmd/lotus-shed/rpc.go +++ b/cmd/lotus-shed/rpc.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "io" "io/ioutil" "net/http" @@ -35,7 +36,7 @@ var rpcCmd = &cli.Command{ rt = repo.StorageMiner } - addr, headers, err := lcli.GetRawAPI(cctx, rt) + addr, headers, err := cliutil.GetRawAPI(cctx, rt) if err != nil { return err } @@ -54,7 +55,7 @@ var rpcCmd = &cli.Command{ addr = u.String() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ctx, cancel := context.WithCancel(ctx) defer cancel() afmt := lcli.NewAppFmt(cctx.App) diff --git a/cmd/lotus-shed/sectors.go b/cmd/lotus-shed/sectors.go index 64f3faf799b..f5576e1af83 100644 --- a/cmd/lotus-shed/sectors.go +++ b/cmd/lotus-shed/sectors.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "strconv" "golang.org/x/xerrors" @@ -16,7 +17,6 @@ import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" ) var sectorsCmd = &cli.Command{ @@ -48,19 +48,19 @@ var terminateSectorCmd = &cli.Command{ return fmt.Errorf("this is a command for advanced users, only use it if you are sure of what you are doing") } - nodeApi, closer, err := lcli.GetFullNodeAPI(cctx) + nodeApi, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetStorageMinerAPI(cctx) + api, acloser, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) maddr, err := api.ActorAddress(ctx) if err != nil { @@ -152,19 +152,19 @@ var terminateSectorPenaltyEstimationCmd = &cli.Command{ return fmt.Errorf("at least one sector must be specified") } - nodeApi, closer, err := lcli.GetFullNodeAPI(cctx) + nodeApi, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetStorageMinerAPI(cctx) + api, acloser, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) maddr, err := api.ActorAddress(ctx) if err != nil { diff --git a/cmd/lotus-shed/sr2-dealstats-rollup.go b/cmd/lotus-shed/sr2-dealstats-rollup.go index a2c6d03d936..8b2c680fbce 100644 --- a/cmd/lotus-shed/sr2-dealstats-rollup.go +++ b/cmd/lotus-shed/sr2-dealstats-rollup.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/filecoin-project/lotus/cli/util" "io" "net/http" "os" @@ -13,7 +14,6 @@ import ( "github.com/Jeffail/gabs" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - lcli "github.com/filecoin-project/lotus/cli" "github.com/ipfs/go-cid" "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -115,7 +115,7 @@ var rollupDealStatsCmd = &cli.Command{ return fmt.Errorf("creation of destination '%s' failed: %s", outDirName, err) } - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) projListName := cctx.Args().Get(1) var projListFh *os.File @@ -208,7 +208,7 @@ var rollupDealStatsCmd = &cli.Command{ } defer outUnfilteredStatsFd.Close() //nolint:errcheck - api, apiCloser, err := lcli.GetFullNodeAPI(cctx) + api, apiCloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } diff --git a/cmd/lotus-shed/stateroot-stats.go b/cmd/lotus-shed/stateroot-stats.go index 023f782bdd1..78d9f3bc370 100644 --- a/cmd/lotus-shed/stateroot-stats.go +++ b/cmd/lotus-shed/stateroot-stats.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "sort" "github.com/multiformats/go-multihash" @@ -43,13 +44,13 @@ var staterootDiffsCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ts, err := lcli.LoadTipSet(ctx, cctx, api) if err != nil { @@ -121,13 +122,13 @@ var staterootStatCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ts, err := lcli.LoadTipSet(ctx, cctx, api) if err != nil { diff --git a/cmd/lotus-shed/sync.go b/cmd/lotus-shed/sync.go index 65d2b6d6f50..d3e8539612e 100644 --- a/cmd/lotus-shed/sync.go +++ b/cmd/lotus-shed/sync.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "strconv" "github.com/filecoin-project/go-state-types/big" @@ -15,7 +16,6 @@ import ( "github.com/ipfs/go-cid" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" "github.com/urfave/cli/v2" ) @@ -33,13 +33,13 @@ var syncValidateCmd = &cli.Command{ Name: "validate", Usage: "checks whether a provided tipset is valid", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() < 1 { fmt.Println("usage: ...") @@ -85,13 +85,13 @@ var syncScrapePowerCmd = &cli.Command{ return nil } - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() < 1 { fmt.Println("usage: ...") diff --git a/cmd/lotus-shed/verifreg.go b/cmd/lotus-shed/verifreg.go index 426827ad265..ee5fe250818 100644 --- a/cmd/lotus-shed/verifreg.go +++ b/cmd/lotus-shed/verifreg.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "github.com/filecoin-project/go-state-types/big" @@ -19,7 +20,6 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin/verifreg" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" cbor "github.com/ipfs/go-ipld-cbor" ) @@ -67,12 +67,12 @@ var verifRegAddVerifierCmd = &cli.Command{ return err } - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) vrk, err := api.StateVerifiedRegistryRootKey(ctx, types.EmptyTSK) if err != nil { @@ -140,12 +140,12 @@ var verifRegVerifyClientCmd = &cli.Command{ return err } - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) msg := &types.Message{ To: verifreg.Address, @@ -178,12 +178,12 @@ var verifRegListVerifiersCmd = &cli.Command{ Name: "list-verifiers", Usage: "list all verifiers", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) act, err := api.StateGetActor(ctx, verifreg.Address, types.EmptyTSK) if err != nil { @@ -208,12 +208,12 @@ var verifRegListClientsCmd = &cli.Command{ Name: "list-clients", Usage: "list all verified clients", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) act, err := api.StateGetActor(ctx, verifreg.Address, types.EmptyTSK) if err != nil { @@ -247,12 +247,12 @@ var verifRegCheckClientCmd = &cli.Command{ return err } - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) dcap, err := api.StateVerifiedClientStatus(ctx, caddr, types.EmptyTSK) if err != nil { @@ -281,12 +281,12 @@ var verifRegCheckVerifierCmd = &cli.Command{ return err } - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) head, err := api.ChainHead(ctx) if err != nil { diff --git a/cmd/lotus-stats/main.go b/cmd/lotus-stats/main.go index b4c13ea8c26..efa95546b22 100644 --- a/cmd/lotus-stats/main.go +++ b/cmd/lotus-stats/main.go @@ -2,10 +2,10 @@ package main import ( "context" + "github.com/filecoin-project/lotus/cli/util" "os" "github.com/filecoin-project/lotus/build" - lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/tools/stats" logging "github.com/ipfs/go-log/v2" @@ -142,7 +142,7 @@ var runCmd = &cli.Command{ height = h } - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } diff --git a/cmd/lotus-storage-miner/actor.go b/cmd/lotus-storage-miner/actor.go index cd388149511..6f458d396cb 100644 --- a/cmd/lotus-storage-miner/actor.go +++ b/cmd/lotus-storage-miner/actor.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "os" "strings" @@ -25,7 +26,6 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/lib/tablewriter" ) @@ -55,19 +55,19 @@ var actorSetAddrsCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeAPI, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeAPI, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var addrs []abi.Multiaddrs for _, a := range cctx.Args().Slice() { @@ -132,19 +132,19 @@ var actorSetPeeridCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeAPI, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeAPI, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) pid, err := peer.Decode(cctx.Args().Get(0)) if err != nil { @@ -191,19 +191,19 @@ var actorWithdrawCmd = &cli.Command{ Usage: "withdraw available balance", ArgsUsage: "[amount (FIL)]", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) maddr, err := nodeApi.ActorAddress(ctx) if err != nil { @@ -269,19 +269,19 @@ var actorRepayDebtCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) maddr, err := nodeApi.ActorAddress(ctx) if err != nil { @@ -381,19 +381,19 @@ var actorControlList = &cli.Command{ Action: func(cctx *cli.Context) error { color.NoColor = !cctx.Bool("color") - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) maddr, err := nodeApi.ActorAddress(ctx) if err != nil { @@ -519,19 +519,19 @@ var actorControlSet = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) maddr, err := nodeApi.ActorAddress(ctx) if err != nil { @@ -641,19 +641,19 @@ var actorSetOwnerCmd = &cli.Command{ return fmt.Errorf("must pass new owner address and sender address") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) na, err := address.NewFromString(cctx.Args().First()) if err != nil { @@ -741,19 +741,19 @@ var actorProposeChangeWorker = &cli.Command{ return fmt.Errorf("must pass address of new worker address") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) na, err := address.NewFromString(cctx.Args().First()) if err != nil { @@ -856,19 +856,19 @@ var actorConfirmChangeWorker = &cli.Command{ return fmt.Errorf("must pass address of new worker address") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) na, err := address.NewFromString(cctx.Args().First()) if err != nil { diff --git a/cmd/lotus-storage-miner/backup.go b/cmd/lotus-storage-miner/backup.go index cf8c9f9125c..2772597686d 100644 --- a/cmd/lotus-storage-miner/backup.go +++ b/cmd/lotus-storage-miner/backup.go @@ -1,6 +1,7 @@ package main import ( + "github.com/filecoin-project/lotus/cli/util" "github.com/urfave/cli/v2" "github.com/filecoin-project/go-jsonrpc" @@ -10,5 +11,5 @@ import ( ) var backupCmd = lcli.BackupCmd(FlagMinerRepo, repo.StorageMiner, func(cctx *cli.Context) (lcli.BackupAPI, jsonrpc.ClientCloser, error) { - return lcli.GetStorageMinerAPI(cctx) + return cliutil.GetStorageMinerAPI(cctx) }) diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index cf39e5516da..6705b094e2d 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "github.com/filecoin-project/lotus/cli/util" "sort" "time" @@ -23,7 +24,6 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" ) var infoCmd = &cli.Command{ @@ -44,19 +44,19 @@ var infoCmd = &cli.Command{ func infoCmdAct(cctx *cli.Context) error { color.NoColor = !cctx.Bool("color") - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) fmt.Print("Chain: ") diff --git a/cmd/lotus-storage-miner/info_all.go b/cmd/lotus-storage-miner/info_all.go index 408f9b5c750..ac2a309256a 100644 --- a/cmd/lotus-storage-miner/info_all.go +++ b/cmd/lotus-storage-miner/info_all.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "github.com/filecoin-project/lotus/cli/util" "sort" "github.com/urfave/cli/v2" @@ -16,20 +17,20 @@ var infoAllCmd = &cli.Command{ Name: "all", Usage: "dump all related miner info", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() _ = api - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) // Top-level info diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index 13f946d78eb..b513f2794a2 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -7,6 +7,7 @@ import ( "encoding/binary" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "io/ioutil" "os" "path/filepath" @@ -139,7 +140,7 @@ var initCmd = &cli.Command{ log.Info("will attempt to symlink to imported sectors") } - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) log.Info("Checking proof parameters") @@ -149,7 +150,7 @@ var initCmd = &cli.Command{ log.Info("Trying to connect to full node RPC") - api, closer, err := lcli.GetFullNodeAPI(cctx) // TODO: consider storing full node address in config + api, closer, err := cliutil.GetFullNodeAPI(cctx) // TODO: consider storing full node address in config if err != nil { return err } diff --git a/cmd/lotus-storage-miner/init_restore.go b/cmd/lotus-storage-miner/init_restore.go index 9591129b8d6..6d008a4777b 100644 --- a/cmd/lotus-storage-miner/init_restore.go +++ b/cmd/lotus-storage-miner/init_restore.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/json" + "github.com/filecoin-project/lotus/cli/util" "io/ioutil" "os" @@ -53,7 +54,7 @@ var initRestoreCmd = &cli.Command{ log.Info("Trying to connect to full node RPC") - api, closer, err := lcli.GetFullNodeAPI(cctx) // TODO: consider storing full node address in config + api, closer, err := cliutil.GetFullNodeAPI(cctx) // TODO: consider storing full node address in config if err != nil { return err } @@ -61,7 +62,7 @@ var initRestoreCmd = &cli.Command{ log.Info("Checking full node version") - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) v, err := api.Version(ctx) if err != nil { diff --git a/cmd/lotus-storage-miner/market.go b/cmd/lotus-storage-miner/market.go index f46ad32bfa8..7fd58bd8c08 100644 --- a/cmd/lotus-storage-miner/market.go +++ b/cmd/lotus-storage-miner/market.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "github.com/filecoin-project/lotus/cli/util" "io" "os" "path/filepath" @@ -72,18 +73,18 @@ var storageDealSelectionShowCmd = &cli.Command{ Name: "list", Usage: "List storage deal proposal selection criteria", Action: func(cctx *cli.Context) error { - smapi, closer, err := lcli.GetStorageMinerAPI(cctx) + smapi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - onlineOk, err := smapi.DealsConsiderOnlineStorageDeals(lcli.DaemonContext(cctx)) + onlineOk, err := smapi.DealsConsiderOnlineStorageDeals(cliutil.DaemonContext(cctx)) if err != nil { return err } - offlineOk, err := smapi.DealsConsiderOfflineStorageDeals(lcli.DaemonContext(cctx)) + offlineOk, err := smapi.DealsConsiderOfflineStorageDeals(cliutil.DaemonContext(cctx)) if err != nil { return err } @@ -99,28 +100,28 @@ var storageDealSelectionResetCmd = &cli.Command{ Name: "reset", Usage: "Reset storage deal proposal selection criteria to default values", Action: func(cctx *cli.Context) error { - smapi, closer, err := lcli.GetStorageMinerAPI(cctx) + smapi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - err = smapi.DealsSetConsiderOnlineStorageDeals(lcli.DaemonContext(cctx), true) + err = smapi.DealsSetConsiderOnlineStorageDeals(cliutil.DaemonContext(cctx), true) if err != nil { return err } - err = smapi.DealsSetConsiderOfflineStorageDeals(lcli.DaemonContext(cctx), true) + err = smapi.DealsSetConsiderOfflineStorageDeals(cliutil.DaemonContext(cctx), true) if err != nil { return err } - err = smapi.DealsSetConsiderVerifiedStorageDeals(lcli.DaemonContext(cctx), true) + err = smapi.DealsSetConsiderVerifiedStorageDeals(cliutil.DaemonContext(cctx), true) if err != nil { return err } - err = smapi.DealsSetConsiderUnverifiedStorageDeals(lcli.DaemonContext(cctx), true) + err = smapi.DealsSetConsiderUnverifiedStorageDeals(cliutil.DaemonContext(cctx), true) if err != nil { return err } @@ -147,35 +148,35 @@ var storageDealSelectionRejectCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - smapi, closer, err := lcli.GetStorageMinerAPI(cctx) + smapi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() if cctx.Bool("online") { - err = smapi.DealsSetConsiderOnlineStorageDeals(lcli.DaemonContext(cctx), false) + err = smapi.DealsSetConsiderOnlineStorageDeals(cliutil.DaemonContext(cctx), false) if err != nil { return err } } if cctx.Bool("offline") { - err = smapi.DealsSetConsiderOfflineStorageDeals(lcli.DaemonContext(cctx), false) + err = smapi.DealsSetConsiderOfflineStorageDeals(cliutil.DaemonContext(cctx), false) if err != nil { return err } } if cctx.Bool("verified") { - err = smapi.DealsSetConsiderVerifiedStorageDeals(lcli.DaemonContext(cctx), false) + err = smapi.DealsSetConsiderVerifiedStorageDeals(cliutil.DaemonContext(cctx), false) if err != nil { return err } } if cctx.Bool("unverified") { - err = smapi.DealsSetConsiderUnverifiedStorageDeals(lcli.DaemonContext(cctx), false) + err = smapi.DealsSetConsiderUnverifiedStorageDeals(cliutil.DaemonContext(cctx), false) if err != nil { return err } @@ -212,9 +213,9 @@ var setAskCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - ctx := lcli.DaemonContext(cctx) + ctx := cliutil.DaemonContext(cctx) - api, closer, err := lcli.GetStorageMinerAPI(cctx) + api, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -280,15 +281,15 @@ var getAskCmd = &cli.Command{ Usage: "Print the miner's ask", Flags: []cli.Flag{}, Action: func(cctx *cli.Context) error { - ctx := lcli.DaemonContext(cctx) + ctx := cliutil.DaemonContext(cctx) - fnapi, closer, err := lcli.GetFullNodeAPI(cctx) + fnapi, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - smapi, closer, err := lcli.GetStorageMinerAPI(cctx) + smapi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -351,13 +352,13 @@ var dealsImportDataCmd = &cli.Command{ Usage: "Manually import data for a deal", ArgsUsage: " ", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + api, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.DaemonContext(cctx) + ctx := cliutil.DaemonContext(cctx) if cctx.Args().Len() < 2 { return fmt.Errorf("must specify proposal CID and file path") @@ -389,13 +390,13 @@ var dealsListCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + api, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.DaemonContext(cctx) + ctx := cliutil.DaemonContext(cctx) deals, err := api.MarketListIncompleteDeals(ctx) if err != nil { @@ -493,13 +494,13 @@ var getBlocklistCmd = &cli.Command{ &CidBaseFlag, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + api, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - blocklist, err := api.DealsPieceCidBlocklist(lcli.DaemonContext(cctx)) + blocklist, err := api.DealsPieceCidBlocklist(cliutil.DaemonContext(cctx)) if err != nil { return err } @@ -523,7 +524,7 @@ var setBlocklistCmd = &cli.Command{ ArgsUsage: "[ (optional, will read from stdin if omitted)]", Flags: []cli.Flag{}, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + api, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -560,7 +561,7 @@ var setBlocklistCmd = &cli.Command{ return err } - return api.DealsSetPieceCidBlocklist(lcli.DaemonContext(cctx), blocklist) + return api.DealsSetPieceCidBlocklist(cliutil.DaemonContext(cctx), blocklist) }, } @@ -569,13 +570,13 @@ var resetBlocklistCmd = &cli.Command{ Usage: "Remove all entries from the miner's piece CID blocklist", Flags: []cli.Flag{}, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + api, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - return api.DealsSetPieceCidBlocklist(lcli.DaemonContext(cctx), []cid.Cid{}) + return api.DealsSetPieceCidBlocklist(cliutil.DaemonContext(cctx), []cid.Cid{}) }, } @@ -584,12 +585,12 @@ var setSealDurationCmd = &cli.Command{ Usage: "Set the expected time, in minutes, that you expect sealing sectors to take. Deals that start before this duration will be rejected.", ArgsUsage: "", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() != 1 { return xerrors.Errorf("must pass duration in minutes") } @@ -633,12 +634,12 @@ var marketRestartTransfer = &cli.Command{ if !cctx.Args().Present() { return cli.ShowCommandHelp(cctx, cctx.Command.Name) } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) transferUint, err := strconv.ParseUint(cctx.Args().First(), 10, 64) if err != nil { @@ -698,12 +699,12 @@ var marketCancelTransfer = &cli.Command{ if !cctx.Args().Present() { return cli.ShowCommandHelp(cctx, cctx.Command.Name) } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) transferUint, err := strconv.ParseUint(cctx.Args().First(), 10, 64) if err != nil { @@ -770,12 +771,12 @@ var transfersListCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + api, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) channels, err := api.MarketListDataTransfers(ctx) if err != nil { @@ -838,12 +839,12 @@ var dealsPendingPublish = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + api, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Bool("publish-now") { if err := api.MarketPublishPendingDeals(ctx); err != nil { diff --git a/cmd/lotus-storage-miner/pieces.go b/cmd/lotus-storage-miner/pieces.go index d5f189943b9..18d7b51c95e 100644 --- a/cmd/lotus-storage-miner/pieces.go +++ b/cmd/lotus-storage-miner/pieces.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "os" "text/tabwriter" @@ -26,12 +27,12 @@ var piecesListPiecesCmd = &cli.Command{ Name: "list-pieces", Usage: "list registered pieces", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) pieceCids, err := nodeApi.PiecesListPieces(ctx) if err != nil { @@ -49,12 +50,12 @@ var piecesListCidInfosCmd = &cli.Command{ Name: "list-cids", Usage: "list registered payload CIDs", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) cids, err := nodeApi.PiecesListCidInfos(ctx) if err != nil { @@ -76,12 +77,12 @@ var piecesInfoCmd = &cli.Command{ return lcli.ShowHelp(cctx, fmt.Errorf("must specify piece cid")) } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) c, err := cid.Decode(cctx.Args().First()) if err != nil { @@ -111,12 +112,12 @@ var piecesCidInfoCmd = &cli.Command{ return lcli.ShowHelp(cctx, fmt.Errorf("must specify payload cid")) } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) c, err := cid.Decode(cctx.Args().First()) if err != nil { diff --git a/cmd/lotus-storage-miner/proving.go b/cmd/lotus-storage-miner/proving.go index f6bc74318e8..f45aa856ae6 100644 --- a/cmd/lotus-storage-miner/proving.go +++ b/cmd/lotus-storage-miner/proving.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "os" "strconv" "text/tabwriter" @@ -38,19 +39,19 @@ var provingFaultsCmd = &cli.Command{ Action: func(cctx *cli.Context) error { color.NoColor = !cctx.Bool("color") - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) stor := store.ActorStore(ctx, blockstore.NewAPIBlockstore(api)) @@ -98,19 +99,19 @@ var provingInfoCmd = &cli.Command{ Action: func(cctx *cli.Context) error { color.NoColor = !cctx.Bool("color") - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor")) if err != nil { @@ -211,19 +212,19 @@ var provingDeadlinesCmd = &cli.Command{ Action: func(cctx *cli.Context) error { color.NoColor = !cctx.Bool("color") - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor")) if err != nil { @@ -301,19 +302,19 @@ var provingDeadlineInfoCmd = &cli.Command{ return xerrors.Errorf("could not parse deadline index: %w", err) } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, acloser, err := lcli.GetFullNodeAPI(cctx) + api, acloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer acloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor")) if err != nil { @@ -401,19 +402,19 @@ var provingCheckProvableCmd = &cli.Command{ return xerrors.Errorf("could not parse deadline index: %w", err) } - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - sapi, scloser, err := lcli.GetStorageMinerAPI(cctx) + sapi, scloser, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer scloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) addr, err := sapi.ActorAddress(ctx) if err != nil { diff --git a/cmd/lotus-storage-miner/retrieval-deals.go b/cmd/lotus-storage-miner/retrieval-deals.go index 03d397852d8..710f0359dd3 100644 --- a/cmd/lotus-storage-miner/retrieval-deals.go +++ b/cmd/lotus-storage-miner/retrieval-deals.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "os" "text/tabwriter" @@ -11,7 +12,6 @@ import ( "github.com/urfave/cli/v2" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" ) var retrievalDealsCmd = &cli.Command{ @@ -39,18 +39,18 @@ var retrievalDealSelectionShowCmd = &cli.Command{ Name: "list", Usage: "List retrieval deal proposal selection criteria", Action: func(cctx *cli.Context) error { - smapi, closer, err := lcli.GetStorageMinerAPI(cctx) + smapi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - onlineOk, err := smapi.DealsConsiderOnlineRetrievalDeals(lcli.DaemonContext(cctx)) + onlineOk, err := smapi.DealsConsiderOnlineRetrievalDeals(cliutil.DaemonContext(cctx)) if err != nil { return err } - offlineOk, err := smapi.DealsConsiderOfflineRetrievalDeals(lcli.DaemonContext(cctx)) + offlineOk, err := smapi.DealsConsiderOfflineRetrievalDeals(cliutil.DaemonContext(cctx)) if err != nil { return err } @@ -66,18 +66,18 @@ var retrievalDealSelectionResetCmd = &cli.Command{ Name: "reset", Usage: "Reset retrieval deal proposal selection criteria to default values", Action: func(cctx *cli.Context) error { - smapi, closer, err := lcli.GetStorageMinerAPI(cctx) + smapi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - err = smapi.DealsSetConsiderOnlineRetrievalDeals(lcli.DaemonContext(cctx), true) + err = smapi.DealsSetConsiderOnlineRetrievalDeals(cliutil.DaemonContext(cctx), true) if err != nil { return err } - err = smapi.DealsSetConsiderOfflineRetrievalDeals(lcli.DaemonContext(cctx), true) + err = smapi.DealsSetConsiderOfflineRetrievalDeals(cliutil.DaemonContext(cctx), true) if err != nil { return err } @@ -98,21 +98,21 @@ var retrievalDealSelectionRejectCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - smapi, closer, err := lcli.GetStorageMinerAPI(cctx) + smapi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() if cctx.Bool("online") { - err = smapi.DealsSetConsiderOnlineRetrievalDeals(lcli.DaemonContext(cctx), false) + err = smapi.DealsSetConsiderOnlineRetrievalDeals(cliutil.DaemonContext(cctx), false) if err != nil { return err } } if cctx.Bool("offline") { - err = smapi.DealsSetConsiderOfflineRetrievalDeals(lcli.DaemonContext(cctx), false) + err = smapi.DealsSetConsiderOfflineRetrievalDeals(cliutil.DaemonContext(cctx), false) if err != nil { return err } @@ -126,13 +126,13 @@ var retrievalDealsListCmd = &cli.Command{ Name: "list", Usage: "List all active retrieval deals for this miner", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + api, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - deals, err := api.MarketListRetrievalDeals(lcli.DaemonContext(cctx)) + deals, err := api.MarketListRetrievalDeals(cliutil.DaemonContext(cctx)) if err != nil { return err } @@ -184,9 +184,9 @@ var retrievalSetAskCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - ctx := lcli.DaemonContext(cctx) + ctx := cliutil.DaemonContext(cctx) - api, closer, err := lcli.GetStorageMinerAPI(cctx) + api, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } @@ -238,9 +238,9 @@ var retrievalGetAskCmd = &cli.Command{ Usage: "Get the provider's current retrieval ask", Flags: []cli.Flag{}, Action: func(cctx *cli.Context) error { - ctx := lcli.DaemonContext(cctx) + ctx := cliutil.DaemonContext(cctx) - api, closer, err := lcli.GetStorageMinerAPI(cctx) + api, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } diff --git a/cmd/lotus-storage-miner/run.go b/cmd/lotus-storage-miner/run.go index 741a18eb6be..b29f41d3da7 100644 --- a/cmd/lotus-storage-miner/run.go +++ b/cmd/lotus-storage-miner/run.go @@ -2,6 +2,7 @@ package main import ( "context" + "github.com/filecoin-project/lotus/cli/util" "net" "net/http" _ "net/http/pprof" @@ -64,13 +65,13 @@ var runCmd = &cli.Command{ } } - nodeApi, ncloser, err := lcli.GetFullNodeAPI(cctx) + nodeApi, ncloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return xerrors.Errorf("getting full node api: %w", err) } defer ncloser() - ctx, _ := tag.New(lcli.DaemonContext(cctx), + ctx, _ := tag.New(cliutil.DaemonContext(cctx), tag.Insert(metrics.Version, build.BuildVersion), tag.Insert(metrics.Commit, build.CurrentCommit), tag.Insert(metrics.NodeType, "miner"), diff --git a/cmd/lotus-storage-miner/sealing.go b/cmd/lotus-storage-miner/sealing.go index ad890129d0b..4a76087be99 100644 --- a/cmd/lotus-storage-miner/sealing.go +++ b/cmd/lotus-storage-miner/sealing.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "os" "sort" "strings" @@ -18,7 +19,6 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/storiface" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" ) var sealingCmd = &cli.Command{ @@ -41,13 +41,13 @@ var sealingWorkersCmd = &cli.Command{ Action: func(cctx *cli.Context) error { color.NoColor = !cctx.Bool("color") - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) stats, err := nodeApi.WorkerStats(ctx) if err != nil { @@ -136,13 +136,13 @@ var sealingJobsCmd = &cli.Command{ Action: func(cctx *cli.Context) error { color.NoColor = !cctx.Bool("color") - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) jobs, err := nodeApi.WorkerJobs(ctx) if err != nil { @@ -238,13 +238,13 @@ var sealingSchedDiagCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) st, err := nodeApi.SealingSchedDiag(ctx, cctx.Bool("force-sched")) if err != nil { @@ -271,13 +271,13 @@ var sealingAbortCmd = &cli.Command{ return xerrors.Errorf("expected 1 argument") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) jobs, err := nodeApi.WorkerJobs(ctx) if err != nil { diff --git a/cmd/lotus-storage-miner/sectors.go b/cmd/lotus-storage-miner/sectors.go index a2d41c3e8d2..e2032690c13 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "os" "sort" "strconv" @@ -48,12 +49,12 @@ var sectorsPledgeCmd = &cli.Command{ Name: "pledge", Usage: "store random data in a sector", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) id, err := nodeApi.PledgeSector(ctx) if err != nil { @@ -81,12 +82,12 @@ var sectorsStatusCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return fmt.Errorf("must specify sector number to get status of") @@ -180,19 +181,19 @@ var sectorsListCmd = &cli.Command{ Action: func(cctx *cli.Context) error { color.NoColor = !cctx.Bool("color") - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - fullApi, closer2, err := lcli.GetFullNodeAPI(cctx) // TODO: consider storing full node address in config + fullApi, closer2, err := cliutil.GetFullNodeAPI(cctx) // TODO: consider storing full node address in config if err != nil { return err } defer closer2() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) var list []abi.SectorNumber @@ -388,12 +389,12 @@ var sectorsRefsCmd = &cli.Command{ Name: "refs", Usage: "List References to sectors", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) refs, err := nodeApi.SectorsRefs(ctx) if err != nil { @@ -428,12 +429,12 @@ var sectorsTerminateCmd = &cli.Command{ if !cctx.Bool("really-do-it") { return xerrors.Errorf("pass --really-do-it to confirm this action") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() != 1 { return xerrors.Errorf("must pass sector number") } @@ -451,12 +452,12 @@ var sectorsTerminateFlushCmd = &cli.Command{ Name: "flush", Usage: "Send a terminate message if there are sectors queued for termination", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) mcid, err := nodeApi.SectorTerminateFlush(ctx) if err != nil { @@ -477,17 +478,17 @@ var sectorsTerminatePendingCmd = &cli.Command{ Name: "pending", Usage: "List sector numbers of sectors pending termination", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - api, nCloser, err := lcli.GetFullNodeAPI(cctx) + api, nCloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer nCloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) pending, err := nodeApi.SectorTerminatePending(ctx) if err != nil { @@ -538,12 +539,12 @@ var sectorsRemoveCmd = &cli.Command{ if !cctx.Bool("really-do-it") { return xerrors.Errorf("this is a command for advanced users, only use it if you are sure of what you are doing") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() != 1 { return xerrors.Errorf("must pass sector number") } @@ -566,12 +567,12 @@ var sectorsMarkForUpgradeCmd = &cli.Command{ return lcli.ShowHelp(cctx, xerrors.Errorf("must pass sector number")) } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) id, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) if err != nil { @@ -587,12 +588,12 @@ var sectorsStartSealCmd = &cli.Command{ Usage: "Manually start sealing a sector (filling any unused space with junk)", ArgsUsage: "", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() != 1 { return xerrors.Errorf("must pass sector number") } @@ -611,12 +612,12 @@ var sectorsSealDelayCmd = &cli.Command{ Usage: "Set the time, in minutes, that a new sector waits for deals before sealing starts", ArgsUsage: "", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() != 1 { return xerrors.Errorf("must pass duration in minutes") } @@ -643,19 +644,19 @@ var sectorsCapacityCollateralCmd = &cli.Command{ }, Action: func(cctx *cli.Context) error { - mApi, mCloser, err := lcli.GetStorageMinerAPI(cctx) + mApi, mCloser, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer mCloser() - nApi, nCloser, err := lcli.GetFullNodeAPI(cctx) + nApi, nCloser, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer nCloser() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) maddr, err := mApi.ActorAddress(ctx) if err != nil { @@ -720,12 +721,12 @@ var sectorsUpdateCmd = &cli.Command{ if !cctx.Bool("really-do-it") { return xerrors.Errorf("this is a command for advanced users, only use it if you are sure of what you are doing") } - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Args().Len() < 2 { return xerrors.Errorf("must pass sector number and new state") } diff --git a/cmd/lotus-storage-miner/stop.go b/cmd/lotus-storage-miner/stop.go index 186a156169e..cebecec19a5 100644 --- a/cmd/lotus-storage-miner/stop.go +++ b/cmd/lotus-storage-miner/stop.go @@ -1,11 +1,10 @@ package main import ( + "github.com/filecoin-project/lotus/cli/util" _ "net/http/pprof" "github.com/urfave/cli/v2" - - lcli "github.com/filecoin-project/lotus/cli" ) var stopCmd = &cli.Command{ @@ -13,13 +12,13 @@ var stopCmd = &cli.Command{ Usage: "Stop a running lotus miner", Flags: []cli.Flag{}, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - err = api.Shutdown(lcli.ReqContext(cctx)) + err = api.Shutdown(cliutil.ReqContext(cctx)) if err != nil { return err } diff --git a/cmd/lotus-storage-miner/storage.go b/cmd/lotus-storage-miner/storage.go index e6986f8c764..c19d1c3a724 100644 --- a/cmd/lotus-storage-miner/storage.go +++ b/cmd/lotus-storage-miner/storage.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "io/ioutil" "os" "path/filepath" @@ -23,7 +24,6 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/extern/sector-storage/fsutil" "github.com/filecoin-project/lotus/extern/sector-storage/stores" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" @@ -90,12 +90,12 @@ over time }, }, Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if !cctx.Args().Present() { return xerrors.Errorf("must specify storage path to attach") @@ -158,12 +158,12 @@ var storageListCmd = &cli.Command{ Action: func(cctx *cli.Context) error { color.NoColor = !cctx.Bool("color") - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) st, err := nodeApi.StorageList(ctx) if err != nil { @@ -295,12 +295,12 @@ var storageFindCmd = &cli.Command{ Usage: "find sector in the storage system", ArgsUsage: "[sector number]", Action: func(cctx *cli.Context) error { - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ma, err := nodeApi.ActorAddress(ctx) if err != nil { @@ -429,19 +429,19 @@ var storageListSectorsCmd = &cli.Command{ Action: func(cctx *cli.Context) error { color.NoColor = !cctx.Bool("color") - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) + nodeApi, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - napi, closer2, err := lcli.GetFullNodeAPI(cctx) + napi, closer2, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer2() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) sectors, err := nodeApi.SectorsList(ctx) if err != nil { @@ -588,19 +588,19 @@ var storageCleanupCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetStorageMinerAPI(cctx) + api, closer, err := cliutil.GetStorageMinerAPI(cctx) if err != nil { return err } defer closer() - napi, closer2, err := lcli.GetFullNodeAPI(cctx) + napi, closer2, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer2() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) if cctx.Bool("removed") { if err := cleanupRemovedSectorData(ctx, api, napi); err != nil { diff --git a/cmd/lotus-wallet/main.go b/cmd/lotus-wallet/main.go index f41e3f4265e..d2652964b08 100644 --- a/cmd/lotus-wallet/main.go +++ b/cmd/lotus-wallet/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "github.com/filecoin-project/lotus/cli/util" "net" "net/http" "os" @@ -18,7 +19,6 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/wallet" ledgerwallet "github.com/filecoin-project/lotus/chain/wallet/ledger" - lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/lib/lotuslog" "github.com/filecoin-project/lotus/metrics" "github.com/filecoin-project/lotus/node/repo" @@ -88,7 +88,7 @@ var runCmd = &cli.Command{ Action: func(cctx *cli.Context) error { log.Info("Starting lotus wallet") - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -153,7 +153,7 @@ var runCmd = &cli.Command{ if !cctx.Bool("offline") { ag = func() (api.FullNode, jsonrpc.ClientCloser, error) { - return lcli.GetFullNodeAPI(cctx) + return cliutil.GetFullNodeAPI(cctx) } } diff --git a/cmd/lotus/backup.go b/cmd/lotus/backup.go index d41e0c098bf..91957dfe694 100644 --- a/cmd/lotus/backup.go +++ b/cmd/lotus/backup.go @@ -2,6 +2,7 @@ package main import ( "context" + "github.com/filecoin-project/lotus/cli/util" "os" dstore "github.com/ipfs/go-datastore" @@ -20,7 +21,7 @@ import ( ) var backupCmd = lcli.BackupCmd("repo", repo.FullNode, func(cctx *cli.Context) (lcli.BackupAPI, jsonrpc.ClientCloser, error) { - return lcli.GetFullNodeAPI(cctx) + return cliutil.GetFullNodeAPI(cctx) }) func restore(cctx *cli.Context, r repo.Repo) error { diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index b3eaf0f8c72..6d373559de0 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -8,6 +8,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "github.com/filecoin-project/lotus/cli/util" "io" "io/ioutil" "net/http" @@ -33,7 +34,6 @@ import ( "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" - lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/lotus/journal" "github.com/filecoin-project/lotus/lib/peermgr" @@ -56,13 +56,13 @@ var daemonStopCmd = &cli.Command{ Usage: "Stop a running lotus daemon", Flags: []cli.Flag{}, Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetAPI(cctx) + api, closer, err := cliutil.GetAPI(cctx) if err != nil { return err } defer closer() - err = api.Shutdown(lcli.ReqContext(cctx)) + err = api.Shutdown(cliutil.ReqContext(cctx)) if err != nil { return err } @@ -231,7 +231,7 @@ var DaemonCmd = &cli.Command{ freshRepo := err != repo.ErrRepoExists if !isLite { - if err := paramfetch.GetParams(lcli.ReqContext(cctx), build.ParametersJSON(), 0); err != nil { + if err := paramfetch.GetParams(cliutil.ReqContext(cctx), build.ParametersJSON(), 0); err != nil { return xerrors.Errorf("fetching proof parameters: %w", err) } } @@ -293,7 +293,7 @@ var DaemonCmd = &cli.Command{ // for RPC calls liteModeDeps := node.Options() if isLite { - gapi, closer, err := lcli.GetGatewayAPI(cctx) + gapi, closer, err := cliutil.GetGatewayAPI(cctx) if err != nil { return err } diff --git a/cmd/lotus/debug_advance.go b/cmd/lotus/debug_advance.go index 4e74a995fac..a926fd423da 100644 --- a/cmd/lotus/debug_advance.go +++ b/cmd/lotus/debug_advance.go @@ -4,6 +4,7 @@ package main import ( "encoding/binary" + "github.com/filecoin-project/lotus/cli/util" "time" "github.com/filecoin-project/go-address" @@ -12,7 +13,6 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/types" - lcli "github.com/filecoin-project/lotus/cli" "golang.org/x/xerrors" "github.com/urfave/cli/v2" @@ -22,13 +22,13 @@ func init() { AdvanceBlockCmd = &cli.Command{ Name: "advance-block", Action: func(cctx *cli.Context) error { - api, closer, err := lcli.GetFullNodeAPI(cctx) + api, closer, err := cliutil.GetFullNodeAPI(cctx) if err != nil { return err } defer closer() - ctx := lcli.ReqContext(cctx) + ctx := cliutil.ReqContext(cctx) head, err := api.ChainHead(ctx) if err != nil { return err diff --git a/cmd/tvx/main.go b/cmd/tvx/main.go index 94a656c3e87..04ef1a41d48 100644 --- a/cmd/tvx/main.go +++ b/cmd/tvx/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/filecoin-project/lotus/cli/util" "log" "os" "sort" @@ -10,7 +11,6 @@ import ( "github.com/urfave/cli/v2" "github.com/filecoin-project/lotus/api" - lcli "github.com/filecoin-project/lotus/cli" ) // FullAPI is a JSON-RPC client targeting a full node. It's initialized in a @@ -101,7 +101,7 @@ func initialize(c *cli.Context) error { // Make the API client. var err error - if FullAPI, Closer, err = lcli.GetFullNodeAPI(c); err != nil { + if FullAPI, Closer, err = cliutil.GetFullNodeAPI(c); err != nil { err = fmt.Errorf("failed to locate Lotus node; err: %w", err) } return err