Skip to content

Commit

Permalink
Refactor EvmGetInfoCmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Stuart committed Jan 20, 2023
1 parent 8835b44 commit 80805df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
50 changes: 18 additions & 32 deletions cli/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
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")
}
} else if ethAddr != "" {
eaddr, err = ethtypes.ParseEthAddress(ethAddr)
faddr, err = eaddr.ToFilecoinAddress()
if err != nil {
return err
}
faddr, err = eaddr.ToFilecoinAddress()
} else {
eaddr, faddr, err = ethAddrFromFilecoinAddress(ctx, addr, api)
if err != nil {
return err
}
} else {
return xerrors.Errorf("Neither filAddr nor ethAddr specified")
}

actor, err := api.StateGetActor(ctx, faddr, types.EmptyTSK)
Expand All @@ -97,7 +84,6 @@ var EvmGetInfoCmd = &cli.Command{
fmt.Println("Code cid: ", actor.Code.String())

return nil

},
}

Expand Down
5 changes: 2 additions & 3 deletions documentation/en/cli-lotus.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

Expand Down

0 comments on commit 80805df

Please sign in to comment.