block

package
v0.1.34 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package block contains a light wrapper of the EventsReplayClient[Block] generic which listens for committed block events on chain and emits them through a ReplayObservable. This enables consumers to listen for newly committed blocks and react to them asynchronously.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnmarshalBlockEvent       = sdkerrors.Register(codespace, 1, "failed to unmarshal block event")
	ErrUnmarshalBlockHeaderEvent = sdkerrors.Register(codespace, 2, "failed to unmarshal block header event")
)

Functions

func IsChainAfterAddPayloadHashInRelayResponse added in v0.1.27

func IsChainAfterAddPayloadHashInRelayResponse(chainVersion *version.Version) bool

TODO(v0.1.26): Remove this once all actors (validators, gateways, relayminers) on the network are upgraded to v0.1.26.

Compare the chain version with the chainVersionAddPayloadHashInRelayResponse.

- If chainVersion >= chainVersionAddPayloadHashInRelayResponse:

  • Compute the payload hash
  • Include the payload hash in the RelayResponse.
  • Omit the full payload from the RelayResponse.

- If chainVersion < chainVersionAddPayloadHashInRelayResponse:

  • Remain backward compatible with older versions of the Network
  • Include the full payload in the RelayResponse.
  • Do not compute the payload hash at all

func NewBlockClient

func NewBlockClient(
	ctx context.Context,
	deps depinject.Config,
) (_ client.BlockClient, err error)

NewBlockClient creates a new block client from the given dependencies.

It uses a pre-defined cometNewBlockHeaderQuery to subscribe to newly committed block events which are mapped to Block objects.

This lightly wraps the EventsReplayClient[Block] generic to correctly mock the interface.

Required dependencies: - client.BlockQueryClient

func UnmarshalNewBlock

func UnmarshalNewBlock(resultEvent *coretypes.ResultEvent) (client.Block, error)

UnmarshalNewBlock deserializes a CometBFT ResultEvent into a client.Block implementation. - Processes events from subscriptions with query `tx.NewBlockHeader` - Contains only block header data (more efficient than full block events) - Returns error if the event data is not of type EventDataNewBlockHeader

Types

type CometBlockResult added in v0.1.2

type CometBlockResult coretypes.ResultBlock

CometBlockResult is a non-alias of the comet ResultBlock type that implements the client.Block interface. It is used across the codebase to standardize the access to a block's height and hash across different block clients.

func (*CometBlockResult) Hash added in v0.1.2

func (cbr *CometBlockResult) Hash() []byte

func (*CometBlockResult) Height added in v0.1.2

func (cbr *CometBlockResult) Height() int64

func (*CometBlockResult) Txs added in v0.1.2

func (cbr *CometBlockResult) Txs() []types.Tx

type CometNewBlockEvent

type CometNewBlockEvent struct {
	*types.EventDataNewBlock
}

CometNewBlockEvent represents a committed block event received from a CometBFT event subscription. - Used to receive a committed block event from a CometBFT event subscription. - Wraps the CometBFT EventDataNewBlock type for deserialization and access to the full block data. - Implements the client.Block interface.

func UnmarshalNewBlockEvent

func UnmarshalNewBlockEvent(resultEvent *coretypes.ResultEvent) (*CometNewBlockEvent, error)

UnmarshalNewBlockEvent deserializes a CometBFT ResultEvent into a CometNewBlockEvent. - Processes events from subscriptions with query `tx.NewBlock` - Contains full block data including transactions and events - Returns error if the event data is not of type EventDataNewBlock

func (*CometNewBlockEvent) Events added in v0.1.23

func (blockEvent *CometNewBlockEvent) Events() []abcitypes.Event

Events returns the list of ABCI events emitted during block finalization.

func (*CometNewBlockEvent) Hash

func (blockEvent *CometNewBlockEvent) Hash() []byte

Hash returns the binary representation of the block's hash as a byte slice.

func (*CometNewBlockEvent) Height

func (blockEvent *CometNewBlockEvent) Height() int64

Height returns the block's height.

func (*CometNewBlockEvent) TxResults added in v0.1.23

func (blockEvent *CometNewBlockEvent) TxResults() []*abcitypes.ExecTxResult

TxResults returns the list of ABCI transaction results emitted during block finalization.

func (*CometNewBlockEvent) Txs added in v0.0.2

func (blockEvent *CometNewBlockEvent) Txs() []types.Tx

Txs returns the list of transactions included in the block.

type CometNewBlockHeader added in v0.1.23

type CometNewBlockHeader struct {
	*types.EventDataNewBlockHeader
}

CometNewBlockHeader wraps EventDataNewBlockHeader to provide additional methods for block header data. - Used to receive a minimal information about a new block - Omits transmitting the entire tx list and finalization events. - Implements the client.Block interface.

func (*CometNewBlockHeader) Hash added in v0.1.23

func (blockHeader *CometNewBlockHeader) Hash() []byte

Hash returns the binary representation of the block header's hash as a byte slice. It uses BlockID.Hash, not LastBlockID.Hash, to ensure the hash corresponds to the current block.

func (*CometNewBlockHeader) Height added in v0.1.23

func (blockHeader *CometNewBlockHeader) Height() int64

Height returns the block's height.

Jump to

Keyboard shortcuts

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