common

package
v0.0.7-alphanet Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: GPL-3.0 Imports: 17 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ChainLogger      = log15.New("module", "chain")
	ConsensusLogger  = log15.New("module", "consensus")
	NodeLogger       = log15.New("module", "node")
	P2PLogger        = log15.New("module", "p2p")
	PillarLogger     = log15.New("module", "pillar")
	ProtocolLogger   = log15.New("module", "handler")
	FetcherLogger    = ProtocolLogger.New("submodule", "fetcher")
	DownloaderLogger = ProtocolLogger.New("submodule", "downloader")
	RPCLogger        = log15.New("module", "rpc")
	VerifierLogger   = log15.New("module", "verifier")
	ZenonLogger      = log15.New("module", "zenon")
	VmLogger         = log15.New("module", "vm")
	SupervisorLogger = log15.New("module", "supervisor")
	EmbeddedLogger   = log15.New("module", "embedded")
	WalletLogger     = log15.New("module", "wallet")
)
View Source
var (
	Big0      = big.NewInt(0)
	Big1      = big.NewInt(1)
	Big2      = big.NewInt(2)
	Big32     = big.NewInt(32)
	Big64     = big.NewInt(64)
	Big100    = big.NewInt(100)
	Big255    = big.NewInt(255)
	Big256    = big.NewInt(256)
	BigP255   = new(big.Int).Exp(Big2, Big255, nil)
	BigP255m1 = new(big.Int).Sub(BigP255, big.NewInt(1))
	BigP256   = new(big.Int).Exp(Big2, Big256, nil)
	BigP256m1 = new(big.Int).Sub(BigP256, big.NewInt(1))
)

Functions

func BigIntToBytes

func BigIntToBytes(int *big.Int) []byte

func BytesToBigInt

func BytesToBigInt(bytes []byte) *big.Int

func BytesToUint64

func BytesToUint64(bytes []byte) uint64

func DealWithErr

func DealWithErr(v interface{})

DealWithErr panics if err is not nil.

func Expect

func Expect(t T, current, expected interface{})

func ExpectAmount

func ExpectAmount(t T, current, expected *big.Int)

func ExpectBytes

func ExpectBytes(t T, current []byte, expected string)

func ExpectError

func ExpectError(t T, current error, expected error)

func ExpectJson

func ExpectJson(t T, current interface{}, expected string)

func ExpectString

func ExpectString(t T, current, expected string)

func ExpectTrue

func ExpectTrue(t T, value bool)

func ExpectUint64

func ExpectUint64(t T, current, expected uint64)

func FailIfErr

func FailIfErr(t T, err error)

func GetStack

func GetStack() string

func HideHashes

func HideHashes(a string) string

func InitLogging

func InitLogging(dataPath, logLevelStr string)

func IsHex

func IsHex(str string) bool

IsHex validates whether each byte is valid hexadecimal string.

func IsHexCharacter

func IsHexCharacter(c byte) bool

IsHexCharacter returns bool of c being a valid hexadecimal.

func JoinBytes

func JoinBytes(data ...[]byte) []byte

func MaxInt64

func MaxInt64(x, y int64) int64

func MinInt64

func MinInt64(x, y int64) int64

func RecoverStack

func RecoverStack()

func StringToBigInt

func StringToBigInt(str string) *big.Int

StringToBigInt The default value is 0 when it cannot parse or the string is ""

func Uint32ToBytes

func Uint32ToBytes(x uint32) []byte

func Uint64ToBytes

func Uint64ToBytes(height uint64) []byte

Types

type ClockType

type ClockType interface {
	Now() time.Time
}
var (
	Clock ClockType
)

type ErrorWCode

type ErrorWCode interface {
	server.Error
	//AddSubErr(err error) ErrorWCode
	AddDetail(detail string) ErrorWCode
}

func NewErrorWCode

func NewErrorWCode(code int, errStr string) ErrorWCode

type Expecter

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

func Json

func Json(j interface{}, inheritedError error) *Expecter

func LateCaller

func LateCaller(f func() (string, error)) *Expecter

func SaveLogs

func SaveLogs(log log15.Logger) *Expecter

func String

func String(received string) *Expecter

func (*Expecter) Equals

func (exp *Expecter) Equals(t T, expected string)

func (*Expecter) Error

func (exp *Expecter) Error(t T, err error)

func (*Expecter) HideHashes

func (exp *Expecter) HideHashes() *Expecter

func (*Expecter) SubJson

func (exp *Expecter) SubJson(subJson interface{}) *Expecter

type LogSaver

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

func (LogSaver) Format

func (f LogSaver) Format(r *log15.Record) []byte

type Logger

type Logger interface {
	log15.Logger
}

type T

type T interface {
	Fatalf(format string, args ...interface{})
	TempDir() string
}

type Task

type Task interface {
	Wait()
	Finished() chan struct{}
	ForceStop()
}

func NewTask

func NewTask(action func(TaskResolver)) Task

type TaskResolver

type TaskResolver interface {
	ShouldStop() bool
}

type Ticker

type Ticker interface {
	// ToTime returns [startTime, endTime) for tick
	ToTime(tick uint64) (time.Time, time.Time)
	ToTick(t time.Time) uint64
	TickMultiplier(bigger Ticker) (uint64, error)
}

Ticker converts time units into ticks. End time of a thick is exclusive.

func NewTicker

func NewTicker(startTime time.Time, interval time.Duration) Ticker

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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