utils

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDevelopmentVersion  = errors.New("not tagged build, running in developer mode")
	ErrUnexpectedTagFormat = errors.New("unexpected version format. expected vX.Y.Z[-optional]")
)

Functions

func AmILeading

func AmILeading(client layer1.Client, ctx context.Context, logger *logrus.Entry, start int, randHash []byte, numOfValidators, validatorIndex, desperationFactor, desperationDelay int) (bool, error)

AmILeading checks if the current node is a leader for an action.

func CloneBigInt

func CloneBigInt(original *big.Int) *big.Int

CloneBigInt makes a deep copy of a big.Int.

func CloneBigInt2

func CloneBigInt2(original [2]*big.Int) [2]*big.Int

CloneBigInt2 makes a deep copy of an array [2] of big.Int's.

func CloneBigInt4

func CloneBigInt4(original [4]*big.Int) [4]*big.Int

CloneBigInt4 makes a deep copy of a array [4] of big.Int's.

func CloneBigIntSlice

func CloneBigIntSlice(original []*big.Int) []*big.Int

CloneBigIntSlice makes a deep copy of a slice of big.Int's.

func CloneSliceBigInt2

func CloneSliceBigInt2(original [][2]*big.Int) [][2]*big.Int

CloneSliceBigInt2 makes a deep copy of a slice of array [2] of big.Int's.

func CompareCanonicalVersion added in v0.0.5

func CompareCanonicalVersion(newVersion bindings.CanonicalVersion) (bool, bool, bool, bindings.CanonicalVersion, error)

func CopySlice

func CopySlice(v []byte) []byte

CopySlice returns a copy of a passed byte slice.

func DebugTrace

func DebugTrace(logger *logrus.Logger, err error, s ...string)

DebugTrace allows a traceback to be generated that includes a file name, a line number, the error message, and an optional string. Calling this function using a logger that is set to anthything other than trace or debug level is a no-op. This filtering helps to minimize overhead during normal use but still allows error tracebacks to be created easily. The returned file and line number will point to where this function was called. Although more than one string may be passed, only the first string will be displayed. The varadic property was only used to shorten calling syntax.

func DecodeHexString

func DecodeHexString(h string) ([]byte, error)

func DeleteValue

func DeleteValue(txn *badger.Txn, key []byte) error

DeleteValue removes the value for key in the database that is safe for use.

func EncodeHexString

func EncodeHexString(h []byte) string

func Epoch

func Epoch(height uint32) uint32

Epoch returns the epoch for the corresponding height.

func ForceSliceToLength

func ForceSliceToLength(inSlice []byte, length int) []byte

ForceSliceToLength will return a byte slice of size length. It will left pad a byte slice to the specified number of zeros if the slice is not long enough. If the slice is too long, it will return the right-most bytes of the slice.

func GetBlocksSinceDesperation added in v0.0.7

func GetBlocksSinceDesperation(currentHeight, start, desperationDelay int) int

GetBlocksSinceDesperation calculation

func GetInt64

func GetInt64(txn *badger.Txn, key []byte) (int64, error)

GetInt64 will retrieve an int64 value in the database.

func GetLocalVersion added in v0.0.5

func GetLocalVersion() (bindings.CanonicalVersion, error)

func GetObjSize

func GetObjSize(obj encoding.BinaryMarshaler) (int, error)

GetObjSize returns the size of a marshalled capnproto object.

func GetValue

func GetValue(txn *badger.Txn, key []byte) ([]byte, error)

GetValue returns a value from the database that is safe for use.

func HandleBadgerErrors added in v0.0.2

func HandleBadgerErrors(err error) error

HandleBadgerErrors handles the badger errors. This function will suppress the errors that we expect to happens and are not harmful to the system.

func LeaderElection added in v0.0.2

func LeaderElection(numValidators, myIdx, blocksSinceDesperation, desperationFactor int, seedHash []byte, logger *logrus.Entry) bool

LeaderElection runs the leader election algorithm to check if an index is a leader or not.

func MarshalInt64

func MarshalInt64(v int64) []byte

MarshalInt64 will marshal an int64 object.

func MarshalUint16

func MarshalUint16(v uint16) []byte

MarshalUint16 will marshal an uint16 object.

func MarshalUint32

func MarshalUint32(v uint32) []byte

MarshalUint32 will marshal an uint32 object.

func MarshalUint64

func MarshalUint64(v uint64) []byte

MarshalUint64 will marshal a uint64 object.

func Max

func Max(a, b uint64) uint64

Computes and returns the max between two uint64.

func Min

func Min(a, b uint64) uint64

Computes and returns the min between two uint64.

func OpenBadger

func OpenBadger(closeChan <-chan struct{}, directoryName string, inMemory bool) (*badger.DB, error)

OpenBadger opens a badgerdb database and closes the db when closeChan returns a struct{}{}.

func RandomBytes

func RandomBytes(num int) ([]byte, error)

RandomBytes will return a byte slice of num random bytes using crypto rand.

func SetInt64

func SetInt64(txn *badger.Txn, key []byte, v int64) error

SetInt64 will set an int64 value in the database.

func SetValue

func SetValue(txn *badger.Txn, key, value []byte) error

SetValue sets the value for key in the database that is safe for use.

func SortKVs

func SortKVs(keys, values [][]byte) ([][]byte, [][]byte, error)

SortKVs allows a pair of slices, one containing keys and one containing values to be sorted by treating each key as a big.Int and preserving the relationship between keys and values during the sort. SortKVs is a copy before sort algorithm. The original slices will remain unsorted.

func StringToBytes32

func StringToBytes32(str string) (b [32]byte)

StringToBytes32 is useful for convert a Go string into a bytes32 useful calling Solidity.

func UnmarshalInt64

func UnmarshalInt64(v []byte) (int64, error)

UnmarshalInt64 will unmarshal an int64 object.

func UnmarshalUint16

func UnmarshalUint16(v []byte) (uint16, error)

UnmarshalUint16 will unmarshal an uint16 object.

func UnmarshalUint32

func UnmarshalUint32(v []byte) (uint32, error)

UnmarshalUint32 will unmarshal an uint32 object.

func UnmarshalUint64

func UnmarshalUint64(v []byte) (uint64, error)

UnmarshalUint64 will unmarshal a uint64 object.

func ValidateHash

func ValidateHash(hsh []byte) error

ValidateHash checks whether or not hsh has the correct length.

Types

This section is empty.

Jump to

Keyboard shortcuts

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