dumpblocks

package
v0.1.118-dev Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: AGPL-3.0 Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DumpblocksCmd = &cobra.Command{
	Use:   "dumpblocks start end",
	Short: "Export a range of blocks from a JSON-RPC endpoint.",
	Long:  usage,
	Args:  cobra.MinimumNArgs(2),
	PreRunE: func(cmd *cobra.Command, args []string) (err error) {
		inputDumpblocks.RPCURL, err = flag.GetRPCURL(cmd)
		if err != nil {
			return err
		}
		return checkFlags(args)
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx := cmd.Context()
		ec, err := ethrpc.DialContext(ctx, inputDumpblocks.RPCURL)
		if err != nil {
			return err
		}

		var wg sync.WaitGroup
		log.Info().Uint("thread", inputDumpblocks.Threads).Msg("Thread count")
		var pool = make(chan bool, inputDumpblocks.Threads)
		start := inputDumpblocks.Start
		end := inputDumpblocks.End

		for start <= end {
			rangeStart := start
			rangeEnd := min(rangeStart+inputDumpblocks.BatchSize-1, end)

			pool <- true
			wg.Add(1)
			log.Info().Uint64("start", rangeStart).Uint64("end", rangeEnd).Msg("Getting range")
			go func() {
				defer wg.Done()
				for {
					failCount := 0
					blocks, err := util.GetBlockRange(ctx, rangeStart, rangeEnd, ec, inputDumpblocks.OnlyTxHashes)
					if err != nil {
						failCount = failCount + 1
						if failCount > 5 {
							log.Error().Uint64("rangeStart", rangeStart).Uint64("rangeEnd", rangeEnd).Msg("Unable to fetch blocks")
							break
						}
						time.Sleep(5 * time.Second)
						continue
					}

					blocks = filterBlocks(blocks)

					if inputDumpblocks.ShouldDumpBlocks {
						err = writeResponses(blocks, "block")
						if err != nil {
							log.Error().Err(err).Msg("Error writing blocks")
						}
					}

					if inputDumpblocks.ShouldDumpReceipts {
						failCount = 0
						receipts, err := util.GetReceipts(ctx, blocks, ec, inputDumpblocks.BatchSize)
						if err != nil {
							failCount = failCount + 1
							if failCount > 5 {
								log.Error().Uint64("rangeStart", rangeStart).Uint64("rangeEnd", rangeEnd).Msg("Unable to fetch receipts")
								break
							}
							time.Sleep(5 * time.Second)
							continue
						}

						err = writeResponses(receipts, "transaction")
						if err != nil {
							log.Error().Err(err).Msg("Error writing receipts")
						}
					}

					break
				}
				<-pool
			}()
			start = rangeEnd + 1
		}

		log.Info().Msg("Finished requesting data starting to wait")
		wg.Wait()
		log.Info().Msg("Done")

		return nil
	},
}

dumpblocksCmd represents the dumpblocks command

Functions

This section is empty.

Types

type Filter

type Filter struct {
	To   []string `json:"to"`
	From []string `json:"from"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL