dag

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 dag provides shared DAG indexing for LUX chains (X, A, B, Q, T, Z). Based on luxfi/consensus/engine/dag/vertex - multiple parents per vertex.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

type Adapter interface {
	ParseVertex(data json.RawMessage) (*Vertex, error)
	GetRecentVertices(ctx context.Context, limit int) ([]json.RawMessage, error)
	GetVertexByID(ctx context.Context, id string) (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 ChainType

type ChainType string

ChainType identifies the DAG chain

const (
	ChainX ChainType = "xchain" // Exchange - assets, UTXOs
	ChainA ChainType = "achain" // AI - attestations, compute
	ChainB ChainType = "bchain" // Bridge - cross-chain
	ChainQ ChainType = "qchain" // Quantum - finality proofs
	ChainT ChainType = "tchain" // Teleport - MPC signatures
	ChainZ ChainType = "zchain" // Privacy - ZK transactions (DAG for fast consensus, proofs for privacy)
	ChainK ChainType = "kchain" // KMS - Post-quantum key material
)

type Config

type Config struct {
	ChainType    ChainType
	ChainName    string
	RPCEndpoint  string
	RPCMethod    string // xvm, bvm, qvm, tvm
	HTTPPort     int
	PollInterval time.Duration
	DataDir      string // For default storage, defaults to ~/.lux/indexer/<chain>
}

Config for DAG indexer

type Edge

type Edge struct {
	Source string   `json:"source"`
	Target string   `json:"target"`
	Type   EdgeType `json:"type"`
}

Edge represents a DAG edge (parent relationship)

type EdgeType

type EdgeType string

EdgeType categorizes edges

const (
	EdgeParent    EdgeType = "parent"    // DAG parent reference
	EdgeInput     EdgeType = "input"     // UTXO input
	EdgeOutput    EdgeType = "output"    // UTXO output
	EdgeReference EdgeType = "reference" // General reference
)

type Indexer

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

Indexer for DAG-based chains

func New

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

New creates a new DAG 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) StoreEdge

func (idx *Indexer) StoreEdge(ctx context.Context, e Edge) error

StoreEdge stores an edge

func (*Indexer) StoreVertex

func (idx *Indexer) StoreVertex(ctx context.Context, v *Vertex) error

StoreVertex stores a vertex 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 vertices

func NewPoller

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

func (*Poller) Run

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

type Stats

type Stats struct {
	TotalVertices    int64     `json:"total_vertices"`
	PendingVertices  int64     `json:"pending_vertices"`
	AcceptedVertices int64     `json:"accepted_vertices"`
	TotalEdges       int64     `json:"total_edges"`
	ChainType        ChainType `json:"chain_type"`
	LastUpdated      time.Time `json:"last_updated"`
}

Stats for DAG chain

type Status

type Status string

Status of vertex consensus

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

type Subscriber

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

Subscriber handles WebSocket for live DAG streaming

func NewSubscriber

func NewSubscriber(ct ChainType) *Subscriber

func (*Subscriber) BroadcastEdge

func (s *Subscriber) BroadcastEdge(e Edge)

func (*Subscriber) BroadcastVertex

func (s *Subscriber) BroadcastVertex(v *Vertex)

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)

type Vertex

type Vertex struct {
	ID         string                 `json:"id"`
	Type       string                 `json:"type"`
	ParentIDs  []string               `json:"parentIds"` // Multiple parents (DAG)
	Height     uint64                 `json:"height"`
	Epoch      uint32                 `json:"epoch,omitempty"`
	TxIDs      []string               `json:"txIds,omitempty"`
	Timestamp  time.Time              `json:"timestamp"`
	Status     Status                 `json:"status"`
	Data       json.RawMessage        `json:"data,omitempty"`
	Metadata   map[string]interface{} `json:"metadata,omitempty"`
	QuasarCert json.RawMessage        `json:"quasarCert,omitempty"` // Triple consensus cert (Q-Chain)
}

Vertex represents a DAG vertex (from luxfi/consensus) Multiple parents allowed (DAG structure)

Jump to

Keyboard shortcuts

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