From 8778787091e468f502ee49e72f69819e28909ce8 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 3 Sep 2020 17:17:00 -0700 Subject: [PATCH 1/2] [cli/state] Robust actor lookup This probably isn't critical, but I noticed it, so I fixed it. --- cli/state.go | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/cli/state.go b/cli/state.go index 1e75cc7cd..4d6253efc 100644 --- a/cli/state.go +++ b/cli/state.go @@ -26,11 +26,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/market" - miner2 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/actors/builtin/multisig" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/specs-actors/actors/builtin/power" + "github.com/filecoin-project/specs-actors/actors/builtin/exported" "github.com/filecoin-project/specs-actors/actors/runtime/exitcode" "github.com/filecoin-project/lotus/api" @@ -1460,21 +1456,21 @@ func parseParamsForMethod(act cid.Cid, method uint64, args []string) ([]byte, er return nil, nil } - var f interface{} - switch act { - case builtin.StorageMarketActorCodeID: - f = market.Actor{}.Exports()[method] - case builtin.StorageMinerActorCodeID: - f = miner2.Actor{}.Exports()[method] - case builtin.StoragePowerActorCodeID: - f = power.Actor{}.Exports()[method] - case builtin.MultisigActorCodeID: - f = multisig.Actor{}.Exports()[method] - case builtin.PaymentChannelActorCodeID: - f = paych.Actor{}.Exports()[method] - default: - return nil, fmt.Errorf("the lazy devs didnt add support for that actor to this call yet") + var target abi.Invokee + for _, actor := range exported.BuiltinActors() { + if actor.Code() == act { + target = actor + } } + if target == nil { + return nil, fmt.Errorf("unknown actor %s", act) + } + methods := target.Exports() + if uint64(len(methods)) <= method || methods[method] == nil { + return nil, fmt.Errorf("unknown method %d for actor %s", method, act) + } + + f := methods[method] rf := reflect.TypeOf(f) if rf.NumIn() != 3 { From 6e711ed7399e40ec1b35ae932d00fbeb8f8abfdd Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 3 Sep 2020 17:22:18 -0700 Subject: [PATCH 2/2] [cli/state] Robust actor name lookup --- cli/state.go | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/cli/state.go b/cli/state.go index 4d6253efc..a0256c2e3 100644 --- a/cli/state.go +++ b/cli/state.go @@ -564,25 +564,7 @@ var stateGetActorCmd = &cli.Command{ return err } - var strtype string - switch a.Code { - case builtin.AccountActorCodeID: - strtype = "account" - case builtin.MultisigActorCodeID: - strtype = "multisig" - case builtin.CronActorCodeID: - strtype = "cron" - case builtin.InitActorCodeID: - strtype = "init" - case builtin.StorageMinerActorCodeID: - strtype = "miner" - case builtin.StorageMarketActorCodeID: - strtype = "market" - case builtin.StoragePowerActorCodeID: - strtype = "power" - default: - strtype = "unknown" - } + strtype := builtin.ActorNameByCode(a.Code) fmt.Printf("Address:\t%s\n", addr) fmt.Printf("Balance:\t%s\n", types.FIL(a.Balance))