Merge pull request #10032 from filecoin-project/feat/cbor-cid
feat:shed:add cid to cbor serialization command
This commit is contained in:
commit
0934cf034d
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -12,6 +13,7 @@ import (
|
|||||||
"github.com/ipld/go-car"
|
"github.com/ipld/go-car"
|
||||||
mh "github.com/multiformats/go-multihash"
|
mh "github.com/multiformats/go-multihash"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
@ -27,6 +29,42 @@ var cidCmd = &cli.Command{
|
|||||||
Subcommands: cli.Commands{
|
Subcommands: cli.Commands{
|
||||||
cidIdCmd,
|
cidIdCmd,
|
||||||
inspectBundleCmd,
|
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
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user