dag

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DAG

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

DAG manages the directed acyclic graph of events

func NewDAG

func NewDAG() *DAG

NewDAG creates a new DAG instance

func (*DAG) AddEvent

func (d *DAG) AddEvent(event *Event) error

AddEvent adds a new event to the DAG

func (*DAG) GetAllEvents

func (d *DAG) GetAllEvents() []*Event

GetAllEvents returns all events in the DAG

func (*DAG) GetEvent

func (d *DAG) GetEvent(id string) (*Event, error)

GetEvent retrieves an event by ID

func (*DAG) VerifyEventChain

func (d *DAG) VerifyEventChain(eventID string) error

VerifyEventChain verifies the integrity of an event and its ancestors

type Event

type Event struct {
	ID        string    `json:"id"`
	Data      []byte    `json:"data"`
	Parents   []string  `json:"parents"` // References to previous events in DAG
	Timestamp time.Time `json:"timestamp"`

	// Optional beacon reference
	BeaconRound uint64 `json:"beacon_round,omitempty"`
	BeaconHash  string `json:"beacon_hash,omitempty"`

	// Sub-events support
	ParentEvent string   `json:"parent_event,omitempty"` // ID of the parent event if this is a sub-event
	SubEvents   []string `json:"sub_events,omitempty"`   // IDs of any sub-events
	IsSubEvent  bool     `json:"is_sub_event,omitempty"` // Flag to distinguish sub-events
}

Event represents a node in the DAG

func NewEvent

func NewEvent(data []byte, parents []string) (*Event, error)

NewEvent creates a new event with the given data and parents

func NewSubEvent

func NewSubEvent(data []byte, parentEventID string, additionalParents []string) (*Event, error)

NewSubEvent creates a new sub-event connected to a parent event

func (*Event) AddSubEvent

func (e *Event) AddSubEvent(subEventID string)

AddSubEvent adds a sub-event to this event

func (*Event) SetBeaconRound

func (e *Event) SetBeaconRound(round uint64, randomness []byte)

SetBeaconRound sets the beacon round reference for this event

Jump to

Keyboard shortcuts

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