diff --git a/cmd/lotus-shed/eth.go b/cmd/lotus-shed/eth.go index 1ebe2fb59a..fde4f96f68 100644 --- a/cmd/lotus-shed/eth.go +++ b/cmd/lotus-shed/eth.go @@ -9,6 +9,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/chain/types/ethtypes" lcli "github.com/filecoin-project/lotus/cli" ) @@ -23,6 +24,7 @@ var ethCmd = &cli.Command{ }, Subcommands: []*cli.Command{ checkTipsetsCmd, + computeEthHashCmd, }, } @@ -70,3 +72,36 @@ var checkTipsetsCmd = &cli.Command{ return nil }, } + +var computeEthHashCmd = &cli.Command{ + Name: "compute-eth-hash", + Usage: "Compute the eth hash for a given message CID", + Action: func(cctx *cli.Context) error { + if cctx.NArg() != 1 { + return lcli.IncorrectNumArgs(cctx) + } + + msg, err := messageFromString(cctx, cctx.Args().First()) + if err != nil { + return err + } + + switch msg := msg.(type) { + case *types.SignedMessage: + tx, err := ethtypes.EthTxFromSignedEthMessage(msg) + if err != nil { + return fmt.Errorf("failed to convert from signed message: %w", err) + } + + tx.Hash, err = tx.TxHash() + if err != nil { + return fmt.Errorf("failed to call TxHash: %w", err) + } + fmt.Println(tx.Hash) + default: + return fmt.Errorf("not a signed message") + } + + return nil + }, +}