Skip to content

Commit

Permalink
add cli to get the actor cid forthe current network version
Browse files Browse the repository at this point in the history
  • Loading branch information
jennijuju committed May 30, 2022
1 parent 718b05e commit 14c5014
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import (
"sort"
"strconv"
"strings"
"text/tabwriter"
"time"

"github.com/filecoin-project/lotus/chain/actors"

"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/chain/consensus/filcns"

Expand Down Expand Up @@ -79,6 +82,7 @@ var StateCmd = &cli.Command{
StateExecTraceCmd,
StateNtwkVersionCmd,
StateMinerProvingDeadlineCmd,
StateSysActorCIDsCmd,
},
}

Expand Down Expand Up @@ -1872,3 +1876,65 @@ var StateNtwkVersionCmd = &cli.Command{
return nil
},
}

var StateSysActorCIDsCmd = &cli.Command{
Name: "actor-cids",
Usage: "Returns the system actor cids",
Action: func(cctx *cli.Context) error {
if cctx.Args().Present() {
return ShowHelp(cctx, fmt.Errorf("doesn't expect any arguments"))
}

api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()

ctx := ReqContext(cctx)

ts, err := LoadTipSet(ctx, cctx, api)
if err != nil {
return err
}

nv, err := api.StateNetworkVersion(ctx, ts.Key())
if err != nil {
return err
}

fmt.Printf("Network Version: %d\n", nv)

actorVersion, err := actors.VersionForNetwork(nv)
if err != nil {
return err
}
fmt.Printf("Actor Version: %d\n", actorVersion)

tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
_, _ = fmt.Fprintln(tw, "Actor\tCID\t")

for _, name := range []string{
actors.AccountKey,
actors.CronKey,
actors.InitKey,
actors.MarketKey,
actors.MinerKey,
actors.MultisigKey,
actors.PaychKey,
actors.PowerKey,
actors.RewardKey,
actors.SystemKey,
actors.VerifregKey,
} {
sysActorCID, ok := actors.GetActorCodeID(actorVersion, name)
if !ok {
return xerrors.Errorf("error getting actor %v code id for actor version %d", name,
actorVersion)
}
_, _ = fmt.Fprintf(tw, "%v\t%v\n", name, sysActorCID)

}
return tw.Flush()
},
}

0 comments on commit 14c5014

Please sign in to comment.