diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index 4e54252bc..ced48ad2a 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -44,7 +44,7 @@ var infoCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - maddr, err := nodeApi.ActorAddress(ctx) + maddr, err := getActorAddress(ctx, nodeApi, cctx.String("maddr")) if err != nil { return err } diff --git a/cmd/lotus-storage-miner/main.go b/cmd/lotus-storage-miner/main.go index bc8d3418a..b2dab2599 100644 --- a/cmd/lotus-storage-miner/main.go +++ b/cmd/lotus-storage-miner/main.go @@ -1,12 +1,16 @@ package main import ( + "context" "os" logging "github.com/ipfs/go-log/v2" "github.com/urfave/cli/v2" "go.opencensus.io/trace" + "golang.org/x/xerrors" + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/lib/lotuslog" @@ -89,3 +93,19 @@ func main() { os.Exit(1) } } + +func getActorAddress(ctx context.Context, nodeApi api.StorageMiner, overrideMaddr string) (maddr address.Address, err error) { + if overrideMaddr != "" { + maddr, err = address.NewFromString(overrideMaddr) + if err != nil { + return maddr, err + } + } + + maddr, err = nodeApi.ActorAddress(ctx) + if err != nil { + return maddr, xerrors.Errorf("getting actor address: %w", err) + } + + return maddr, nil +} diff --git a/cmd/lotus-storage-miner/proving.go b/cmd/lotus-storage-miner/proving.go index 352336505..73bc510d5 100644 --- a/cmd/lotus-storage-miner/proving.go +++ b/cmd/lotus-storage-miner/proving.go @@ -10,7 +10,6 @@ import ( "github.com/urfave/cli/v2" "golang.org/x/xerrors" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" rlepluslazy "github.com/filecoin-project/go-bitfield/rle" "github.com/filecoin-project/specs-actors/actors/abi" @@ -49,18 +48,9 @@ var provingFaultsCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - maddr, err := nodeApi.ActorAddress(ctx) + maddr, err := getActorAddress(ctx, nodeApi, cctx.String("maddr")) if err != nil { - return xerrors.Errorf("getting actor address: %w", err) - } - - // override maddr is specified - if cctx.String("maddr") != "" { - var err error - maddr, err = address.NewFromString(cctx.String("maddr")) - if err != nil { - panic(err) - } + return err } var mas miner.State @@ -126,18 +116,9 @@ var provingInfoCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - maddr, err := nodeApi.ActorAddress(ctx) + maddr, err := getActorAddress(ctx, nodeApi, cctx.String("maddr")) if err != nil { - return xerrors.Errorf("getting actor address: %w", err) - } - - // override maddr is specified - if cctx.String("maddr") != "" { - var err error - maddr, err = address.NewFromString(cctx.String("maddr")) - if err != nil { - panic(err) - } + return err } head, err := api.ChainHead(ctx) @@ -258,18 +239,9 @@ var provingDeadlinesCmd = &cli.Command{ ctx := lcli.ReqContext(cctx) - maddr, err := nodeApi.ActorAddress(ctx) + maddr, err := getActorAddress(ctx, nodeApi, cctx.String("maddr")) if err != nil { - return xerrors.Errorf("getting actor address: %w", err) - } - - // override maddr is specified - if cctx.String("maddr") != "" { - var err error - maddr, err = address.NewFromString(cctx.String("maddr")) - if err != nil { - panic(err) - } + return err } deadlines, err := api.StateMinerDeadlines(ctx, maddr, types.EmptyTSK)