lib

package
v0.0.0-...-2515fb6 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const CharNewLine = '\n'

Variables

View Source
var (
	ErrInvalidAddress = errors.New("invalid address")
)
View Source
var (
	ErrInvalidHashLen = errors.New("invalid hash length")
)
View Source
var (
	ErrInvalidHexString = fmt.Errorf("invalid hex string")
)
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 BytesToString

func BytesToString(b []byte) string

func CastErrorData

func CastErrorData(errData []byte, abis []*abi.ABI) (abi.Error, interface{}, bool)

CastErrorData casts the error data to the appropriate error type

func CopySlice

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

func CopyURL

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

func DecryptBytes

func DecryptBytes(bytes, privateKey []byte) ([]byte, error)

func DecryptString

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

func EncodeAbiParameters

func EncodeAbiParameters(abiParams []AbiParameter, params []interface{}) ([]byte, error)

func EncryptString

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

func Exp10

func Exp10(exp int) *big.Int

func ExtractGETHErrorData

func ExtractGETHErrorData(err error) ([]byte, bool)

ExtractGETHErrorData extracts the error data from an unexproted geth 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 HexToHash

func HexToHash(s string) (common.Hash, error)

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 MustPubKeyStringFromPrivate

func MustPubKeyStringFromPrivate(privateKey string) string

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 PrivKeyBytesToAddr

func PrivKeyBytesToAddr(privateKey []byte) (common.Address, error)

func PrivKeyStringToAddr

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

func PrivKeyToAddr

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

func PubKeyStringFromPrivate

func PubKeyStringFromPrivate(privateKey string) (string, error)

func ReadJSONFile

func ReadJSONFile(filePath string) (string, error)

func RelativeError

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

RelativeError returns relative error between two values

func RemoveHexPrefix

func RemoveHexPrefix(s string) string

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 Short

func Short(s Hexable) string

Short returns a short representation of a Hexable in "0x123..567" format

func SignEthMessage

func SignEthMessage(msg []byte, privateKeyHex string) ([]byte, error)

func SignEthMessageV2

func SignEthMessageV2(msg []byte, privateKeyBytes []byte) ([]byte, error)

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 TryConvertGethError

func TryConvertGethError(err error) error

TryConvertGethError attempts to convert geth error to an EVMError, otherwise just returns original error

func VerifySignature

func VerifySignature(params []byte, signature []byte, publicKeyBytes []byte) bool

https://goethereumbook.org/signature-verify/

func VerifySignatureAddr

func VerifySignatureAddr(params []byte, signature []byte, addr common.Address) bool

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 AbiParameter

type AbiParameter struct {
	Type string
}

type Address

type Address struct {
	common.Address
}

func MustStringToAddress

func MustStringToAddress(s string) Address

func StringToAddress

func StringToAddress(s string) (Address, error)

func (*Address) UnmarshalParam

func (a *Address) UnmarshalParam(param string) error

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 BigInt

type BigInt struct {
	big.Int
}

func (BigInt) MarshalJSON

func (b BigInt) MarshalJSON() ([]byte, error)

func (*BigInt) UnmarshalJSON

func (b *BigInt) UnmarshalJSON(data []byte) error

Enables the use of big.Int as a JSON field

func (*BigInt) Unpack

func (b *BigInt) Unpack() *big.Int

type Bool

type Bool struct {
	Bool *bool
}

func (*Bool) String

func (b *Bool) String() string

func (*Bool) UnmarshalText

func (b *Bool) UnmarshalText(data []byte) error

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 EVMError

type EVMError struct {
	Abi   abi.Error
	Cause error
	Args  interface{}
}

func ConvertGethError

func ConvertGethError(gethErr error, contractMeta []Meta) (*EVMError, bool)

ConvertGethError converts a geth error to an EVMError with exposed error signature and arguments

func (EVMError) As

func (e EVMError) As(target interface{}) bool

Implement As() method to check if EVMError can be converted to another type.

func (EVMError) Error

func (e EVMError) Error() string

type Hash

type Hash struct {
	common.Hash
}

func GetRandomHash

func GetRandomHash() (Hash, error)

func MustStringToHash

func MustStringToHash(s string) Hash

func StringToHash

func StringToHash(s string) (Hash, error)

func (*Hash) UnmarshalParam

func (h *Hash) UnmarshalParam(param string) error

type HexString

type HexString []byte

Arbitrary length hex string represented internally as a byte slice

func MustStringToHexString

func MustStringToHexString(s string) HexString

func PubKeyFromPrivate

func PubKeyFromPrivate(privateKey HexString) (HexString, error)

func StringToHexString

func StringToHexString(s string) (HexString, error)

func (HexString) Hex

func (b HexString) Hex() string

func (HexString) MarshalJSON

func (b HexString) MarshalJSON() ([]byte, error)

func (HexString) String

func (b HexString) String() string

func (*HexString) UnmarshalJSON

func (b *HexString) UnmarshalJSON(data []byte) error

func (*HexString) UnmarshalText

func (b *HexString) UnmarshalText(data []byte) error

type Hexable

type Hexable interface {
	Hex() string
}

type ILogger

type ILogger interface {
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	DPanic(args ...interface{}) // Development panic - panics only in development mode
	Panic(args ...interface{})
	Fatal(args ...interface{})

	Debugf(template string, args ...interface{})
	Infof(template string, args ...interface{})
	Warnf(template string, args ...interface{})
	Errorf(template string, args ...interface{})
	DPanicf(template string, args ...interface{})
	Panicf(template string, args ...interface{})
	Fatalf(template string, args ...interface{})

	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	DPanicw(msg string, keysAndValues ...interface{})
	Panicw(msg string, keysAndValues ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})

	Log(lvl zapcore.Level, msg string, fields ...zapcore.Field)

	Sync() error
	Close() error
	Named(name string) ILogger
	With(args ...interface{}) ILogger
}

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) ILogger

func (*Logger) With

func (l *Logger) With(args ...interface{}) 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) 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{}) ILogger

type Meta

type Meta interface {
	GetAbi() (*abi.ABI, error)
}

type Number

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

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