Skip to content

Commit

Permalink
feat: dagstore lookup-cid command (#751)
Browse files Browse the repository at this point in the history
* add dagstore lookup-cid command

* add subcommand

* rename command
  • Loading branch information
LexLuthr authored Sep 1, 2022
1 parent 85347fc commit 9d186e3
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions cmd/boostd/dagstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/filecoin-project/lotus/lib/tablewriter"
"github.com/ipfs/go-cid"

"github.com/fatih/color"
bapi "github.com/filecoin-project/boost/api"
Expand All @@ -25,6 +26,7 @@ var dagstoreCmd = &cli.Command{
dagstoreListShardsCmd,
dagstoreGcCmd,
dagstoreDestroyShardCmd,
dagstoreLookupCmd,
},
}

Expand Down Expand Up @@ -309,3 +311,47 @@ var dagstoreDestroyShardCmd = &cli.Command{
return nil
},
}

var dagstoreLookupCmd = &cli.Command{
Name: "lookup-piece-cid",
ArgsUsage: "[key]",
Usage: "Performs a reverse lookup with payload CID to get Piece CID",
Aliases: []string{"lpc"},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "color",
Usage: "use color in display output",
DefaultText: "depends on output being a TTY",
},
},
Action: func(cctx *cli.Context) error {
if cctx.IsSet("color") {
color.NoColor = !cctx.Bool("color")
}

if cctx.NArg() != 1 {
return fmt.Errorf("must provide a single payload CID")
}

napi, closer, err := bcli.GetBoostAPI(cctx)
if err != nil {
return err
}
defer closer()

ctx := lcli.ReqContext(cctx)

shardKey := cctx.Args().First()
payloadCid, err := cid.Parse(shardKey)
if err != nil {
return fmt.Errorf("Unable to parse the provided CID: %s", shardKey)
}
pieceCid, err := napi.BoostDagstorePiecesContainingMultihash(ctx, payloadCid.Hash())
if err != nil {
return err
}

fmt.Printf("Given CID was found in the following pieces: %s", pieceCid)
return nil
},
}

0 comments on commit 9d186e3

Please sign in to comment.