Skip to content

Commit 2a5df7c

Browse files
authored
feat: command to print actor CID's and version (#1026)
1 parent fb9bc26 commit 2a5df7c

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

commands/chain.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"sort"
78
"strings"
89
"time"
910

@@ -14,9 +15,19 @@ import (
1415
"github.com/filecoin-project/lotus/chain/types"
1516
lotuscli "github.com/filecoin-project/lotus/cli"
1617
"github.com/ipfs/go-cid"
18+
"github.com/jedib0t/go-pretty/v6/table"
1719
"github.com/urfave/cli/v2"
1820

21+
"github.com/filecoin-project/lily/chain/actors"
22+
init_ "github.com/filecoin-project/lily/chain/actors/builtin/init"
23+
"github.com/filecoin-project/lily/chain/actors/builtin/market"
24+
"github.com/filecoin-project/lily/chain/actors/builtin/miner"
25+
"github.com/filecoin-project/lily/chain/actors/builtin/multisig"
26+
"github.com/filecoin-project/lily/chain/actors/builtin/power"
27+
"github.com/filecoin-project/lily/chain/actors/builtin/reward"
28+
"github.com/filecoin-project/lily/chain/actors/builtin/verifreg"
1929
"github.com/filecoin-project/lily/lens/lily"
30+
"github.com/filecoin-project/lily/lens/util"
2031
)
2132

2233
var ChainCmd = &cli.Command{
@@ -30,9 +41,59 @@ var ChainCmd = &cli.Command{
3041
ChainGetMsgCmd,
3142
ChainListCmd,
3243
ChainSetHeadCmd,
44+
ChainActorCodesCmd,
3345
},
3446
}
3547

48+
var ChainActorCodesCmd = &cli.Command{
49+
Name: "actor-codes",
50+
Usage: "Print actor codes and names",
51+
Action: func(cctx *cli.Context) error {
52+
if err := printSortedActorVersions(init_.VersionCodes()); err != nil {
53+
return err
54+
}
55+
if err := printSortedActorVersions(power.VersionCodes()); err != nil {
56+
return err
57+
}
58+
if err := printSortedActorVersions(miner.VersionCodes()); err != nil {
59+
return err
60+
}
61+
if err := printSortedActorVersions(market.VersionCodes()); err != nil {
62+
return err
63+
}
64+
if err := printSortedActorVersions(verifreg.VersionCodes()); err != nil {
65+
return err
66+
}
67+
if err := printSortedActorVersions(multisig.VersionCodes()); err != nil {
68+
return err
69+
}
70+
if err := printSortedActorVersions(reward.VersionCodes()); err != nil {
71+
return err
72+
}
73+
return nil
74+
},
75+
}
76+
77+
func printSortedActorVersions(av map[actors.Version]cid.Cid) error {
78+
t := table.NewWriter()
79+
t.AppendHeader(table.Row{"Version", "Name", "Family", "Code"})
80+
var versions []int
81+
for v := range av {
82+
versions = append(versions, int(v))
83+
}
84+
sort.Ints(versions)
85+
for _, v := range versions {
86+
name, family, err := util.ActorNameAndFamilyFromCode(av[actors.Version(v)])
87+
if err != nil {
88+
return err
89+
}
90+
t.AppendRow(table.Row{v, name, family, av[actors.Version(v)]})
91+
t.AppendSeparator()
92+
}
93+
fmt.Println(t.Render())
94+
return nil
95+
}
96+
3697
var ChainHeadCmd = &cli.Command{
3798
Name: "head",
3899
Usage: "Print chain head",

0 commit comments

Comments
 (0)