Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var EcRecoverCmd = &cobra.Command{ Use: "ecrecover", Short: "Recovers and returns the public key of the signature", Long: usage, Args: cobra.NoArgs, PreRunE: func(cmd *cobra.Command, args []string) error { return checkFlags() }, Run: func(cmd *cobra.Command, args []string) { ctx := cmd.Context() var block *types.Block var err error if rpcUrl == "" { var blockJSON []byte if filePath != "" { blockJSON, err = os.ReadFile(filePath) if err != nil { log.Error().Err(err).Msg("Unable to read file") return } } else { blockJSON, err = io.ReadAll(os.Stdin) if err != nil { log.Error().Err(err).Msg("Unable to read stdin") return } } var header types.Header if err = json.Unmarshal(blockJSON, &header); err != nil { log.Error().Err(err).Msg("Unable to unmarshal JSON") return } block = types.NewBlockWithHeader(&header) blockNumber = header.Number.Uint64() } else { var rpc *ethrpc.Client rpc, err = ethrpc.DialContext(ctx, rpcUrl) if err != nil { log.Error().Err(err).Msg("Unable to dial rpc") return } ec := ethclient.NewClient(rpc) if blockNumber == 0 { blockNumber, err = ec.BlockNumber(ctx) if err != nil { log.Error().Err(err).Msg("Unable to retrieve latest block number") return } } block, err = ec.BlockByNumber(ctx, big.NewInt(int64(blockNumber))) if err != nil { log.Error().Err(err).Msg("Unable to retrieve block") return } } signerBytes, err := util.Ecrecover(block) if err != nil { log.Error().Err(err).Msg("Unable to recover signature") return } cmd.Printf("Recovering signer from block #%d\n", blockNumber) cmd.Println(ethcommon.BytesToAddress(signerBytes)) }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.