utils

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PublicKey  = "PUBLIC KEY"
	PrivateKey = "PRIVATE KEY"
)

Constants that are common across packages.

View Source
const ErrEventNotFound = errors.Error("event not found")

ErrEventNotFound when event is not found and need to retry

Variables

This section is empty.

Functions

func AddressTo32Bytes

func AddressTo32Bytes(address common.Address) [32]byte

AddressTo32Bytes converts an address to 32 a byte array The length of an address is 20 bytes. First 12 bytes are filled with zeros.

func Byte32ToSlice

func Byte32ToSlice(in [32]byte) []byte

Byte32ToSlice converts a [32]bytes to an unbounded byte array

func ByteArrayTo32BytesLeftPadded

func ByteArrayTo32BytesLeftPadded(in []byte) ([32]byte, error)

ByteArrayTo32BytesLeftPadded converts an address to 32 a byte array The length of the input has to be less or equals to 32

func ByteFixedToBigInt

func ByteFixedToBigInt(bytes []byte, size int) *big.Int

ByteFixedToBigInt convert arbitrary length byte arrays to big.Int

func ByteSliceToBigInt

func ByteSliceToBigInt(slice []byte) *big.Int

ByteSliceToBigInt convert bute slices to big.Int (bigendian)

func Check32BytesFilled

func Check32BytesFilled(b []byte) bool

Check32BytesFilled ensures byte slice is of length 32 and don't contain all 0x0 bytes.

func CheckMultiple32BytesFilled

func CheckMultiple32BytesFilled(b []byte, bs ...[]byte) bool

CheckMultiple32BytesFilled takes multiple []byte slices and ensures they are all of length 32 and don't contain all 0x0 bytes.

func ContainsBigIntInSlice

func ContainsBigIntInSlice(value *big.Int, list []*big.Int) bool

ContainsBigIntInSlice checks if value is present in list.

func ContainsString

func ContainsString(slice []string, str string) bool

ContainsString returns true if the slice contains str.

func ConvertByte32ToInt

func ConvertByte32ToInt(nb [32]byte) int

ConvertByte32ToInt converts a fixed length byte array into int with BigEndian order

func ConvertIntToByte32

func ConvertIntToByte32(n int) ([32]byte, error)

ConvertIntToByte32 converts an integer into a fixed length byte array with BigEndian order

func ConvertProofForEthereum

func ConvertProofForEthereum(sortedHashes [][]byte) ([][32]byte, error)

ConvertProofForEthereum converts a proof to 32 byte format needed by ethereum

func FromTimestamp

func FromTimestamp(t *timestamp.Timestamp) (time.Time, error)

FromTimestamp converts a timestamp protobuf to time

func GetCentLogFormat

func GetCentLogFormat() string

GetCentLogFormat returns the specific log format

func GetFreeAddrPort

func GetFreeAddrPort() (string, int, error)

GetFreeAddrPort returns a loopback address and port that can be listened from. Note: port is included in the address.

func InRange added in v1.0.0

func InRange(i, min, max int) bool

InRange returns a boolean if the given number is in between a specified range.

func IsEmptyAddress

func IsEmptyAddress(addr common.Address) bool

IsEmptyAddress checks if the addr is empty.

func IsEmptyByte32

func IsEmptyByte32(source [32]byte) bool

IsEmptyByte32 checks if the source is empty.

func IsEmptyByteSlice

func IsEmptyByteSlice(s []byte) bool

IsEmptyByteSlice checks if the provided slice is empty returns true if: s == nil every element is == 0

func IsSameByteSlice

func IsSameByteSlice(a []byte, b []byte) bool

IsSameByteSlice checks if a and b contains same bytes.

func IsStringEmpty

func IsStringEmpty(msg string) bool

IsStringEmpty returns true if the string is empty

func IsStringOfLength

func IsStringOfLength(msg string, n int) bool

IsStringOfLength returns true if length of the string == n

func IsValidByteSliceForLength

func IsValidByteSliceForLength(slice []byte, length int) bool

IsValidByteSliceForLength checks if the len(slice) == length.

func LookForEvent

func LookForEvent(iter EventIterator) (err error)

LookForEvent checks if the iterator is ready with the Event if no event is found, returns ErrEventNotFound returns iter.Error when iterator errored out

func MustSliceToByte32 added in v1.0.0

func MustSliceToByte32(in []byte) [32]byte

MustSliceToByte32 converts the bytes to byte 32 panics if the input length is > 32 bytes.

func RandomBigInt added in v1.0.0

func RandomBigInt(max string) (*big.Int, error)

RandomBigInt returns a random big int that's less than the provided max.

func RandomByte32

func RandomByte32() (out [32]byte)

RandomByte32 returns a randomly filled byte array with length of 32

func RandomSlice

func RandomSlice(size int) (out []byte)

RandomSlice returns a randomly filled byte array with length of given size

func ReadKeyFromPemFile

func ReadKeyFromPemFile(fileName, keyPurpose string) (key []byte, err error)

ReadKeyFromPemFile reads the pem file and returns the key with matching key purpose

func SendPOSTRequest

func SendPOSTRequest(url string, contentType string, payload []byte) (statusCode int, err error)

SendPOSTRequest sends post with data to given URL.

func SimulateJSONDecodeForGocelery

func SimulateJSONDecodeForGocelery(kwargs map[string]interface{}) (map[string]interface{}, error)

SimulateJSONDecodeForGocelery encodes and decodes the kwargs.

func SliceOfByteSlicesToHexStringSlice

func SliceOfByteSlicesToHexStringSlice(byteSlices [][]byte) []string

SliceOfByteSlicesToHexStringSlice converts the given slice of byte slices to a hex encoded string array with 0x prefix

func SliceToByte32

func SliceToByte32(in []byte) (out [32]byte, err error)

SliceToByte32 converts a 32 byte slice to an array. Will throw error if the slice is too long

func ToTimestamp

func ToTimestamp(time time.Time) (*timestamp.Timestamp, error)

ToTimestamp converts time.Time to timestamp.TimeStamp.

func WriteKeyToPemFile

func WriteKeyToPemFile(fileName string, keyPurpose string, key []byte) (err error)

WriteKeyToPemFile writes encode of key and purpose to the file

Types

type EventIterator

type EventIterator interface {
	Next() bool
	Error() error
	Close() error
}

EventIterator contains functions that make events listening more easier

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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