Add a command to read an object by its cid

This commit is contained in:
whyrusleeping
2019-10-01 10:28:07 -06:00
parent 62e596d0a3
commit 404e14d3eb
4 changed files with 41 additions and 0 deletions
+26
View File
@@ -16,6 +16,7 @@ var chainCmd = &cli.Command{
Subcommands: []*cli.Command{
chainHeadCmd,
chainGetBlock,
chainReadObjCmd,
},
}
@@ -113,3 +114,28 @@ var chainGetBlock = &cli.Command{
},
}
var chainReadObjCmd = &cli.Command{
Name: "read-obj",
Usage: "Read the raw bytes of an object",
Action: func(cctx *cli.Context) error {
api, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
ctx := ReqContext(cctx)
c, err := cid.Parse(cctx.Args().First)
if err != nil {
return fmt.Errorf("failed to parse cid input: %s", err)
}
obj, err := api.ChainReadObj(ctx, c)
if err != nil {
return err
}
fmt.Printf("%x\n", obj)
return nil
},
}