spenddag

package
v1.0.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExpected              = ierrors.New("expected error")
	ErrAlreadyPartOfSpendSet = ierrors.New("spender already part of SpendSet")
	ErrEntityEvicted         = ierrors.New("tried to operate on evicted entity")
	ErrFatal                 = ierrors.New("fatal error")
)

Functions

This section is empty.

Types

type Events

type Events[SpenderID, ResourceID comparable] struct {
	// SpenderCreated is triggered when a new Spender is created.
	SpenderCreated *event.Event1[SpenderID]

	// SpenderEvicted is triggered when a Spender is evicted from the SpendDAG.
	SpenderEvicted *event.Event1[SpenderID]

	// SpentResourcesAdded is triggered when the Spender is added to a new SpendSet.
	SpentResourcesAdded *event.Event2[SpenderID, ds.Set[ResourceID]]

	// SpenderParentsUpdated is triggered when the parents of a Spender are updated.
	SpenderParentsUpdated *event.Event2[SpenderID, ds.Set[SpenderID]]

	// SpenderAccepted is an event that gets triggered whenever a Spender is confirmed.
	SpenderAccepted *event.Event1[SpenderID]

	// SpenderRejected is an event that gets triggered whenever a Spender is rejected.
	SpenderRejected *event.Event1[SpenderID]

	event.Group[Events[SpenderID, ResourceID], *Events[SpenderID, ResourceID]]
}

Events is a container that acts as a dictionary for the events of a SpendDAG.

func NewEvents

func NewEvents[SpenderID, ResourceID comparable](optsLinkTarget ...*Events[SpenderID, ResourceID]) (events *Events[SpenderID, ResourceID])

NewEvents contains the constructor of the Events object (it is generated by a generic factory).

type IDType

type IDType interface {
	// comparable is a built-in constraint that ensures that the type can be used as a map key.
	comparable

	// Bytes returns a serialized version of the ID.
	Bytes() ([]byte, error)

	// String returns a human-readable version of the ID.
	String() string
}

IDType is the constraint for the identifier of a spend or a resource.

type ReadLockedSpendDAG

type ReadLockedSpendDAG[SpenderID, ResourceID IDType, VoteRank VoteRankType[VoteRank]] interface {
	LikedInstead(spenderIDs ds.Set[SpenderID]) ds.Set[SpenderID]
	FutureCone(spenderIDs ds.Set[SpenderID]) (futureCone ds.Set[SpenderID])
	ConflictingSpenders(spenderID SpenderID) (conflictingSpends ds.Set[SpenderID], exists bool)
	AcceptanceState(spenderIDs ds.Set[SpenderID]) acceptance.State
	UnacceptedSpenders(spenderIDs ds.Set[SpenderID]) ds.Set[SpenderID]
}

type SpendDAG

type SpendDAG[SpenderID, ResourceID IDType, VoteRank VoteRankType[VoteRank]] interface {
	Shutdown()
	Events() *Events[SpenderID, ResourceID]

	CreateSpender(id SpenderID)
	UpdateSpentResources(id SpenderID, resourceIDs ds.Set[ResourceID]) error

	ReadConsistent(callback func(spendDAG ReadLockedSpendDAG[SpenderID, ResourceID, VoteRank]) error) error
	UpdateSpenderParents(spenderID SpenderID, addedParentIDs, removedParentIDs ds.Set[SpenderID]) error
	FutureCone(spenderIDs ds.Set[SpenderID]) (futureCone ds.Set[SpenderID])
	ConflictingSpenders(spenderID SpenderID) (conflictingSpends ds.Set[SpenderID], exists bool)
	CastVotes(vote *vote.Vote[VoteRank], spenderIDs ds.Set[SpenderID]) error
	AcceptanceState(spenderIDs ds.Set[SpenderID]) acceptance.State
	SetAccepted(spenderID SpenderID)
	UnacceptedSpenders(spenderIDs ds.Set[SpenderID]) ds.Set[SpenderID]
	AllSpendsSupported(seat account.SeatIndex, spenderIDs ds.Set[SpenderID]) bool
	EvictSpender(spenderID SpenderID)

	SpendSets(spenderID SpenderID) (spendSetIDs ds.Set[ResourceID], exists bool)
	SpenderParents(spenderID SpenderID) (spenderIDs ds.Set[SpenderID], exists bool)
	SpendSetMembers(spendSetID ResourceID) (spenderIDs ds.Set[SpenderID], exists bool)
	SpenderWeight(spenderID SpenderID) int64
	SpenderChildren(spenderID SpenderID) (spenderIDs ds.Set[SpenderID], exists bool)
	SpenderVoters(spenderID SpenderID) (voters ds.Set[account.SeatIndex])
	LikedInstead(spenderIDs ds.Set[SpenderID]) ds.Set[SpenderID]
}

type VoteRankType

type VoteRankType[T any] interface {
	// Comparable imports the constraints.Comparable[T] interface to ensure that the type can be compared.
	constraints.Comparable[T]
}

VoteRankType is the constraint for the vote rank of a voter.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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