chain

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package chain provides shared linear chain indexing for LUX chains (P). Based on luxfi/consensus/engine/chain/block - single parent per block.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	ParseBlock(data json.RawMessage) (*Block, error)
	GetRecentBlocks(ctx context.Context, limit int) ([]json.RawMessage, error)
	GetBlockByID(ctx context.Context, id string) (json.RawMessage, error)
	GetBlockByHeight(ctx context.Context, height uint64) (json.RawMessage, error)
	InitSchema(ctx context.Context, store storage.Store) error
	GetStats(ctx context.Context, store storage.Store) (map[string]interface{}, error)
}

Adapter interface for chain-specific logic

type Block

type Block struct {
	ID        string                 `json:"id"`
	ParentID  string                 `json:"parentId"` // Single parent (linear)
	Height    uint64                 `json:"height"`
	Timestamp time.Time              `json:"timestamp"`
	Status    Status                 `json:"status"`
	TxCount   int                    `json:"txCount,omitempty"`
	TxIDs     []string               `json:"txIds,omitempty"`
	Data      json.RawMessage        `json:"data,omitempty"`
	Metadata  map[string]interface{} `json:"metadata,omitempty"`
}

Block represents a linear chain block (from luxfi/consensus) Single parent only (linear chain structure)

type ChainType

type ChainType string

ChainType identifies the linear chain

const (
	ChainP ChainType = "pchain" // Platform - validators, staking

)

type Config

type Config struct {
	ChainType    ChainType
	ChainName    string
	RPCEndpoint  string
	RPCMethod    string // pvm
	HTTPPort     int
	PollInterval time.Duration
	DataDir      string // For default storage
}

Config for chain indexer

type Indexer

type Indexer struct {
	// contains filtered or unexported fields
}

Indexer for linear chains

func New

func New(cfg Config, store storage.Store, adapter Adapter) (*Indexer, error)

New creates a new chain indexer with the given storage

func (*Indexer) Init

func (idx *Indexer) Init(ctx context.Context) error

Init creates database schema

func (*Indexer) Run

func (idx *Indexer) Run(ctx context.Context) error

Run starts the indexer

func (*Indexer) Store added in v0.3.0

func (idx *Indexer) Store() storage.Store

Store returns the underlying storage for adapters

func (*Indexer) StoreBlock

func (idx *Indexer) StoreBlock(ctx context.Context, b *Block) error

StoreBlock stores a block and broadcasts to subscribers

func (*Indexer) UpdateStats

func (idx *Indexer) UpdateStats(ctx context.Context) error

UpdateStats updates statistics

type Poller

type Poller struct {
	// contains filtered or unexported fields
}

Poller polls for new blocks

func NewPoller

func NewPoller(idx *Indexer, sub *Subscriber) *Poller

func (*Poller) Run

func (p *Poller) Run(ctx context.Context)

type Stats

type Stats struct {
	TotalBlocks    int64     `json:"total_blocks"`
	LatestHeight   uint64    `json:"latest_height"`
	PendingBlocks  int64     `json:"pending_blocks"`
	AcceptedBlocks int64     `json:"accepted_blocks"`
	ChainType      ChainType `json:"chain_type"`
	LastUpdated    time.Time `json:"last_updated"`
}

Stats for linear chain

type Status

type Status string

Status of block consensus

const (
	StatusPending   Status = "pending"
	StatusAccepted  Status = "accepted"
	StatusRejected  Status = "rejected"
	StatusFinalized Status = "finalized"
)

type Subscriber

type Subscriber struct {
	// contains filtered or unexported fields
}

Subscriber handles WebSocket for live block streaming

func NewSubscriber

func NewSubscriber(ct ChainType) *Subscriber

func (*Subscriber) BroadcastBlock

func (s *Subscriber) BroadcastBlock(b *Block)

func (*Subscriber) ClientCount

func (s *Subscriber) ClientCount() int

func (*Subscriber) HandleWebSocket

func (s *Subscriber) HandleWebSocket(w http.ResponseWriter, r *http.Request)

func (*Subscriber) Run

func (s *Subscriber) Run(ctx context.Context)

Jump to

Keyboard shortcuts

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