block

package
v0.0.11-rc Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 11 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

This section is empty.

Functions

func NewBlockClient

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

NewBlockClient creates a new block client from the given dependencies and cometWebsocketURL. It uses a pre-defined committedBlocksQuery 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.EventsQueryClient - client.BlockQueryClient

func UnmarshalNewBlock

func UnmarshalNewBlock(blockMsgBz []byte) (client.Block, error)

UnmarshalNewBlock is a wrapper around UnmarshalNewBlockEvent to return an interface that satisfies the client.Block interface.

func WithConnRetryLimit

func WithConnRetryLimit(limit int) client.BlockClientOption

WithConnRetryLimit returns an option function which sets the number of times the underlying replay client should retry in the event that it encounters an error or its connection is interrupted. If connRetryLimit is < 0, it will retry indefinitely.

Types

type CometNewBlockEvent

type CometNewBlockEvent struct {
	Data struct {
		Value struct {
			// Block and BlockID are nested to match CometBFT's unique serialization,
			// diverging from the rollkit's approach seen in other implementations.
			Block               *types.Block  `json:"block"`
			BlockID             types.BlockID `json:"block_id"`
			ResultFinalizeBlock struct {
				Events []abci.Event `json:"events"`
			} `json:"result_finalize_block"`
		} `json:"value"`
	} `json:"data"`
}

CometNewBlockEvent is used to deserialize incoming committed block event messages from the respective events query subscription. It implements the client.Block interface by loosely wrapping cometbft's block type, into which messages are deserialized.

func UnmarshalNewBlockEvent

func UnmarshalNewBlockEvent(blockMsgBz []byte) (*CometNewBlockEvent, error)

UnmarshalNewBlockEvent is a function that attempts to deserialize the given bytes into a comet new block event . If the resulting block has a height of zero, assume the event was not a block event and return an ErrUnmarshalBlockEvent error.

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) Txs added in v0.0.2

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

Jump to

Keyboard shortcuts

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