utils

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayToMap

func ArrayToMap[T, K comparable](ts []T, kf func(T) K) map[K]T

Create a map from array with kf providing keys, values are array elements

func ArrayToPtrMap

func ArrayToPtrMap[T, K comparable](ts []T, kf func(T) K) map[K]*T

Create a map from array with kf providing keys, values are pointers to array elements

func CastArray

func CastArray[T, V any](a []V) ([]T, error)

func Hex20ToBytes20

func Hex20ToBytes20(str string) (result [20]byte, err error)

func Join

func Join(errs ...error) error

Use errors.Join when upgrading to Go 1.20

func Keys

func Keys[K comparable, V any](m map[K]V) []K

func Map

func Map[T, V any](ins []T, f func(T) V) []V

func NewRandomizedTicker

func NewRandomizedTicker(interval time.Duration, randomDelta time.Duration) <-chan time.Time

func PadHexString

func PadHexString(value string, length int) (string, error)

Checks if the string is a valid hex string and pad it to the given length (even number)

func TransactionHexToBytes32

func TransactionHexToBytes32(address string) (result [32]byte, err error)

func TransformSignatureRSVtoVRS

func TransformSignatureRSVtoVRS(rsv []byte) (vrs []byte)

Transform signature transforms [R || S || V - 27] to [V || R || S]. No checks are performed, we assume that signature array has length 65

func TransformSignatureVRStoRSV

func TransformSignatureVRStoRSV(vrs []byte) (rsv []byte)

Transform signature to be used by go-ethereum crypto.SigToPub: transforms [V || R || S] to [R || S || V - 27] No checks are performed, we assume that signature array has length 65

func UInt16ToHex

func UInt16ToHex(value uint16) string

func UInt32ToHex

func UInt32ToHex(value uint32) string

func UInt64ToHex

func UInt64ToHex(value uint64) string

func Values

func Values[K comparable, V any](m map[K]V) []V

Types

type DelayedQueueManager

type DelayedQueueManager[T any] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewDelayedQueueManager

func NewDelayedQueueManager[T any](processor QueueProcessorFunc[T]) *DelayedQueueManager[T]

func (*DelayedQueueManager[T]) Add

func (l *DelayedQueueManager[T]) Add(t time.Time, item T)

func (*DelayedQueueManager[T]) Get

func (l *DelayedQueueManager[T]) Get(t time.Time) []T

type EpochTicker

type EpochTicker struct {
	Epoch *EpochTimingConfig

	// C is the channel on which the epoch index is sent
	C <-chan int64
	// contains filtered or unexported fields
}

func NewEpochTicker

func NewEpochTicker(epoch *EpochTimingConfig) *EpochTicker

NewEpochTicker creates a ticker that sends the epoch index on the channel C at the start of the epoch

type EpochTimingConfig

type EpochTimingConfig struct {
	Start  time.Time     // start of the epoch with index 0
	Period time.Duration // length of one epoch
}

func NewEpochConfig

func NewEpochConfig(start time.Time, duration time.Duration) *EpochTimingConfig

func (EpochTimingConfig) EndTime

func (e EpochTimingConfig) EndTime(epoch int64) time.Time

EndTime returns the end time of the epoch.

func (EpochTimingConfig) EpochIndex

func (e EpochTimingConfig) EpochIndex(t time.Time) int64

EpochIndex returns returns the consecutive index of the epoch that takes place at time t.

func (EpochTimingConfig) StartTime

func (e EpochTimingConfig) StartTime(epoch int64) time.Time

StartTime returns the start time of the epoch.

type FixedTimeProvider

type FixedTimeProvider struct {
	Time time.Time
}

func (FixedTimeProvider) Now

func (f FixedTimeProvider) Now() time.Time

type QueueProcessorFunc

type QueueProcessorFunc[T any] func([]T) error

type RealTimeProvider

type RealTimeProvider struct{}

func (RealTimeProvider) Now

func (RealTimeProvider) Now() time.Time

type RewardEpochConfig

type RewardEpochConfig struct {
	Start  int64 // index of the voting round in which the reward epoch with index 0 starts
	Period int64 // length of one reward epoch in voting rounds
}

func NewRewardEpochConfig

func NewRewardEpochConfig(start int64, period int64) *RewardEpochConfig

func (RewardEpochConfig) EndEpoch

func (e RewardEpochConfig) EndEpoch(rewardEpoch int64) int64

EndEpoch returns the index of the voting round in which the given reward epoch is expected to end.

func (RewardEpochConfig) StartEpoch

func (e RewardEpochConfig) StartEpoch(rewardEpoch int64) int64

StartEpoch returns the index of the voting round in which the given reward epoch is expected to start.

type TimeProvider

type TimeProvider interface {
	Now() time.Time
}

type Timestamp

type Timestamp struct {
	time.Time
}

func (*Timestamp) UnmarshalText

func (t *Timestamp) UnmarshalText(text []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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