From fff58e136810afb9f7cfe8f3f60fa2fc00e41ee6 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Fri, 20 Jan 2023 16:23:56 -0500 Subject: [PATCH] Refactor EvmGetInfoCmd --- cli/evm.go | 52 +++++++++++++---------------------- documentation/en/cli-lotus.md | 5 ++-- 2 files changed, 21 insertions(+), 36 deletions(-) diff --git a/cli/evm.go b/cli/evm.go index 5d6d05f49..1c02f92b4 100644 --- a/cli/evm.go +++ b/cli/evm.go @@ -38,25 +38,13 @@ var EvmCmd = &cli.Command{ } var EvmGetInfoCmd = &cli.Command{ - Name: "stat", - Usage: "Print eth/filecoin addrs and code cid", - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "filAddr", - Usage: "Filecoin address", - }, - &cli.StringFlag{ - Name: "ethAddr", - Usage: "Ethereum address", - }, - }, + Name: "stat", + Usage: "Print eth/filecoin addrs and code cid", + ArgsUsage: "address", Action: func(cctx *cli.Context) error { - - filAddr := cctx.String("filAddr") - ethAddr := cctx.String("ethAddr") - - var faddr address.Address - var eaddr ethtypes.EthAddress + if cctx.NArg() != 1 { + return IncorrectNumArgs(cctx) + } api, closer, err := GetFullNodeAPI(cctx) if err != nil { @@ -65,26 +53,25 @@ var EvmGetInfoCmd = &cli.Command{ defer closer() ctx := ReqContext(cctx) - if filAddr != "" { - addr, err := address.NewFromString(filAddr) - if err != nil { - return err - } - eaddr, faddr, err = ethAddrFromFilecoinAddress(ctx, addr, api) - if err != nil { - return err - } - } else if ethAddr != "" { - eaddr, err = ethtypes.ParseEthAddress(ethAddr) - if err != nil { - return err + addrString := cctx.Args().Get(0) + + var faddr address.Address + var eaddr ethtypes.EthAddress + addr, err := address.NewFromString(addrString) + if err != nil { // This isn't a filecoin address + eaddr, err = ethtypes.ParseEthAddress(addrString) + if err != nil { // This isn't an Eth address either + return xerrors.Errorf("address is not a filecoin or eth address") } faddr, err = eaddr.ToFilecoinAddress() if err != nil { return err } } else { - return xerrors.Errorf("Neither filAddr nor ethAddr specified") + eaddr, faddr, err = ethAddrFromFilecoinAddress(ctx, addr, api) + if err != nil { + return err + } } actor, err := api.StateGetActor(ctx, faddr, types.EmptyTSK) @@ -97,7 +84,6 @@ var EvmGetInfoCmd = &cli.Command{ fmt.Println("Code cid: ", actor.Code.String()) return nil - }, } diff --git a/documentation/en/cli-lotus.md b/documentation/en/cli-lotus.md index 5e0c7a305..04d6611bf 100644 --- a/documentation/en/cli-lotus.md +++ b/documentation/en/cli-lotus.md @@ -2596,11 +2596,10 @@ NAME: lotus evm stat - Print eth/filecoin addrs and code cid USAGE: - lotus evm stat [command options] [arguments...] + lotus evm stat [command options] address OPTIONS: - --ethAddr value Ethereum address - --filAddr value Filecoin address + --help, -h show help (default: false) ```