2019-08-07 06:35:57 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"gopkg.in/urfave/cli.v2"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-lotus/chain/address"
|
|
|
|
)
|
|
|
|
|
|
|
|
var stateCmd = &cli.Command{
|
|
|
|
Name: "state",
|
|
|
|
Usage: "Interact with and query filecoin chain state",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
statePowerCmd,
|
|
|
|
stateSectorsCmd,
|
|
|
|
stateProvingSetCmd,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var statePowerCmd = &cli.Command{
|
|
|
|
Name: "power",
|
|
|
|
Usage: "Query network or miner power",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-08-08 03:30:50 +00:00
|
|
|
api, err := GetFullNodeAPI(cctx)
|
2019-08-07 06:35:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
2019-08-21 22:14:58 +00:00
|
|
|
var maddr address.Address
|
2019-08-07 06:35:57 +00:00
|
|
|
if cctx.Args().Present() {
|
2019-08-21 22:14:58 +00:00
|
|
|
maddr, err = address.NewFromString(cctx.Args().First())
|
2019-08-07 06:35:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2019-08-21 22:14:58 +00:00
|
|
|
power, err := api.StateMinerPower(ctx, maddr, nil)
|
2019-08-07 06:35:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-08-21 22:14:58 +00:00
|
|
|
|
|
|
|
res := power.TotalPower
|
|
|
|
if cctx.Args().Present() {
|
|
|
|
res = power.MinerPower
|
2019-08-07 06:35:57 +00:00
|
|
|
}
|
|
|
|
|
2019-08-21 22:14:58 +00:00
|
|
|
fmt.Println(res.String())
|
2019-08-07 06:35:57 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var stateSectorsCmd = &cli.Command{
|
|
|
|
Name: "sectors",
|
|
|
|
Usage: "Query the sector set of a miner",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-08-08 03:30:50 +00:00
|
|
|
api, err := GetFullNodeAPI(cctx)
|
2019-08-07 06:35:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
|
|
|
if !cctx.Args().Present() {
|
|
|
|
return fmt.Errorf("must specify miner to list sectors for")
|
|
|
|
}
|
|
|
|
|
|
|
|
maddr, err := address.NewFromString(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sectors, err := api.StateMinerSectors(ctx, maddr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range sectors {
|
|
|
|
fmt.Printf("%d: %x %x\n", s.SectorID, s.CommR, s.CommD)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var stateProvingSetCmd = &cli.Command{
|
|
|
|
Name: "proving",
|
|
|
|
Usage: "Query the proving set of a miner",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-08-08 03:30:50 +00:00
|
|
|
api, err := GetFullNodeAPI(cctx)
|
2019-08-07 06:35:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := ReqContext(cctx)
|
|
|
|
|
|
|
|
if !cctx.Args().Present() {
|
|
|
|
return fmt.Errorf("must specify miner to list sectors for")
|
|
|
|
}
|
|
|
|
|
|
|
|
maddr, err := address.NewFromString(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sectors, err := api.StateMinerProvingSet(ctx, maddr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range sectors {
|
|
|
|
fmt.Printf("%d: %x %x\n", s.SectorID, s.CommR, s.CommD)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|