Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var QueryCmd = &cobra.Command{ Use: "query [enode/enr]", Short: "Query block header(s) from node and prints the output.", Long: `Query header of single block or range of blocks given a single enode/enr. This command will initially establish a handshake and exchange status message from the peer. Then, it will query the node for block(s) given the start block and the amount of blocks to query and print the results.`, Args: cobra.MinimumNArgs(1), PreRunE: func(cmd *cobra.Command, args []string) (err error) { if inputQueryParams.Amount < 1 { return fmt.Errorf("amount must be greater than 0") } inputQueryParams.privateKey, err = p2p.ParsePrivateKey(inputQueryParams.KeyFile, inputQueryParams.PrivateKey) if err != nil { return err } return nil }, Run: func(cmd *cobra.Command, args []string) { node, err := p2p.ParseNode(args[0]) if err != nil { log.Error().Err(err).Msg("Unable to parse enode") return } var ( hello *p2p.Hello status *p2p.Status start = inputQueryParams.StartBlock amount = inputQueryParams.Amount ) opts := p2p.DialOpts{ Port: inputQueryParams.Port, Addr: inputQueryParams.Addr, PrivateKey: inputQueryParams.privateKey, } conn, err := p2p.Dial(node, opts) if err != nil { log.Error().Err(err).Msg("Dial failed") return } defer func() { if closeErr := conn.Close(); closeErr != nil { log.Debug().Err(closeErr).Msg("Failed to close p2p connection") } }() if hello, status, err = conn.Peer(); err != nil { log.Error().Err(err).Msg("Peer failed") return } log.Info().Interface("hello", hello).Interface("status", status).Msg("Peering messages received") log.Info().Uint64("start", start).Uint64("amount", amount).Msg("Requesting headers") if err = conn.QueryHeaders(start, amount); err != nil { log.Error().Err(err).Msg("Failed to request header(s)") return } headers, err := conn.ListenHeaders() if err != nil { log.Error().Err(err).Msg("Failed to listen for header(s)") return } if len(headers) != int(amount) { log.Error().Uint64("want", amount).Int("have", len(headers)).Msg("Received less headers than requested") return } var ( headerStart = headers[0].Number.Uint64() headerEnd = headers[len(headers)-1].Number.Uint64() end = start + amount - 1 ) if headerStart != start || headerEnd != end { log.Error().Uint64("start", start).Uint64("end", end).Uint64("header start", headerStart).Uint64("header end", headerEnd).Msg("Received headers out of range") return } print(headers) }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.