From 5bcecdd5077c0501d4e1690021069f14204654a2 Mon Sep 17 00:00:00 2001 From: Aayush Date: Thu, 23 Jun 2022 16:31:15 -0400 Subject: [PATCH] feat: shed: print out actor code CIDs in manifest cid checker --- cmd/lotus-shed/cid.go | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/cmd/lotus-shed/cid.go b/cmd/lotus-shed/cid.go index 6540f83587c..aa34d2e7d47 100644 --- a/cmd/lotus-shed/cid.go +++ b/cmd/lotus-shed/cid.go @@ -5,6 +5,11 @@ import ( "encoding/hex" "fmt" "os" + "text/tabwriter" + + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + cbor "github.com/ipfs/go-ipld-cbor" "github.com/ipfs/go-cid" "github.com/ipld/go-car" @@ -22,7 +27,7 @@ var cidCmd = &cli.Command{ Usage: "Cid command", Subcommands: cli.Commands{ cidIdCmd, - cidFromCarCmd, + inspectBundleCmd, }, } @@ -90,9 +95,9 @@ var cidIdCmd = &cli.Command{ }, } -var cidFromCarCmd = &cli.Command{ - Name: "manifest-cid-from-car", - Usage: "Get the manifest CID from a car file", +var inspectBundleCmd = &cli.Command{ + Name: "inspect-bundle", + Usage: "Get the manifest CID from a car file, as well as the actor code CIDs", ArgsUsage: "[path]", Action: func(cctx *cli.Context) error { ctx := cctx.Context @@ -104,6 +109,7 @@ var cidFromCarCmd = &cli.Command{ } bs := blockstore.NewMemory() + wrapBs := adt.WrapStore(ctx, cbor.NewCborStore(bs)) hdr, err := car.LoadCar(ctx, bs, f) if err != nil { @@ -114,6 +120,19 @@ var cidFromCarCmd = &cli.Command{ fmt.Printf("Manifest CID: %s\n", manifestCid.String()) - return nil + entries, err := actors.ReadManifest(ctx, wrapBs, manifestCid) + if err != nil { + return xerrors.Errorf("error loading manifest: %w", err) + } + + tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) + _, _ = fmt.Fprintln(tw, "\nActor\tCID\t") + + for name, cid := range entries { + _, _ = fmt.Fprintf(tw, "%v\t%v\n", name, cid) + + } + + return tw.Flush() }, }