Skip to content

Commit

Permalink
Merge pull request #7699 from filecoin-project/feat/listcids-verbose
Browse files Browse the repository at this point in the history
Add verbose mode to lotus-miner pieces list-cids
  • Loading branch information
jennijuju authored Nov 29, 2021
2 parents f399422 + f8b1328 commit 4d2f337
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
54 changes: 53 additions & 1 deletion cmd/lotus-miner/pieces.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"text/tabwriter"

lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/lib/tablewriter"
"github.com/ipfs/go-cid"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -48,6 +49,12 @@ var piecesListPiecesCmd = &cli.Command{
var piecesListCidInfosCmd = &cli.Command{
Name: "list-cids",
Usage: "list registered payload CIDs",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"v"},
},
},
Action: func(cctx *cli.Context) error {
nodeApi, closer, err := lcli.GetMarketsAPI(cctx)
if err != nil {
Expand All @@ -61,9 +68,54 @@ var piecesListCidInfosCmd = &cli.Command{
return err
}

w := tablewriter.New(tablewriter.Col("CID"),
tablewriter.Col("Piece"),
tablewriter.Col("BlockOffset"),
tablewriter.Col("BlockLen"),
tablewriter.Col("Deal"),
tablewriter.Col("Sector"),
tablewriter.Col("DealOffset"),
tablewriter.Col("DealLen"),
)

for _, c := range cids {
fmt.Println(c)
if !cctx.Bool("verbose") {
fmt.Println(c)
continue
}

ci, err := nodeApi.PiecesGetCIDInfo(ctx, c)
if err != nil {
fmt.Printf("Error getting CID info: %s\n", err)
continue
}

for _, location := range ci.PieceBlockLocations {
pi, err := nodeApi.PiecesGetPieceInfo(ctx, location.PieceCID)
if err != nil {
fmt.Printf("Error getting piece info: %s\n", err)
continue
}

for _, deal := range pi.Deals {
w.Write(map[string]interface{}{
"CID": c,
"Piece": location.PieceCID,
"BlockOffset": location.RelOffset,
"BlockLen": location.BlockSize,
"Deal": deal.DealID,
"Sector": deal.SectorID,
"DealOffset": deal.Offset,
"DealLen": deal.Length,
})
}
}
}

if cctx.Bool("verbose") {
return w.Flush(os.Stdout)
}

return nil
},
}
Expand Down
3 changes: 2 additions & 1 deletion documentation/en/cli-lotus-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,8 @@ USAGE:
lotus-miner pieces list-cids [command options] [arguments...]
OPTIONS:
--help, -h show help (default: false)
--verbose, -v (default: false)
--help, -h show help (default: false)
```

Expand Down

0 comments on commit 4d2f337

Please sign in to comment.