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

Clean up printActorMethods #1113

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
98 changes: 33 additions & 65 deletions commands/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
builtin9 "github.com/filecoin-project/go-state-types/builtin"
"github.com/filecoin-project/go-state-types/builtin"
"github.com/filecoin-project/lotus/api"
lotusbuild "github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
Expand Down Expand Up @@ -48,7 +48,7 @@ var ChainActorCodesCmd = &cli.Command{
Name: "actor-codes",
Usage: "Print actor codes and names",
Action: func(cctx *cli.Context) error {
for _, a := range []string{actors.AccountKey, actors.CronKey, actors.DatacapKey, actors.InitKey, actors.MarketKey, actors.MultisigKey, actors.PaychKey, actors.PowerKey, actors.RewardKey, actors.SystemKey, actors.VerifregKey} {
for _, a := range []string{actors.AccountKey, actors.CronKey, actors.DatacapKey, actors.InitKey, actors.MarketKey, actors.MinerKey, actors.MultisigKey, actors.PaychKey, actors.PowerKey, actors.RewardKey, actors.SystemKey, actors.VerifregKey} {
av := make(map[actors.Version]cid.Cid)
for _, v := range []int{0, 2, 3, 4, 5, 6, 7, 8, 9} {
code, ok := actors.GetActorCodeID(actors.Version(v), a)
Expand Down Expand Up @@ -735,84 +735,52 @@ func printActorMethods(actorKey string) error {
t := table.NewWriter()
t.AppendHeader(table.Row{"Method Name", "Method Number"})
var (
methodName string
methodNumber any
methodName string
methodNumber any
correspondingMethods interface{}
)

switch actorKey {
case actors.AccountKey:
for i := 0; i < reflect.TypeOf(builtin9.MethodsAccount).NumField(); i++ {
methodName = reflect.TypeOf(builtin9.MethodsAccount).Field(i).Name
methodNumber = reflect.ValueOf(builtin9.MethodsAccount).Field(i).Interface()
t.AppendRow(table.Row{methodName, methodNumber})
t.AppendSeparator()
}
correspondingMethods = builtin.MethodsAccount
case actors.CronKey:
for i := 0; i < reflect.TypeOf(builtin9.MethodsCron).NumField(); i++ {
methodName = reflect.TypeOf(builtin9.MethodsCron).Field(i).Name
methodNumber = reflect.ValueOf(builtin9.MethodsCron).Field(i).Interface()
t.AppendRow(table.Row{methodName, methodNumber})
t.AppendSeparator()
}
correspondingMethods = builtin.MethodsCron
case actors.DatacapKey:
for i := 0; i < reflect.TypeOf(builtin9.MethodsDatacap).NumField(); i++ {
methodName = reflect.TypeOf(builtin9.MethodsDatacap).Field(i).Name
methodNumber = reflect.ValueOf(builtin9.MethodsDatacap).Field(i).Interface()
t.AppendRow(table.Row{methodName, methodNumber})
t.AppendSeparator()
}
correspondingMethods = builtin.MethodsDatacap
case actors.MarketKey:
for i := 0; i < reflect.TypeOf(builtin9.MethodsMarket).NumField(); i++ {
methodName = reflect.TypeOf(builtin9.MethodsMarket).Field(i).Name
methodNumber = reflect.ValueOf(builtin9.MethodsMarket).Field(i).Interface()
t.AppendRow(table.Row{methodName, methodNumber})
t.AppendSeparator()
}
correspondingMethods = builtin.MethodsMarket
case actors.MinerKey:
correspondingMethods = builtin.MethodsMiner
case actors.InitKey:
for i := 0; i < reflect.TypeOf(builtin9.MethodsInit).NumField(); i++ {
methodName = reflect.TypeOf(builtin9.MethodsInit).Field(i).Name
methodNumber = reflect.ValueOf(builtin9.MethodsInit).Field(i).Interface()
t.AppendRow(table.Row{methodName, methodNumber})
t.AppendSeparator()
}
correspondingMethods = builtin.MethodsInit
case actors.MultisigKey:
for i := 0; i < reflect.TypeOf(builtin9.MethodsMultisig).NumField(); i++ {
methodName = reflect.TypeOf(builtin9.MethodsMultisig).Field(i).Name
methodNumber = reflect.ValueOf(builtin9.MethodsMultisig).Field(i).Interface()
t.AppendRow(table.Row{methodName, methodNumber})
t.AppendSeparator()
}
correspondingMethods = builtin.MethodsMultisig
case actors.PaychKey:
for i := 0; i < reflect.TypeOf(builtin9.MethodsPaych).NumField(); i++ {
methodName = reflect.TypeOf(builtin9.MethodsPaych).Field(i).Name
methodNumber = reflect.ValueOf(builtin9.MethodsPaych).Field(i).Interface()
t.AppendRow(table.Row{methodName, methodNumber})
t.AppendSeparator()
}
correspondingMethods = builtin.MethodsPaych
case actors.PowerKey:
for i := 0; i < reflect.TypeOf(builtin9.MethodsPower).NumField(); i++ {
methodName = reflect.TypeOf(builtin9.MethodsPower).Field(i).Name
methodNumber = reflect.ValueOf(builtin9.MethodsPower).Field(i).Interface()
t.AppendRow(table.Row{methodName, methodNumber})
t.AppendSeparator()
}
correspondingMethods = builtin.MethodsPower
case actors.RewardKey:
for i := 0; i < reflect.TypeOf(builtin9.MethodsReward).NumField(); i++ {
methodName = reflect.TypeOf(builtin9.MethodsReward).Field(i).Name
methodNumber = reflect.ValueOf(builtin9.MethodsReward).Field(i).Interface()
t.AppendRow(table.Row{methodName, methodNumber})
t.AppendSeparator()
}
correspondingMethods = builtin.MethodsReward
case actors.SystemKey:
correspondingMethods = nil
case actors.VerifregKey:
for i := 0; i < reflect.TypeOf(builtin9.MethodsVerifiedRegistry).NumField(); i++ {
methodName = reflect.TypeOf(builtin9.MethodsVerifiedRegistry).Field(i).Name
methodNumber = reflect.ValueOf(builtin9.MethodsVerifiedRegistry).Field(i).Interface()
t.AppendRow(table.Row{methodName, methodNumber})
t.AppendSeparator()
}
correspondingMethods = builtin.MethodsVerifiedRegistry
default:
return fmt.Errorf("unsupported actor key: %s", actorKey)
return fmt.Errorf("unknown actor key: %s", actorKey)
}

// Check if correspondingMethods is nil
if correspondingMethods == nil {
return nil
}

for i := 0; i < reflect.TypeOf(correspondingMethods).NumField(); i++ {
methodName = reflect.TypeOf(correspondingMethods).Field(i).Name
methodNumber = reflect.ValueOf(correspondingMethods).Field(i).Interface()
t.AppendRow(table.Row{methodName, methodNumber})
t.AppendSeparator()
}

fmt.Println(t.RenderMarkdown())
return nil
}