Help us shape the future of Go! Take the 2026 Go Developer Survey

comet

package
v0.1.119 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package comet provides typed fetch helpers for the CometBFT JSON-RPC endpoints shared by the heimdall subcommand families (chain, milestone). We decode only the fields actually used; the raw JSON is returned alongside where callers need passthrough.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockTime

func BlockTime(ctx context.Context, rpc *client.RPCClient, h int64) (time.Time, error)

BlockTime fetches /block at h and returns the header's time parsed as a Go time.Time. Separate from FetchBlock for tightness.

func FindBlockAt

func FindBlockAt(ctx context.Context, rpc *client.RPCClient, lo, hi int64, target time.Time) (int64, error)

FindBlockAt binary-searches the closed range [lo, hi] for the height whose block time is closest to target. Cancellable via ctx.

Heimdall block times are monotonically non-decreasing so bsearch applies. The fetch-per-step cost is the dominant factor so we cap at log2(hi-lo+1) + 1 probes.

func ParseTimestamp

func ParseTimestamp(s string) (time.Time, error)

ParseTimestamp accepts either a bare unix-second integer or an RFC3339 / RFC3339Nano string. Returns a time.Time in UTC.

Types

type ABCIEvent

type ABCIEvent struct {
	Type       string `json:"type"`
	Attributes []struct {
		Key   string `json:"key"`
		Value string `json:"value"`
	} `json:"attributes"`
}

ABCIEvent is one event from a CometBFT /block_results response. Attribute keys/values are plain strings on CometBFT 0.38.

type Block

type Block struct {
	BlockID struct {
		Hash string `json:"hash"`
	} `json:"block_id"`
	Block struct {
		Header struct {
			ChainID         string `json:"chain_id"`
			Height          string `json:"height"`
			Time            string `json:"time"`
			ProposerAddress string `json:"proposer_address"`
		} `json:"header"`
		Data struct {
			Txs []string `json:"txs"`
		} `json:"data"`
	} `json:"block"`
}

Block is the subset of the CometBFT /block response we consume.

func FetchBlock

func FetchBlock(ctx context.Context, rpc *client.RPCClient, height string) (*Block, json.RawMessage, error)

FetchBlock calls CometBFT /block at the given height (empty == latest). Returns the typed struct, the raw result bytes (for --json passthrough), and any error. Both return values are nil when --curl short-circuits.

type BlockResults

type BlockResults struct {
	Height              string      `json:"height"`
	FinalizeBlockEvents []ABCIEvent `json:"finalize_block_events"`
}

BlockResults is the subset of /block_results we consume.

func FetchBlockResults

func FetchBlockResults(ctx context.Context, rpc *client.RPCClient, height int64) (*BlockResults, error)

FetchBlockResults calls CometBFT /block_results at the given height. Returns (nil, nil) when --curl short-circuits.

type Status

type Status struct {
	NodeInfo struct {
		Version string `json:"version"`
		Network string `json:"network"`
		Moniker string `json:"moniker"`
	} `json:"node_info"`
	SyncInfo struct {
		LatestBlockHeight   string `json:"latest_block_height"`
		LatestBlockTime     string `json:"latest_block_time"`
		EarliestBlockHeight string `json:"earliest_block_height"`
		CatchingUp          bool   `json:"catching_up"`
	} `json:"sync_info"`
}

Status is the subset of the CometBFT /status response we consume.

func FetchStatus

func FetchStatus(ctx context.Context, rpc *client.RPCClient) (*Status, error)

FetchStatus calls the CometBFT /status RPC and returns the decoded struct. Returns (nil, nil) when running under --curl.

Jump to

Keyboard shortcuts

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