weight

package
v1.0.0-alpha.24 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparison

type Comparison = int

Comparison is the result of a comparison between two values.

const (
	// Lighter is the result of a comparison between two values when the first value is lighter than the second value.
	Lighter Comparison = -1

	// Equal is the result of a comparison between two values when the first value is equal to the second value.
	Equal Comparison = 0

	// Heavier is the result of a comparison between two values when the first value is heavier than the second value.
	Heavier Comparison = 1
)

type Value

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

Value represents an immutable multi-tiered weight value, which is used to determine the order of spenders.

func (Value) AcceptanceState

func (v Value) AcceptanceState() acceptance.State

AcceptanceState returns the acceptance state of the Value.

func (Value) AddCumulativeWeight

func (v Value) AddCumulativeWeight(weight int64) Value

AddCumulativeWeight adds the given weight to the cumulative weight of the Value and returns the new Value.

func (Value) AttestorsWeight

func (v Value) AttestorsWeight() int64

AttestorsWeight returns the weight of the validators.

func (Value) Compare

func (v Value) Compare(other Value) Comparison

Compare compares the Value to the given other Value and returns the result of the comparison.

func (Value) CumulativeWeight

func (v Value) CumulativeWeight() int64

CumulativeWeight returns the cumulative weight of the Value.

func (Value) RemoveCumulativeWeight

func (v Value) RemoveCumulativeWeight(weight int64) Value

RemoveCumulativeWeight removes the given weight from the cumulative weight of the Value and returns the new Value.

func (Value) SetAcceptanceState

func (v Value) SetAcceptanceState(acceptanceState acceptance.State) Value

SetAcceptanceState sets the acceptance state of the Value and returns the new Value.

func (Value) SetAttestorsWeight

func (v Value) SetAttestorsWeight(weight int64) Value

SetAttestorsWeight sets the weight of the attestors and returns the new Value.

func (Value) SetCumulativeWeight

func (v Value) SetCumulativeWeight(cumulativeWeight int64) Value

SetCumulativeWeight sets the cumulative weight of the Value and returns the new Value.

func (Value) SetValidatorsWeight

func (v Value) SetValidatorsWeight(weight int64) Value

SetValidatorsWeight sets the weight of the validators and returns the new Value.

func (Value) String

func (v Value) String() string

String returns a human-readable representation of the Value.

func (Value) ValidatorsWeight

func (v Value) ValidatorsWeight() int64

ValidatorsWeight returns the weight of the validators.

type Weight

type Weight struct {
	// OnUpdate is an event that is triggered when the weight value is updated.
	OnUpdate *event.Event1[Value]

	// Voters is the set of voters contributing to the weight
	Voters ds.Set[account.SeatIndex]

	// Attestors is the set of attestors contributing to the weight.
	Attestors ds.Set[account.SeatIndex]
	// contains filtered or unexported fields
}

Weight represents a mutable multi-tiered weight value that can be updated in-place.

func New

func New() *Weight

New creates a new Weight instance.

func (*Weight) AcceptanceState

func (w *Weight) AcceptanceState() acceptance.State

AcceptanceState returns the acceptance state of the weight.

func (*Weight) AddAttestor

func (w *Weight) AddAttestor(seat account.SeatIndex) *Weight

AddAttestor adds the given voter to the list of Attestors, updates the weight and returns the Weight (for chaining).

func (*Weight) AddCumulativeWeight

func (w *Weight) AddCumulativeWeight(delta int64) *Weight

AddCumulativeWeight adds the given weight to the cumulative weight and returns the Weight (for chaining).

func (*Weight) AddVoter

func (w *Weight) AddVoter(seat account.SeatIndex) *Weight

AddVoter adds the given voter to the list of Voters, updates the weight and returns the Weight (for chaining).

func (*Weight) Compare

func (w *Weight) Compare(other *Weight) Comparison

Compare compares the Weight to the given other Weight.

func (*Weight) CumulativeWeight

func (w *Weight) CumulativeWeight() int64

CumulativeWeight returns the cumulative weight of the Weight.

func (*Weight) DeleteAttestor

func (w *Weight) DeleteAttestor(seat account.SeatIndex) *Weight

DeleteAttestor removes the given voter from the list of Attestors, updates the weight and returns the Weight (for chaining).

func (*Weight) DeleteVoter

func (w *Weight) DeleteVoter(seat account.SeatIndex) *Weight

DeleteVoter removes the given voter from the list of Voters, updates the weight and returns the Weight (for chaining).

func (*Weight) RemoveCumulativeWeight

func (w *Weight) RemoveCumulativeWeight(delta int64) *Weight

RemoveCumulativeWeight removes the given weight from the cumulative weight and returns the Weight (for chaining).

func (*Weight) ResetAttestors

func (w *Weight) ResetAttestors() *Weight

ResetAttestors removes all voters from the list of Attestors, updates the weight and returns the Weight (for chaining).

func (*Weight) SetAcceptanceState

func (w *Weight) SetAcceptanceState(acceptanceState acceptance.State) (previousState acceptance.State)

SetAcceptanceState sets the acceptance state of the weight and returns the previous acceptance state.

func (*Weight) SetCumulativeWeight

func (w *Weight) SetCumulativeWeight(cumulativeWeight int64) *Weight

SetCumulativeWeight sets the cumulative weight of the Weight and returns the Weight (for chaining).

func (*Weight) String

func (w *Weight) String() string

String returns a human-readable representation of the Weight.

func (*Weight) Value

func (w *Weight) Value() Value

Value returns an immutable copy of the Weight.

func (*Weight) WithAcceptanceState

func (w *Weight) WithAcceptanceState(acceptanceState acceptance.State) *Weight

WithAcceptanceState sets the acceptance state of the weight and returns the Weight instance.

Jump to

Keyboard shortcuts

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