lib

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const CharNewLine = '\n'

Variables

View Source
var (
	ErrInvalidPrivateKey = fmt.Errorf("invalid private key")
)

Functions

func Abs

func Abs[T Number](a T) T

func AddrShort

func AddrShort(addr string) string

AddrShort returns a short representation of an address in "0x123..567" format

func AlmostEqual

func AlmostEqual[T Number](a, b T, tolerance float64) bool

func CopySlice

func CopySlice[T any](s []T) []T

func CopyURL

func CopyURL(u *url.URL) *url.URL

func DecryptString

func DecryptString(str string, privateKey string) (string, error)

func EncryptString

func EncryptString(str string, publicKeyHex string) (string, error)

func Filter

func Filter[T any](arr []T, f func(T) bool) (ret []T)

func FilterValue

func FilterValue[T comparable](arr []T, val T) (ret []T)

func GetRandomAddr

func GetRandomAddr() common.Address

func JoinUsername

func JoinUsername(accountName, userName string) string

func Merge

func Merge[T any](cs ...<-chan T) <-chan T

func MustPrivKeyStringToAddr

func MustPrivKeyStringToAddr(privateKey string) common.Address

func MustPrivKeyToAddr

func MustPrivKeyToAddr(privateKey *ecdsa.PrivateKey) common.Address

func MustUnmarshallString

func MustUnmarshallString(value json.RawMessage) string

func NewRat

func NewRat(numerator, denominator *big.Int) *big.Rat

NewRat returns a new Rat set to the quotient big.Int numerator/denominator

func NormalizeJson

func NormalizeJson(msg []byte) ([]byte, error)

NormalizeJson returns normalized json message, without spaces and newlines

func ParsePort

func ParsePort(addr string) (port string)

func PrKeyToCompressedPubKey

func PrKeyToCompressedPubKey(prkey *ecdsa.PrivateKey) (yParity bool, x common.Hash, err error)

PrKeyToCompressedPubKey converts a private key to a compressed public key (yParity, x) for use with validator registry

func PrivKeyStringToAddr

func PrivKeyStringToAddr(privateKey string) (common.Address, error)

func PrivKeyToAddr

func PrivKeyToAddr(privateKey *ecdsa.PrivateKey) (common.Address, error)

func RelativeError

func RelativeError[T Number](target, actual T) float64

RelativeError returns relative error between two values

func SanitizeFilename

func SanitizeFilename(fileName string) string

SanitizeFileName modifies filename to be safe to use as cross-platform file name

func SetUserName

func SetUserName(u *url.URL, userName string)

func SetWorkerName

func SetWorkerName(u *url.URL, workerName string)

func SplitUsername

func SplitUsername(username string) (accountName string, workerName string, ok bool)

func StrShort

func StrShort(str string) string

StrShort returns a short version of the string in a format "aaaaa..aa"

func StrShortConf

func StrShortConf(str string, prefix, suffix int) string

StrShortConf returns a short version of the string in a format "{prefix chars}..{suffix chars}"

func TCPPipe

func TCPPipe() (clientConn net.Conn, serverConn net.Conn, err error)

func WrapError

func WrapError(parent error, child error) error

WrapError allows to use reuse predefined error objects and add dynamic data allowing to create error chains

Example:
var ErrEnvParse = errors.New("cannot parse env variable")
var err = fmt.Errorf("IS_BUYER should be boolean")
wrappedErr := WrapError(ErrEnvParse, err)

errors.Is(wrappedErr, ErrEnvParse) 	// true
errors.Unwrap(wrappedErr).Is(err) 	// true
wrappedErr.Error()	// "cannot parse env variable: IS_BUYER should be boolean"

Types

type AtomicValue

type AtomicValue[T any] struct {
	// contains filtered or unexported fields
}

func NewAtomicValue

func NewAtomicValue[T any](v T) *AtomicValue[T]

func (*AtomicValue[T]) CompareAndSwap

func (a *AtomicValue[T]) CompareAndSwap(old, new T) bool

func (*AtomicValue[T]) Load

func (a *AtomicValue[T]) Load() T

func (*AtomicValue[T]) Store

func (a *AtomicValue[T]) Store(v T)

func (*AtomicValue[T]) Swap

func (a *AtomicValue[T]) Swap(v T) T

type BoundStackMap

type BoundStackMap[T any] struct {
	// contains filtered or unexported fields
}

func NewBoundStackMap

func NewBoundStackMap[T any](size int) *BoundStackMap[T]

NewBoundStackMap creates a new map with the limited capacity, where new records overwrite the oldest ones. The map is thread-safe

func (*BoundStackMap[T]) At

func (bs *BoundStackMap[T]) At(index int) (T, bool)

func (*BoundStackMap[T]) Capacity

func (bs *BoundStackMap[T]) Capacity() int

func (*BoundStackMap[T]) Clear

func (bs *BoundStackMap[T]) Clear()

func (*BoundStackMap[T]) Count

func (bs *BoundStackMap[T]) Count() int

func (*BoundStackMap[T]) Filter

func (bs *BoundStackMap[T]) Filter(f func(key string, value T) bool)

func (*BoundStackMap[T]) Get

func (bs *BoundStackMap[T]) Get(key string) (T, bool)

func (*BoundStackMap[T]) Push

func (bs *BoundStackMap[T]) Push(key string, item T)

func (*BoundStackMap[T]) Range

func (bs *BoundStackMap[T]) Range(f func(key string, value T) bool)

func (*BoundStackMap[T]) String

func (bs *BoundStackMap[T]) String() string

type ChanRecvStop

type ChanRecvStop[T any] struct {
	DataCh chan T
	StopCh chan struct{}
}

func NewChanRecvStop

func NewChanRecvStop[T any]() *ChanRecvStop[T]

NewChanRecvStop creates a new ChanRecvStop, an abstraction over a channel that supports multiple writers and a single reader. The writes can be stopped and/or unblocked by calling the Stop method from a reader

func (*ChanRecvStop[T]) Receive

func (c *ChanRecvStop[T]) Receive() <-chan T

func (*ChanRecvStop[T]) Send

func (c *ChanRecvStop[T]) Send(data T)

func (*ChanRecvStop[T]) Stop

func (c *ChanRecvStop[T]) Stop()

type Collection

type Collection[T IModel] struct {
	// contains filtered or unexported fields
}

func NewCollection

func NewCollection[T IModel]() *Collection[T]

func (*Collection[T]) Delete

func (p *Collection[T]) Delete(ID string)

func (*Collection[T]) Len

func (p *Collection[T]) Len() int

Len returns the number of items in the collection. It is O(n)

func (*Collection[T]) Load

func (p *Collection[T]) Load(ID string) (item T, ok bool)

func (*Collection[T]) LoadOrStore

func (p *Collection[T]) LoadOrStore(item T) (actual T, loaded bool)

func (*Collection[T]) Range

func (p *Collection[T]) Range(f func(item T) bool)

func (*Collection[T]) Store

func (p *Collection[T]) Store(item T)

type IModel

type IModel interface {
	ID() string
}

type Logger

type Logger struct {
	*zap.SugaredLogger
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(level string, color, isProd bool, isJSON bool, filepath string) (*Logger, error)

func NewLoggerMemory

func NewLoggerMemory(level string, color, isProd bool, isJSON bool, filepath string, wr io.Writer) (*Logger, error)

func NewTestLogger

func NewTestLogger() *Logger

NewTestLogger logs only to stdout

func (*Logger) Close

func (l *Logger) Close() error

func (*Logger) Log

func (l *Logger) Log(lvl zapcore.Level, msg string, fields ...zapcore.Field)

func (*Logger) Named

func (l *Logger) Named(name string) interfaces.ILogger

func (*Logger) With

func (l *Logger) With(args ...interface{}) interfaces.ILogger

type LoggerMock

type LoggerMock struct{}

func (*LoggerMock) Close

func (l *LoggerMock) Close() error

func (*LoggerMock) DPanic

func (l *LoggerMock) DPanic(args ...interface{})

func (*LoggerMock) DPanicf

func (l *LoggerMock) DPanicf(template string, args ...interface{})

func (*LoggerMock) DPanicw

func (l *LoggerMock) DPanicw(template string, args ...interface{})

func (*LoggerMock) Debug

func (l *LoggerMock) Debug(args ...interface{})

func (*LoggerMock) Debugf

func (l *LoggerMock) Debugf(template string, args ...interface{})

func (*LoggerMock) Debugw

func (l *LoggerMock) Debugw(template string, args ...interface{})

func (*LoggerMock) Error

func (l *LoggerMock) Error(args ...interface{})

func (*LoggerMock) Errorf

func (l *LoggerMock) Errorf(template string, args ...interface{})

func (*LoggerMock) Errorw

func (l *LoggerMock) Errorw(template string, args ...interface{})

func (*LoggerMock) Fatal

func (l *LoggerMock) Fatal(args ...interface{})

func (*LoggerMock) Fatalf

func (l *LoggerMock) Fatalf(template string, args ...interface{})

func (*LoggerMock) Fatalw

func (l *LoggerMock) Fatalw(template string, args ...interface{})

func (*LoggerMock) Info

func (l *LoggerMock) Info(args ...interface{})

func (*LoggerMock) Infof

func (l *LoggerMock) Infof(template string, args ...interface{})

func (*LoggerMock) Infow

func (l *LoggerMock) Infow(template string, args ...interface{})

func (*LoggerMock) Log

func (l *LoggerMock) Log(lvl zapcore.Level, msg string, fields ...zapcore.Field)

func (*LoggerMock) Named

func (l *LoggerMock) Named(n string) i.ILogger

func (*LoggerMock) Panic

func (l *LoggerMock) Panic(args ...interface{})

func (*LoggerMock) Panicf

func (l *LoggerMock) Panicf(template string, args ...interface{})

func (*LoggerMock) Panicw

func (l *LoggerMock) Panicw(template string, args ...interface{})

func (*LoggerMock) Sync

func (l *LoggerMock) Sync() error

func (*LoggerMock) Warn

func (l *LoggerMock) Warn(args ...interface{})

func (*LoggerMock) Warnf

func (l *LoggerMock) Warnf(template string, args ...interface{})

func (*LoggerMock) Warnw

func (l *LoggerMock) Warnw(template string, args ...interface{})

func (*LoggerMock) With

func (l *LoggerMock) With(args ...interface{}) i.ILogger

type Mutex

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

Mutex is a non blocking mutex

func NewMutex

func NewMutex() Mutex

func (*Mutex) Lock

func (m *Mutex) Lock()

func (*Mutex) LockCtx

func (m *Mutex) LockCtx(ctx context.Context) error

func (*Mutex) LockTimeout

func (m *Mutex) LockTimeout(d time.Duration) error

func (*Mutex) Unlock

func (m *Mutex) Unlock()

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

type PubKey

type PubKey struct {
	X       common.Hash
	YParity bool
}

func (*PubKey) Compressed

func (p *PubKey) Compressed() []byte

func (*PubKey) String

func (p *PubKey) String() string

type Runnable

type Runnable interface {
	Run(ctx context.Context) error
}

type Set

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

func NewSet

func NewSet() Set

func NewSetFromSlice

func NewSetFromSlice(slice []string) Set

func (Set) Add

func (s Set) Add(value ...string)

func (Set) Clear

func (s Set) Clear()

func (Set) Contains

func (s Set) Contains(value string) bool

func (Set) Len

func (s Set) Len() int

func (Set) Remove

func (s Set) Remove(value string) bool

func (Set) ToSlice

func (s Set) ToSlice() []string

type Stack

type Stack[T any] []T

func NewStack

func NewStack[T any]() *Stack[T]

func (*Stack[T]) Clear

func (s *Stack[T]) Clear()

func (*Stack[T]) Copy

func (s *Stack[T]) Copy() *Stack[T]

func (*Stack[T]) IsEmpty

func (s *Stack[T]) IsEmpty() bool

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() (T, bool)

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (T, bool)

func (*Stack[T]) Push

func (s *Stack[T]) Push(str T)

func (*Stack[T]) Range

func (s *Stack[T]) Range(f func(T) bool)

func (*Stack[T]) Remove

func (s *Stack[T]) Remove(f func(T) bool)

func (*Stack[T]) Size

func (s *Stack[T]) Size() int

type Subscription

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

func NewSubscription

func NewSubscription(producer func(quit <-chan struct{}) error, ch chan interface{}) *Subscription

func (*Subscription) Ch

func (s *Subscription) Ch() chan interface{}

func (*Subscription) Err

func (s *Subscription) Err() <-chan error

func (*Subscription) Events

func (s *Subscription) Events() <-chan interface{}

func (*Subscription) Unsubscribe

func (s *Subscription) Unsubscribe()

type Task

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

Task is a wrapper around a function that can be started and stopped

func NewTask

func NewTask(runnable Runnable) *Task

NewTask creates a new task from Runnable that runs in a separate goroutine that can be started and stopped

func NewTaskFunc

func NewTaskFunc(f func(ctx context.Context) error) *Task

NewTaskFunc creates a new task from a function that runs in a separate goroutine that can be started and stopped

func (*Task) Done

func (s *Task) Done() <-chan struct{}

Done returns a channel that's closed when task exited or cancelled from outside using context When Stop called done is not closed

func (*Task) Err

func (s *Task) Err() error

Err returns error that caused routine to exit

func (*Task) Start

func (s *Task) Start(ctx context.Context)

func (*Task) Stop

func (s *Task) Stop() <-chan struct{}

Jump to

Keyboard shortcuts

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