Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: command to print actor CID's and version #1026

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions commands/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"sort"
"strings"
"time"

Expand All @@ -14,9 +15,19 @@ import (
"github.com/filecoin-project/lotus/chain/types"
lotuscli "github.com/filecoin-project/lotus/cli"
"github.com/ipfs/go-cid"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/urfave/cli/v2"

"github.com/filecoin-project/lily/chain/actors"
init_ "github.com/filecoin-project/lily/chain/actors/builtin/init"
"github.com/filecoin-project/lily/chain/actors/builtin/market"
"github.com/filecoin-project/lily/chain/actors/builtin/miner"
"github.com/filecoin-project/lily/chain/actors/builtin/multisig"
"github.com/filecoin-project/lily/chain/actors/builtin/power"
"github.com/filecoin-project/lily/chain/actors/builtin/reward"
"github.com/filecoin-project/lily/chain/actors/builtin/verifreg"
"github.com/filecoin-project/lily/lens/lily"
"github.com/filecoin-project/lily/lens/util"
)

var ChainCmd = &cli.Command{
Expand All @@ -30,9 +41,59 @@ var ChainCmd = &cli.Command{
ChainGetMsgCmd,
ChainListCmd,
ChainSetHeadCmd,
ChainActorCodesCmd,
},
}

var ChainActorCodesCmd = &cli.Command{
Name: "actor-codes",
Usage: "Print actor codes and names",
Action: func(cctx *cli.Context) error {
if err := printSortedActorVersions(init_.VersionCodes()); err != nil {
return err
}
if err := printSortedActorVersions(power.VersionCodes()); err != nil {
return err
}
if err := printSortedActorVersions(miner.VersionCodes()); err != nil {
return err
}
if err := printSortedActorVersions(market.VersionCodes()); err != nil {
return err
}
if err := printSortedActorVersions(verifreg.VersionCodes()); err != nil {
return err
}
if err := printSortedActorVersions(multisig.VersionCodes()); err != nil {
return err
}
if err := printSortedActorVersions(reward.VersionCodes()); err != nil {
return err
}
return nil
},
}

func printSortedActorVersions(av map[actors.Version]cid.Cid) error {
t := table.NewWriter()
t.AppendHeader(table.Row{"Version", "Name", "Family", "Code"})
var versions []int
for v := range av {
versions = append(versions, int(v))
}
sort.Ints(versions)
for _, v := range versions {
name, family, err := util.ActorNameAndFamilyFromCode(av[actors.Version(v)])
if err != nil {
return err
}
t.AppendRow(table.Row{v, name, family, av[actors.Version(v)]})
t.AppendSeparator()
}
fmt.Println(t.Render())
return nil
}

var ChainHeadCmd = &cli.Command{
Name: "head",
Usage: "Print chain head",
Expand Down