Refactor EvmGetInfoCmd

This commit is contained in:
Geoff Stuart 2023-01-20 16:23:56 -05:00
parent 550eef131c
commit fff58e1368
2 changed files with 21 additions and 36 deletions

View File

@ -40,23 +40,11 @@ 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",
},
},
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
},
}

View File

@ -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)
```