utils

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 DeleteValue

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

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

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 GetInt64

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

GetInt64 will retrieve an int64 value in the database

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 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 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 []byte, value []byte) error

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

func SortKVs

func SortKVs(keys [][]byte, 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 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