Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new lotus-shed command for computing eth hash for a given mcid #10961

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions cmd/lotus-shed/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -23,6 +24,7 @@ var ethCmd = &cli.Command{
},
Subcommands: []*cli.Command{
checkTipsetsCmd,
computeEthHashCmd,
},
}

Expand Down Expand Up @@ -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
},
}