Miner CLI: If performing read-only operations on a foreign miner, miner API isn't needed

This commit is contained in:
Aayush Rajasekaran 2021-03-28 01:21:09 -04:00
parent ded4ff43f4
commit b734e5a232
4 changed files with 20 additions and 49 deletions

View File

@ -90,7 +90,7 @@ func infoCmdAct(cctx *cli.Context) error {
fmt.Println()
maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor"))
maddr, err := getActorAddress(ctx, cctx)
if err != nil {
return err
}

View File

@ -106,15 +106,21 @@ func main() {
lcli.RunApp(app)
}
func getActorAddress(ctx context.Context, nodeAPI api.StorageMiner, overrideMaddr string) (maddr address.Address, err error) {
if overrideMaddr != "" {
maddr, err = address.NewFromString(overrideMaddr)
func getActorAddress(ctx context.Context, cctx *cli.Context) (maddr address.Address, err error) {
if cctx.IsSet("actor") {
maddr, err = address.NewFromString(cctx.String("actor"))
if err != nil {
return maddr, err
}
return
}
nodeAPI, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return address.Undef, err
}
defer closer()
maddr, err = nodeAPI.ActorAddress(ctx)
if err != nil {
return maddr, xerrors.Errorf("getting actor address: %w", err)

View File

@ -38,12 +38,6 @@ var provingFaultsCmd = &cli.Command{
Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color")
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
api, acloser, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
@ -54,7 +48,7 @@ var provingFaultsCmd = &cli.Command{
stor := store.ActorStore(ctx, blockstore.NewAPIBlockstore(api))
maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor"))
maddr, err := getActorAddress(ctx, cctx)
if err != nil {
return err
}
@ -98,12 +92,6 @@ var provingInfoCmd = &cli.Command{
Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color")
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
api, acloser, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
@ -112,7 +100,7 @@ var provingInfoCmd = &cli.Command{
ctx := lcli.ReqContext(cctx)
maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor"))
maddr, err := getActorAddress(ctx, cctx)
if err != nil {
return err
}
@ -211,12 +199,6 @@ var provingDeadlinesCmd = &cli.Command{
Action: func(cctx *cli.Context) error {
color.NoColor = !cctx.Bool("color")
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
api, acloser, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
@ -225,7 +207,7 @@ var provingDeadlinesCmd = &cli.Command{
ctx := lcli.ReqContext(cctx)
maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor"))
maddr, err := getActorAddress(ctx, cctx)
if err != nil {
return err
}
@ -301,12 +283,6 @@ var provingDeadlineInfoCmd = &cli.Command{
return xerrors.Errorf("could not parse deadline index: %w", err)
}
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
api, acloser, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
@ -315,7 +291,7 @@ var provingDeadlineInfoCmd = &cli.Command{
ctx := lcli.ReqContext(cctx)
maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor"))
maddr, err := getActorAddress(ctx, cctx)
if err != nil {
return err
}

View File

@ -434,11 +434,6 @@ var sectorsExtendCmd = &cli.Command{
&cli.StringFlag{},
},
Action: func(cctx *cli.Context) error {
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
api, nCloser, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
@ -447,9 +442,10 @@ var sectorsExtendCmd = &cli.Command{
defer nCloser()
ctx := lcli.ReqContext(cctx)
maddr, err := nodeApi.ActorAddress(ctx)
maddr, err := getActorAddress(ctx, cctx)
if err != nil {
return xerrors.Errorf("getting miner actor address: %w", err)
return err
}
var params []miner0.ExtendSectorExpirationParams
@ -512,7 +508,6 @@ var sectorsExtendCmd = &cli.Command{
}
}
// TODO: Count added sectors, if it exceeds 10k, split messages
p := &miner0.ExtendSectorExpirationParams{}
scount := 0
for l, exts := range sectors {
@ -578,8 +573,8 @@ var sectorsExtendCmd = &cli.Command{
return xerrors.Errorf("getting miner info: %w", err)
}
for _, p := range params {
sp, aerr := actors.SerializeParams(&p)
for i := range params {
sp, aerr := actors.SerializeParams(&params[i])
if aerr != nil {
return xerrors.Errorf("serializing params: %w", err)
}
@ -836,12 +831,6 @@ var sectorsCapacityCollateralCmd = &cli.Command{
},
Action: func(cctx *cli.Context) error {
mApi, mCloser, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer mCloser()
nApi, nCloser, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
@ -850,7 +839,7 @@ var sectorsCapacityCollateralCmd = &cli.Command{
ctx := lcli.ReqContext(cctx)
maddr, err := mApi.ActorAddress(ctx)
maddr, err := getActorAddress(ctx, cctx)
if err != nil {
return err
}