From cb4ae013c658dee974365523766bcd1c7a0a7e99 Mon Sep 17 00:00:00 2001 From: Travis Person Date: Tue, 18 Feb 2020 19:02:52 +0000 Subject: [PATCH] cli: add state miner-info command Resolves #1270 --- cli/state.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/cli/state.go b/cli/state.go index 5c0ddb65f..a5021bc64 100644 --- a/cli/state.go +++ b/cli/state.go @@ -17,6 +17,7 @@ import ( "github.com/libp2p/go-libp2p-core/peer" "golang.org/x/xerrors" + "github.com/docker/go-units" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "gopkg.in/urfave/cli.v2" @@ -48,6 +49,67 @@ var stateCmd = &cli.Command{ stateCallCmd, stateGetDealSetCmd, stateWaitMsgCmd, + stateMinerInfo, + }, +} + +var stateMinerInfo = &cli.Command{ + Name: "miner-info", + Usage: "Retrieve miner information", + Action: func(cctx *cli.Context) error { + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + + ctx := ReqContext(cctx) + + if !cctx.Args().Present() { + return fmt.Errorf("must specify miner to get information for") + } + + addr, err := address.NewFromString(cctx.Args().First()) + if err != nil { + return err + } + + ts, err := loadTipSet(ctx, cctx, api) + if err != nil { + return err + } + + act, err := api.StateGetActor(ctx, addr, ts.Key()) + if err != nil { + return err + } + + aso, err := api.ChainReadObj(ctx, act.Head) + if err != nil { + return err + } + + var mst actors.StorageMinerActorState + if err := mst.UnmarshalCBOR(bytes.NewReader(aso)); err != nil { + return err + } + + mio, err := api.ChainReadObj(ctx, mst.Info) + if err != nil { + return err + } + + var mi actors.MinerInfo + if err := mi.UnmarshalCBOR(bytes.NewReader(mio)); err != nil { + return err + } + + fmt.Printf("Owner:\t%s\n", mi.Owner) + fmt.Printf("Worker:\t%s\n", mi.Worker) + fmt.Printf("PeerID:\t%s\n", mi.PeerID) + fmt.Printf("SectorSize:\t%s (%d)\n", units.BytesSize(float64(mi.SectorSize)), mi.SectorSize) + + return nil }, }