chainutil

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchBlocks

func FetchBlocks(ctx context.Context, rpc *rpcclient.HTTP, fromHeight, toHeight int64) (
	[]*coretypes.ResultBlock, []*coretypes.ResultBlockResults, error)

FetchBlocks fetches blocks and their results from the CometBFT RPC server.

Types

type Node

type Node struct {
	Id             string
	RemoteURL      string
	AppVersion     *semver.Version
	EarliestHeight int64
	LatestHeight   int64
	RPC            *rpcclient.HTTP
}

Node represents a cometbft node with its remote address, application version, and base height.

type Nodes

type Nodes []Node

Nodes is a slice of Node, representing a collection of discovered nodes.

func DiscoverNodes

func DiscoverNodes(
	ctx context.Context,
	remotes []string,
	expand bool,
	logger *slog.Logger,
) (Nodes, error)

DiscoverNodes fetches some basic information about the nodes from the given remotes. If `expand` is true, it will also expand the remotes by querying the the chain network info.

func (Nodes) ByHeightRange

func (nodes Nodes) ByHeightRange(minHeight, maxHeight int64) Nodes

ByHeightRange filters the discovered nodes by the given height range.

func (Nodes) ConstrainByVersion

func (nodes Nodes) ConstrainByVersion(c semver.Constraints) Nodes

ConstrainByVersion filters the discovered nodes by the given semver constraints.

func (Nodes) EarliestAvailableHeight

func (nodes Nodes) EarliestAvailableHeight() int64

EarliestAvailableHeight returns the minimum earliest height among the discovered nodes.

func (Nodes) LatestAvailableHeight

func (nodes Nodes) LatestAvailableHeight() int64

LatestAvailableHeight returns the maximum latest height among the discovered nodes.

func (Nodes) LatestVersion

func (nodes Nodes) LatestVersion() Nodes

LatestVersion returns the nodes with the latest application version.

func (Nodes) PickRandom

func (nodes Nodes) PickRandom() Node

PickRandom returns a random node from the discovered nodes. If the slice is empty, it returns nil.

Jump to

Keyboard shortcuts

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