From 39ae4b04be8a5a7d0b5d4dc23b83524046a2a20b Mon Sep 17 00:00:00 2001 From: zenground0 Date: Mon, 16 Jan 2023 17:50:47 -0700 Subject: [PATCH] Add cid to cbor cmd --- cmd/lotus-shed/cid.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/lotus-shed/cid.go b/cmd/lotus-shed/cid.go index a8534eff2..4b526ea2f 100644 --- a/cmd/lotus-shed/cid.go +++ b/cmd/lotus-shed/cid.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "encoding/base64" "encoding/hex" "fmt" @@ -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" @@ -27,6 +29,23 @@ var cidCmd = &cli.Command{ Subcommands: cli.Commands{ cidIdCmd, inspectBundleCmd, + cborCid, + }, +} + +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)) + cbgc.MarshalCBOR(buf) + fmt.Printf("%x\n", buf.Bytes()) }, }