Skip to content

Commit

Permalink
Merge pull request #10032 from filecoin-project/feat/cbor-cid
Browse files Browse the repository at this point in the history
feat:shed:add cid to cbor serialization command
  • Loading branch information
magik6k authored Jan 18, 2023
2 parents 2d3f1e0 + 72baa3d commit 0934cf0
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cmd/lotus-shed/cid.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"encoding/base64"
"encoding/hex"
"fmt"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/ipld/go-car"
mh "github.com/multiformats/go-multihash"
"github.com/urfave/cli/v2"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-state-types/abi"
Expand All @@ -27,6 +29,42 @@ var cidCmd = &cli.Command{
Subcommands: cli.Commands{
cidIdCmd,
inspectBundleCmd,
cborCid,
cidBytes,
},
}

var cidBytes = &cli.Command{
Name: "bytes",
Usage: "cid bytes",
ArgsUsage: "[cid]",
Action: func(cctx *cli.Context) error {
c, err := cid.Decode(cctx.Args().First())
if err != nil {
return err
}
// Add in the troublesome zero byte prefix
fmt.Printf("00%x\n", c.Bytes())
return nil
},
}

var cborCid = &cli.Command{
Name: "cbor",
Usage: "Serialize cid to cbor",
ArgsUsage: "[cid]",
Action: func(cctx *cli.Context) error {
c, err := cid.Decode(cctx.Args().First())
if err != nil {
return err
}
cbgc := cbg.CborCid(c)
buf := bytes.NewBuffer(make([]byte, 0))
if err := cbgc.MarshalCBOR(buf); err != nil {
return err
}
fmt.Printf("%x\n", buf.Bytes())
return nil
},
}

Expand Down

0 comments on commit 0934cf0

Please sign in to comment.