Skip to content

Commit

Permalink
Merge pull request #6244 from filecoin-project/chore/sort-before-output
Browse files Browse the repository at this point in the history
chore: cmd: sort actor CIDs alphabetically before printing
  • Loading branch information
LinZexiao authored Dec 5, 2023
2 parents bc5cf50 + c3bf89f commit d85a8d7
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 d85a8d7

Please sign in to comment.