common

package
v0.0.0-...-3356115 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package common contains various helper functions.

Index

Constants

View Source
const (
	// AddressLength is the expected length of the address
	AddressLength = 20
)
View Source
const (
	// HashLength is the expected length of the hash
	HashLength = sha256.Size
)

Variables

This section is empty.

Functions

func Bytes2Hex

func Bytes2Hex(d []byte) string

Bytes2Hex returns the hexadecimal encoding of d.

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

CopyBytes returns an exact copy of the provided bytes.

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func Hash64

func Hash64(data []byte) uint64

Hash64 TODO

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func Hex2BytesFixed

func Hex2BytesFixed(str string, flen int) []byte

Hex2BytesFixed returns bytes of a specified fixed length flen.

func Is

func Is(err error, t StoreErrType) bool

Is checks if store error type

func IsHexAddress

func IsHexAddress(s string) bool

IsHexAddress verifies whether a string can represent a valid hex-encoded Ethereum address or not.

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

LeftPadBytes zero-pads slice to the left up to length l.

func NewTestLogger

func NewTestLogger(t testing.TB) *logrus.Logger

NewTestLogger constructor

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

RightPadBytes zero-pads slice to the right up to length l.

func ToHex deprecated

func ToHex(b []byte) string

ToHex returns the hex representation of b, prefixed with '0x'. For empty slices, the return value is "0x0".

Deprecated: use hexutil.Encode instead.

func ToHexArray

func ToHexArray(b [][]byte) []string

ToHexArray creates a array of hex-string based on []byte

Types

type Address

type Address [AddressLength]byte

Address represents the address of an PoS account.

func BigToAddress

func BigToAddress(b *big.Int) Address

BigToAddress returns Address with byte values of b. If b is larger than len(h), b will be cropped from the left.

func BytesToAddress

func BytesToAddress(b []byte) Address

BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped from the left.

func HexToAddress

func HexToAddress(s string) Address

HexToAddress returns Address with byte values of s. If s is larger than len(h), s will be cropped from the left.

func (Address) Big

func (a Address) Big() *big.Int

Big converts an address to a big integer.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes gets the string representation of the underlying address.

func (Address) Format

func (a Address) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Address) Hash

func (a Address) Hash() Hash

Hash converts an address to a hash by left-padding it with zeros.

func (Address) Hex

func (a Address) Hex() string

Hex returns an EIP55-compliant hex string representation of the address.

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

MarshalText returns the hex representation of a.

func (*Address) Scan

func (a *Address) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte)

SetBytes sets the address to the value of b. If b is larger than len(a) it will panic.

func (Address) String

func (a Address) String() string

String implements fmt.Stringer.

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Address) Value

func (a Address) Value() (driver.Value, error)

Value implements valuer for database/sql.

type Hash

type Hash [HashLength]byte

Hash represents the 32 byte Keccak256 hash of arbitrary data.

func BigToHash

func BigToHash(b *big.Int) Hash

BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func HexToHash

func HexToHash(s string) Hash

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func (Hash) Big

func (h Hash) Big() *big.Int

Big converts a hash to a big integer.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash) Format

func (h Hash) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Hash) Generate

func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements testing/quick.Generator.

func (Hash) Hex

func (h Hash) Hex() string

Hex converts a hash to a hex string.

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (*Hash) Scan

func (h *Hash) Scan(src interface{}) error

Scan implements Scanner for database/sql.

func (*Hash) SetBytes

func (h *Hash) SetBytes(raw []byte)

SetBytes sets the hash to the value of b.

func (Hash) String

func (h Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash) TerminalString

func (h Hash) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

func (Hash) Value

func (h Hash) Value() (driver.Value, error)

Value implements valuer for database/sql.

type Int64Slice

type Int64Slice []int64

Int64Slice allows sorting of 64-bit integer slices, like PendingRoundReceived

func (Int64Slice) Len

func (a Int64Slice) Len() int

func (Int64Slice) Less

func (a Int64Slice) Less(i, j int) bool

func (Int64Slice) Swap

func (a Int64Slice) Swap(i, j int)

type RollingIndex

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

RollingIndex struct

func NewRollingIndex

func NewRollingIndex(name string, size int) *RollingIndex

NewRollingIndex constructor

func (*RollingIndex) Get

func (r *RollingIndex) Get(skipIndex int64) ([]interface{}, error)

Get with skipIndex option

func (*RollingIndex) GetItem

func (r *RollingIndex) GetItem(index int64) (interface{}, error)

GetItem get item for a given index

func (*RollingIndex) GetLastWindow

func (r *RollingIndex) GetLastWindow() (lastWindow []interface{}, lastIndex int64)

GetLastWindow getter

func (*RollingIndex) Set

func (r *RollingIndex) Set(item interface{}, index int64) error

Set item for given index

type RollingIndexMap

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

RollingIndexMap struct

func NewRollingIndexMap

func NewRollingIndexMap(name string, size int, keys []uint64) *RollingIndexMap

NewRollingIndexMap constructor

func (*RollingIndexMap) AddKey

func (rim *RollingIndexMap) AddKey(key uint64) error

AddKey adds a key to map if it doesn't already exist, returns an error if it already exists

func (*RollingIndexMap) Get

func (rim *RollingIndexMap) Get(key uint64, skipIndex int64) ([]interface{}, error)

Get return key items with index > skip

func (*RollingIndexMap) GetItem

func (rim *RollingIndexMap) GetItem(key uint64, index int64) (interface{}, error)

GetItem returns the item in rolling index for given key

func (*RollingIndexMap) GetLast

func (rim *RollingIndexMap) GetLast(key uint64) (interface{}, error)

GetLast get last item for given key

func (*RollingIndexMap) Import

func (rim *RollingIndexMap) Import(other *RollingIndexMap)

Import from another index

func (*RollingIndexMap) Known

func (rim *RollingIndexMap) Known() map[uint64]int64

Known returns [key] => lastKnownIndex

func (*RollingIndexMap) Reset

func (rim *RollingIndexMap) Reset() error

Reset resets the map

func (*RollingIndexMap) Set

func (rim *RollingIndexMap) Set(key uint64, item interface{}, index int64) error

Set sets a given key for the index

type StorageSize

type StorageSize float64

StorageSize is a wrapper around a float value that supports user friendly formatting.

func (StorageSize) String

func (s StorageSize) String() string

String implements the stringer interface.

func (StorageSize) TerminalString

func (s StorageSize) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

type StoreErr

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

StoreErr storage error

func NewStoreErr

func NewStoreErr(dataType string, errType StoreErrType, key string) StoreErr

NewStoreErr constructor

func (StoreErr) Error

func (e StoreErr) Error() string

type StoreErrType

type StoreErrType uint32

StoreErrType store error type

const (
	// KeyNotFound PEM key not found
	KeyNotFound StoreErrType = iota
	// TooLate TODO
	TooLate
	// PassedIndex passed the index lookup
	PassedIndex
	// SkippedIndex skipped the index lookup
	SkippedIndex
	// NoRoot no root to load
	NoRoot
	// UnknownParticipant signed participant is not known
	UnknownParticipant
	// Empty TODO
	Empty
	// KeyAlreadyExists key already exists in the store
	KeyAlreadyExists
)

type UnprefixedHash

type UnprefixedHash Hash

UnprefixedHash allows marshaling a Hash without 0x prefix.

func (UnprefixedHash) MarshalText

func (h UnprefixedHash) MarshalText() ([]byte, error)

MarshalText encodes the hash as hex.

func (*UnprefixedHash) UnmarshalText

func (h *UnprefixedHash) UnmarshalText(input []byte) error

UnmarshalText decodes the hash from hex. The 0x prefix is optional.

Directories

Path Synopsis
Package hexutil implements hex encoding with 0x prefix.
Package hexutil implements hex encoding with 0x prefix.

Jump to

Keyboard shortcuts

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