Merge pull request #1275 from filecoin-project/feat/cli-state-miner-info

cli: add state miner-info command
This commit is contained in:
Łukasz Magiera 2020-02-24 15:29:19 +01:00 committed by GitHub
commit a6a63d35e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@ import (
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
"golang.org/x/xerrors" "golang.org/x/xerrors"
"github.com/docker/go-units"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
@ -48,6 +49,67 @@ var stateCmd = &cli.Command{
stateCallCmd, stateCallCmd,
stateGetDealSetCmd, stateGetDealSetCmd,
stateWaitMsgCmd, 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
}, },
} }