Skip to content

Commit

Permalink
chore: cmd: sort actor CIDs alphabetically before printing
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Dec 5, 2023
1 parent bc5cf50 commit c3bf89f
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions cmd/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"os"
"reflect"
"sort"
"strconv"

"github.com/filecoin-project/go-address"
Expand Down Expand Up @@ -651,16 +652,39 @@ var stateSysActorCIDsCmd = &cmds.Command{
}
buf.WriteString(fmt.Sprintf("Actor Version: %d\n", actorVersion))

manifestCid, err := env.(*node.Env).ChainAPI.StateActorManifestCID(ctx, nv)
if err != nil {
return err
}
buf.WriteString(fmt.Sprintf("Manifest CID: %v\n", manifestCid))

tw := tablewriter.New(tablewriter.Col("Actor"), tablewriter.Col("CID"))

actorsCids, err := env.(*node.Env).ChainAPI.StateActorCodeCIDs(ctx, nv)
if err != nil {
return err
}
for name, cid := range actorsCids {

type actorCid struct {
actorName string
actorCID string
}

var actorsCid []actorCid
for name, c := range actorsCids {
actorsCid = append(actorsCid, actorCid{
actorName: name,
actorCID: c.String(),
})
}
sort.Slice(actorsCid, func(i, j int) bool {
return actorsCid[i].actorName < actorsCid[j].actorName
})

for _, ac := range actorsCid {
tw.Write(map[string]interface{}{
"Actor": name,
"CID": cid.String(),
"Actor": ac.actorName,
"CID": ac.actorCID,
})
}

Expand Down

0 comments on commit c3bf89f

Please sign in to comment.