Documentation
¶
Overview ¶
Package common contains various helper functions.
Index ¶
- Constants
- Variables
- func Bytes2Hex(d []byte) string
- func CopyBytes(b []byte) (copiedBytes []byte)
- func FromECDSAPub(pub *ecdsa.PublicKey) []byte
- func FromHex(s string) []byte
- func Hash64(data []byte) uint64
- func Hex2Bytes(str string) []byte
- func Hex2BytesFixed(str string, flen int) []byte
- func Is(err error, t StoreErrType) bool
- func LeftPadBytes(slice []byte, l int) []byte
- func NewTestLogger(t testing.TB) *logrus.Logger
- func RightPadBytes(slice []byte, l int) []byte
- func ToECDSAPub(pub []byte) *ecdsa.PublicKey
- func ToHex(b []byte) stringdeprecated
- func ToHexArray(b [][]byte) []string
- type Address
- type Hash
- func (h Hash) Big() *big.Int
- func (h Hash) Bytes() []byte
- func (h Hash) Format(s fmt.State, c rune)
- func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value
- func (h Hash) Hex() string
- func (h Hash) MarshalText() ([]byte, error)
- func (h *Hash) Scan(src interface{}) error
- func (h *Hash) SetBytes(raw []byte)
- func (h Hash) ShortString() string
- func (h Hash) String() string
- func (h Hash) TerminalString() string
- func (h *Hash) UnmarshalJSON(input []byte) error
- func (h *Hash) UnmarshalText(input []byte) error
- func (h Hash) Value() (driver.Value, error)
- type Int64Slice
- type PrivateKey
- type PublicKey
- type RollingIndex
- type RollingIndexMap
- func (rim *RollingIndexMap) AddKey(key uint64) error
- func (rim *RollingIndexMap) Get(key uint64, skipIndex int64) ([]interface{}, error)
- func (rim *RollingIndexMap) GetItem(key uint64, index int64) (interface{}, error)
- func (rim *RollingIndexMap) GetLast(key uint64) (interface{}, error)
- func (rim *RollingIndexMap) Import(other *RollingIndexMap)
- func (rim *RollingIndexMap) Known() map[uint64]int64
- func (rim *RollingIndexMap) Reset() error
- func (rim *RollingIndexMap) Set(key uint64, item interface{}, index int64) error
- type StorageSize
- type StoreErr
- type StoreErrType
Constants ¶
const ( // HashLength is the expected length of the hash HashLength = sha256.Size )
Variables ¶
var ( // NodeNameDict is an optional dictionary to make node address human readable in log. NodeNameDict = make(map[Address]string) )
Functions ¶
func FromECDSAPub ¶
FromECDSAPub create bytes from ECDSA public key. NOTE: deprecated
func FromHex ¶
FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".
func Hex2BytesFixed ¶
Hex2BytesFixed returns bytes of a specified fixed length flen.
func LeftPadBytes ¶
LeftPadBytes zero-pads slice to the left up to length l.
func RightPadBytes ¶
RightPadBytes zero-pads slice to the right up to length l.
func ToECDSAPub ¶
ToECDSAPub convert to ECDSA public key from bytes. NOTE: deprecated
func ToHexArray ¶
ToHexArray creates a array of hex-string based on []byte
Types ¶
type Address ¶
type Address Hash
Address is a unique identifier of Node. It is a hash of node's PubKey.
func BytesToAddress ¶
BytesToAddress sets b to address. If b is larger than len(h), b will be cropped from the left.
func FakeAddress ¶
func FakeAddress() Address
FakeAddress generates random fake address for testing purpose.
type Hash ¶
type Hash [HashLength]byte
Hash represents the 32 byte Keccak256 hash of arbitrary data.
func BigToHash ¶
BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.
func BytesToHash ¶
BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.
func HexToHash ¶
HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.
func (Hash) Format ¶
Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.
func (Hash) MarshalText ¶
MarshalText returns the hex representation of h.
func (Hash) ShortString ¶
ShortString returns short string representation.
func (Hash) String ¶
String implements the stringer interface and is used also by the logger when doing full logging into a file.
func (Hash) TerminalString ¶
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
func (*Hash) UnmarshalJSON ¶
UnmarshalJSON parses a hash in hex syntax.
func (*Hash) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
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 PrivateKey ¶
type PrivateKey ecdsa.PrivateKey
PrivateKey is a private key wrapper.
func (*PrivateKey) Public ¶
func (key *PrivateKey) Public() *PublicKey
Public returns public part of key.
type PublicKey ¶
PublicKey is a public key wrapper.
func Base64ToPubkey ¶
Base64ToPubkey decodes public key from base64.
func BytesToPubkey ¶
BytesToPubkey decodes public key from bytes.
func StringToPubkey ¶
StringToPubkey decode public key from base64 to common.PublicKey NOTE: deprecated
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
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
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 )