slot

package
v0.0.0-...-15a9106 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: Apache-2.0, BSD-2-Clause Imports: 4 Imported by: 53

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Index

type Index int64

Index is the ID of a slot.

func IndexFromBytes

func IndexFromBytes(bytes []byte) (ei Index, consumedBytes int, err error)

func (Index) Abs

func (i Index) Abs() (absolute Index)

Abs returns the absolute value of the Index.

func (Index) Bytes

func (i Index) Bytes() []byte

func (Index) Length

func (i Index) Length() int

func (Index) Max

func (i Index) Max(other Index) Index

Max returns the maximum of the two given slots.

func (Index) String

func (i Index) String() string

type IndexedEntity

type IndexedEntity[IDType IndexedID] interface {
	ID() IDType
}

type IndexedID

type IndexedID interface {
	comparable

	Index() Index
	String() string
}

type TimeProvider

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

TimeProvider defines the genesis time of slot 0 and allows to convert index to and from time.

func NewTimeProvider

func NewTimeProvider(genesisUnixTime int64, slotDuration int64) *TimeProvider

NewTimeProvider creates a new time provider.

func (*TimeProvider) Duration

func (t *TimeProvider) Duration() int64

Duration is the slot duration in seconds.

func (*TimeProvider) EndTime

func (t *TimeProvider) EndTime(i Index) time.Time

EndTime returns the latest possible timestamp for a slot. Anything with higher timestamp will belong to the next slot.

func (*TimeProvider) GenesisTime

func (t *TimeProvider) GenesisTime() time.Time

GenesisTime is the time of the genesis.

func (*TimeProvider) GenesisUnixTime

func (t *TimeProvider) GenesisUnixTime() int64

GenesisUnixTime is the time (Unix in seconds) of the genesis.

func (*TimeProvider) IndexFromTime

func (t *TimeProvider) IndexFromTime(time time.Time) Index

IndexFromTime calculates the Index from the given time.

Note: slots are counted starting from 1 because 0 is reserved for the genesis which has to be addressable as its own slot as part of the commitment chains.

func (*TimeProvider) StartTime

func (t *TimeProvider) StartTime(i Index) time.Time

StartTime calculates the start time of the given slot.

Jump to

Keyboard shortcuts

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