common

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2019 License: LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HashLength is the length of a hash in DEXON.
	HashLength = 32
)

Variables

This section is empty.

Functions

func CopyBytes

func CopyBytes(src []byte) (dst []byte)

CopyBytes copies byte slice.

func GenerateRandomBytes

func GenerateRandomBytes() []byte

GenerateRandomBytes generates bytes randomly.

Types

type ByTime

type ByTime []time.Time

ByTime implements sort.Interface for time.Time.

func (ByTime) Len

func (t ByTime) Len() int

func (ByTime) Less

func (t ByTime) Less(i, j int) bool

func (ByTime) Swap

func (t ByTime) Swap(i, j int)

type CustomLogger

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

CustomLogger logs everything.

func NewCustomLogger

func NewCustomLogger(logger *log.Logger) *CustomLogger

NewCustomLogger creates a new custom logger.

func (*CustomLogger) Debug

func (logger *CustomLogger) Debug(msg string, ctx ...interface{})

Debug implements Logger interface.

func (*CustomLogger) Error

func (logger *CustomLogger) Error(msg string, ctx ...interface{})

Error implements Logger interface.

func (*CustomLogger) Info

func (logger *CustomLogger) Info(msg string, ctx ...interface{})

Info implements Logger interface.

func (*CustomLogger) Trace

func (logger *CustomLogger) Trace(msg string, ctx ...interface{})

Trace implements Logger interface.

func (*CustomLogger) Warn

func (logger *CustomLogger) Warn(msg string, ctx ...interface{})

Warn implements Logger interface.

type Event

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

Event implements the Observer pattern.

func NewEvent

func NewEvent() *Event

NewEvent creates a new event instance.

func (*Event) NotifyHeight

func (e *Event) NotifyHeight(h uint64)

NotifyHeight and trigger function callback.

func (*Event) RegisterHeight

func (e *Event) RegisterHeight(h uint64, fn heightEventFn)

RegisterHeight to get notified on a specific height.

func (*Event) Reset

func (e *Event) Reset()

Reset clears all pending event

type Hash

type Hash [HashLength]byte

Hash is the basic hash type in DEXON.

func NewRandomHash

func NewRandomHash() Hash

NewRandomHash returns a random Hash-like value.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes return the hash as slice of bytes.

func (Hash) Equal

func (h Hash) Equal(hp Hash) bool

Equal compares if two hashes are the same.

func (Hash) Less

func (h Hash) Less(hp Hash) bool

Less compares if current hash is lesser.

func (Hash) MarshalText

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

MarshalText implements the encoding.TextMarhsaler interface.

func (Hash) String

func (h Hash) String() string

func (*Hash) UnmarshalText

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

UnmarshalText implements the encoding.TextUnmarshaler interface.

type Hashes

type Hashes []Hash

Hashes is for sorting hashes.

func (Hashes) Len

func (hs Hashes) Len() int

func (Hashes) Less

func (hs Hashes) Less(i, j int) bool

func (Hashes) Swap

func (hs Hashes) Swap(i, j int)

type Logger

type Logger interface {
	// Info logs info level logs.
	Trace(msg string, ctx ...interface{})
	Debug(msg string, ctx ...interface{})
	Info(msg string, ctx ...interface{})
	Warn(msg string, ctx ...interface{})
	Error(msg string, ctx ...interface{})
}

Logger define the way to receive logs from Consensus instance. NOTE: parameter in 'ctx' should be paired as key-value mapping. For example,

to log an error with message:
    logger.Error("some message", "error", err)
which is similar to loggers with context:
    logger.Error("some message", map[string]interface{}{
       "error": err,
    })

type NullLogger

type NullLogger struct{}

NullLogger logs nothing.

func (*NullLogger) Debug

func (logger *NullLogger) Debug(msg string, ctx ...interface{})

Debug implements Logger interface.

func (*NullLogger) Error

func (logger *NullLogger) Error(msg string, ctx ...interface{})

Error implements Logger interface.

func (*NullLogger) Info

func (logger *NullLogger) Info(msg string, ctx ...interface{})

Info implements Logger interface.

func (*NullLogger) Trace

func (logger *NullLogger) Trace(msg string, ctx ...interface{})

Trace implements Logger interface.

func (*NullLogger) Warn

func (logger *NullLogger) Warn(msg string, ctx ...interface{})

Warn implements Logger interface.

type SimpleLogger

type SimpleLogger struct{}

SimpleLogger logs everything.

func (*SimpleLogger) Debug

func (logger *SimpleLogger) Debug(msg string, ctx ...interface{})

Debug implements Logger interface.

func (*SimpleLogger) Error

func (logger *SimpleLogger) Error(msg string, ctx ...interface{})

Error implements Logger interface.

func (*SimpleLogger) Info

func (logger *SimpleLogger) Info(msg string, ctx ...interface{})

Info implements Logger interface.

func (*SimpleLogger) Trace

func (logger *SimpleLogger) Trace(msg string, ctx ...interface{})

Trace implements Logger interface.

func (*SimpleLogger) Warn

func (logger *SimpleLogger) Warn(msg string, ctx ...interface{})

Warn implements Logger interface.

type SortedHashes

type SortedHashes Hashes

SortedHashes is a slice of hashes sorted in ascending order.

func NewSortedHashes

func NewSortedHashes(hs Hashes) SortedHashes

NewSortedHashes converts a slice of hashes to a sorted one. It's a firewall to prevent us from assigning unsorted hashes to a variable declared as SortedHashes directly.

Jump to

Keyboard shortcuts

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