From ba1c0f0639e563a486e37b6ef40702f6a9f1f8b9 Mon Sep 17 00:00:00 2001 From: Fridrik Asmundsson Date: Tue, 6 Jun 2023 17:17:15 -0500 Subject: [PATCH] Add new lotus-shed command for computing eth hash for a given message cid --- cmd/lotus-shed/eth.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/cmd/lotus-shed/eth.go b/cmd/lotus-shed/eth.go index 1ebe2fb59aa..fde4f96f68f 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 + }, +}