common

package
v0.0.0-...-ce7d804 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: LGPL-3.0 Imports: 30 Imported by: 2

Documentation

Overview

Package common is a generated protocol buffer package.

It is generated from these files:

common/types.proto

It has these top-level messages:

KVPair
KI64Pair

nolint: gas

Index

Constants

View Source
const (
	ANSIReset      = "\x1b[0m"
	ANSIBright     = "\x1b[1m"
	ANSIDim        = "\x1b[2m"
	ANSIUnderscore = "\x1b[4m"
	ANSIBlink      = "\x1b[5m"
	ANSIReverse    = "\x1b[7m"
	ANSIHidden     = "\x1b[8m"

	ANSIFgBlack   = "\x1b[30m"
	ANSIFgRed     = "\x1b[31m"
	ANSIFgGreen   = "\x1b[32m"
	ANSIFgYellow  = "\x1b[33m"
	ANSIFgBlue    = "\x1b[34m"
	ANSIFgMagenta = "\x1b[35m"
	ANSIFgCyan    = "\x1b[36m"
	ANSIFgWhite   = "\x1b[37m"

	ANSIBgBlack   = "\x1b[40m"
	ANSIBgRed     = "\x1b[41m"
	ANSIBgGreen   = "\x1b[42m"
	ANSIBgYellow  = "\x1b[43m"
	ANSIBgBlue    = "\x1b[44m"
	ANSIBgMagenta = "\x1b[45m"
	ANSIBgCyan    = "\x1b[46m"
	ANSIBgWhite   = "\x1b[47m"
)
View Source
const (
	AddressLength = 20
)
View Source
const (
	HashLength = 32
)

Variables

View Source
var (
	Big1   = big.NewInt(1)
	Big2   = big.NewInt(2)
	Big3   = big.NewInt(3)
	Big0   = big.NewInt(0)
	Big32  = big.NewInt(32)
	Big256 = big.NewInt(256)
	Big257 = big.NewInt(257)
)

Common big integers often used

View Source
var (
	ErrAlreadyStarted = errors.New("already started")
	ErrAlreadyStopped = errors.New("already stopped")
)
View Source
var (
	EmptyAddress = Address{}
)
View Source
var (
	EmptyHash = Hash{}
)
View Source
var Fmt = func(format string, a ...interface{}) string {
	if len(a) == 0 {
		return format
	}
	return fmt.Sprintf(format, a...)
}

Like fmt.Sprintf, but skips formatting if args are empty.

Functions

func ASCIITrim

func ASCIITrim(s string) string

NOTE: Assumes that s is ASCII as per IsASCIIText(), otherwise panics.

func AbsolutePath

func AbsolutePath(datadir string, filename string) string

AbsolutePath returns datadir + filename, or filename if it is absolute.

func Black

func Black(args ...interface{}) string

func Blue

func Blue(args ...interface{}) string

func Bytes2Hex

func Bytes2Hex(d []byte) string

Bytes2Hex returns the hexadecimal encoding of d.

func Bytes2Uint

func Bytes2Uint(src []byte) (uint64, error)

Bytes2Uint returns the uint64 by the hexadecimal src.

func ColoredBytes

func ColoredBytes(data []byte, textColor, bytesColor func(...interface{}) string) string

func CopyBytes

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

CopyBytes returns an exact copy of the provided bytes.

func Cyan

func Cyan(args ...interface{}) string

func EnsureDir

func EnsureDir(dir string, mode os.FileMode) error

func Exit

func Exit(s string)

func ExpUint64

func ExpUint64(a, b uint64) uint64

func FileExists

func FileExists(filePath string) bool

func Fingerprint

func Fingerprint(slice []byte) []byte

Fingerprint returns the first 6 bytes of a byte slice. If the slice is less than 6 bytes, the fingerprint contains trailing zeroes.

func FromHex

func FromHex(s string) []byte

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

func GoPath

func GoPath() string

GoPath returns GOPATH env variable value. If it is not set, this function will try to call `go env GOPATH` subcommand.

func Green

func Green(args ...interface{}) string

func HasHexPrefix

func HasHexPrefix(str string) bool

HasHexPrefix validates str begins with '0x' or '0X'.

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 Is0xHex

func Is0xHex(s string) bool

IsHex returns true for non-empty hex-string prefixed with "0x"

func IsASCIIText

func IsASCIIText(s string) bool

Returns true if s is a non-empty printable non-tab ascii character.

func IsDirEmpty

func IsDirEmpty(name string) (bool, error)

func IsEmpty

func IsEmpty(o interface{}) bool

Returns true if it has zero length.

func IsHex

func IsHex(str string) bool

IsHex validates whether each byte is valid hexadecimal string.

func IsHexAddress

func IsHexAddress(s string) bool

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

func IsLKC

func IsLKC(addr Address) bool

IsLKC check whether a coin is LKC or other token.

func IsZeros

func IsZeros(slice []byte) bool

func Kill

func Kill() error

Kill the running process by sending itself SIGTERM.

func LeftPadBytes

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

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

func Magenta

func Magenta(args ...interface{}) string

func MaxInt

func MaxInt(a, b int) int

func MaxInt16

func MaxInt16(a, b int16) int16

func MaxInt32

func MaxInt32(a, b int32) int32

func MaxInt64

func MaxInt64(a, b int64) int64

func MaxInt8

func MaxInt8(a, b int8) int8

func MaxUint

func MaxUint(a, b uint) uint

func MaxUint16

func MaxUint16(a, b uint16) uint16

func MaxUint32

func MaxUint32(a, b uint32) uint32

func MaxUint64

func MaxUint64(a, b uint64) uint64

func MaxUint8

func MaxUint8(a, b uint8) uint8

func MinInt

func MinInt(a, b int) int

func MinInt16

func MinInt16(a, b int16) int16

func MinInt32

func MinInt32(a, b int32) int32

func MinInt64

func MinInt64(a, b int64) int64

func MinInt8

func MinInt8(a, b int8) int8

func MinUint

func MinUint(a, b uint) uint

func MinUint16

func MinUint16(a, b uint16) uint16

func MinUint32

func MinUint32(a, b uint32) uint32

func MinUint64

func MinUint64(a, b uint64) uint64

func MinUint8

func MinUint8(a, b uint8) uint8

func MustReadFile

func MustReadFile(filePath string) []byte

func MustWriteFile

func MustWriteFile(filePath string, contents []byte, mode os.FileMode)

func PanicConsensus

func PanicConsensus(v interface{})

Indicates a failure of consensus. Someone was malicious or something has gone horribly wrong. These should really boot us into an "emergency-recover" mode XXX DEPRECATED

func PanicCrisis

func PanicCrisis(v interface{})

A panic here means something has gone horribly wrong, in the form of data corruption or failure of the operating system. In a correct/healthy system, these should never fire. If they do, it's indicative of a much more serious problem. XXX DEPRECATED

func PanicQ

func PanicQ(v interface{})

For those times when we're not sure if we should panic XXX DEPRECATED

func PanicSanity

func PanicSanity(v interface{})

A panic resulting from a sanity check means there is a programmer error and some guarantee is not satisfied. XXX DEPRECATED

func PrefixEndBytes

func PrefixEndBytes(prefix []byte) []byte

PrefixEndBytes returns the end byteslice for a noninclusive range that would include all byte slices for which the input is the prefix

func Prompt

func Prompt(prompt string, defaultValue string) (string, error)

func RandBytes

func RandBytes(n int) []byte

func RandFloat32

func RandFloat32() float32

func RandFloat64

func RandFloat64() float64

func RandInt

func RandInt() int

func RandInt16

func RandInt16() int16

func RandInt31

func RandInt31() int32

func RandInt31n

func RandInt31n(n int32) int32

func RandInt32

func RandInt32() int32

func RandInt63

func RandInt63() int64

func RandInt63n

func RandInt63n(n int64) int64

func RandInt64

func RandInt64() int64

func RandIntn

func RandIntn(n int) int

func RandPerm

func RandPerm(n int) []int

func RandStr

func RandStr(length int) string

func RandTime

func RandTime() time.Time

func RandUint

func RandUint() uint

func RandUint16

func RandUint16() uint16

func RandUint32

func RandUint32() uint32

func RandUint64

func RandUint64() uint64

func ReadFile

func ReadFile(filePath string) ([]byte, error)

func Red

func Red(args ...interface{}) string

func RightPadBytes

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

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

func Seed

func Seed(seed int64)

func SplitAndTrim

func SplitAndTrim(s, sep, cutset string) []string

SplitAndTrim slices s into all subslices separated by sep and returns a slice of the string s with all leading and trailing Unicode code points contained in cutset removed. If sep is empty, SplitAndTrim splits after each UTF-8 sequence. First part is equivalent to strings.SplitN with a count of -1.

func StringInSlice

func StringInSlice(a string, list []string) bool

StringInSlice returns true if a is found the list.

func StripHex

func StripHex(s string) string

StripHex returns hex string without leading "0x"

func Tempdir

func Tempdir(prefix string) (*os.File, string)

func Tempfile

func Tempfile(prefix string) (*os.File, string)

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 TrapSignal

func TrapSignal(cb func())

TrapSignal catches the SIGTERM and executes cb function. After that it exits with code 1.

func TrimmedString

func TrimmedString(b []byte) string

func White

func White(args ...interface{}) string

func WriteFile

func WriteFile(filePath string, contents []byte, mode os.FileMode) error

func WriteFileAtomic

func WriteFileAtomic(filename string, data []byte, perm os.FileMode) error

WriteFileAtomic creates a temporary file with data and the perm given and swaps it atomically with filename if successful.

func Yellow

func Yellow(args ...interface{}) string

Types

type Address

type Address [AddressLength]byte

Address represents the 20 byte address of an Ethereum 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) MarshalJSON

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

func (Address) MarshalText

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

MarshalText returns the hex representation of a.

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.

type BaseService

type BaseService struct {
	Logger log.Logger
	// contains filtered or unexported fields
}

Classical-inheritance-style service declarations. Services can be started, then stopped, then optionally restarted.

Users can override the OnStart/OnStop methods. In the absence of errors, these methods are guaranteed to be called at most once. If OnStart returns an error, service won't be marked as started, so the user can call Start again.

A call to Reset will panic, unless OnReset is overwritten, allowing OnStart/OnStop to be called again.

The caller must ensure that Start and Stop are not called concurrently.

It is ok to call Stop without calling Start first.

Typical usage:

type FooService struct {
	BaseService
	// private fields
}

func NewFooService() *FooService {
	fs := &FooService{
		// init
	}
	fs.BaseService = *NewBaseService(log, "FooService", fs)
	return fs
}

func (fs *FooService) OnStart() error {
	fs.BaseService.OnStart() // Always call the overridden method.
	// initialize private fields
	// start subroutines, etc.
}

func (fs *FooService) OnStop() error {
	fs.BaseService.OnStop() // Always call the overridden method.
	// close/destroy private fields
	// stop subroutines, etc.
}

func NewBaseService

func NewBaseService(logger log.Logger, name string, impl Service) *BaseService

NewBaseService creates a new BaseService.

func (*BaseService) IsRunning

func (bs *BaseService) IsRunning() bool

IsRunning implements Service by returning true or false depending on the service's state.

func (*BaseService) OnReset

func (bs *BaseService) OnReset() error

OnReset implements Service by panicking.

func (*BaseService) OnStart

func (bs *BaseService) OnStart() error

OnStart implements Service by doing nothing. NOTE: Do not put anything in here, that way users don't need to call BaseService.OnStart()

func (*BaseService) OnStop

func (bs *BaseService) OnStop()

OnStop implements Service by doing nothing. NOTE: Do not put anything in here, that way users don't need to call BaseService.OnStop()

func (*BaseService) Quit

func (bs *BaseService) Quit() <-chan struct{}

Quit Implements Service by returning a quit channel.

func (*BaseService) Reset

func (bs *BaseService) Reset() error

Reset implements Service by calling OnReset callback (if defined). An error will be returned if the service is running.

func (*BaseService) SetLogger

func (bs *BaseService) SetLogger(l log.Logger)

SetLogger implements Service by setting a logger.

func (*BaseService) Start

func (bs *BaseService) Start() error

Start implements Service by calling OnStart (if defined). An error will be returned if the service is already running or stopped. Not to start the stopped service, you need to call Reset.

func (*BaseService) Stop

func (bs *BaseService) Stop() error

Stop implements Service by calling OnStop (if defined) and closing quit channel. An error will be returned if the service is already stopped.

func (*BaseService) String

func (bs *BaseService) String() string

String implements Servce by returning a string representation of the service.

func (*BaseService) Wait

func (bs *BaseService) Wait()

Wait blocks until the service is stopped.

type BitArray

type BitArray struct {
	Bits  int      `json:"bits"`  // NOTE: persisted via reflect, must be exported
	Elems []uint64 `json:"elems"` // NOTE: persisted via reflect, must be exported
	// contains filtered or unexported fields
}

func NewBitArray

func NewBitArray(bits int) *BitArray

There is no BitArray whose Size is 0. Use nil instead.

func (*BitArray) And

func (bA *BitArray) And(o *BitArray) *BitArray

Returns a BitArray of smaller bit size.

func (*BitArray) Bytes

func (bA *BitArray) Bytes() []byte

func (*BitArray) Copy

func (bA *BitArray) Copy() *BitArray

func (*BitArray) GetIndex

func (bA *BitArray) GetIndex(i int) bool

NOTE: behavior is undefined if i >= bA.Bits

func (*BitArray) IsEmpty

func (bA *BitArray) IsEmpty() bool

func (*BitArray) IsFull

func (bA *BitArray) IsFull() bool

func (*BitArray) MarshalJSON

func (bA *BitArray) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface by marshaling bit array using a custom format: a string of '-' or 'x' where 'x' denotes the 1 bit.

func (*BitArray) Not

func (bA *BitArray) Not() *BitArray

func (*BitArray) Or

func (bA *BitArray) Or(o *BitArray) *BitArray

Returns a BitArray of larger bits size.

func (*BitArray) PickRandom

func (bA *BitArray) PickRandom() (int, bool)

func (*BitArray) SetIndex

func (bA *BitArray) SetIndex(i int, v bool) bool

NOTE: behavior is undefined if i >= bA.Bits

func (*BitArray) Size

func (bA *BitArray) Size() int

func (*BitArray) String

func (bA *BitArray) String() string

String returns a string representation of BitArray: BA{<bit-string>}, where <bit-string> is a sequence of 'x' (1) and '_' (0). The <bit-string> includes spaces and newlines to help people. For a simple sequence of 'x' and '_' characters with no spaces or newlines, see the MarshalJSON() method. Example: "BA{_x_}" or "nil-BitArray" for nil.

func (*BitArray) StringIndented

func (bA *BitArray) StringIndented(indent string) string

func (*BitArray) Sub

func (bA *BitArray) Sub(o *BitArray) *BitArray

func (*BitArray) UnmarshalJSON

func (bA *BitArray) UnmarshalJSON(bz []byte) error

UnmarshalJSON implements json.Unmarshaler interface by unmarshaling a custom JSON description.

func (*BitArray) Update

func (bA *BitArray) Update(o *BitArray)

NOTE: other bitarray o is not locked when reading, so if necessary, caller must copy or lock o prior to calling Update. If bA is nil, does nothing.

type Error

type Error interface {
	Error() string
	Stacktrace() Error
	Trace(offset int, format string, args ...interface{}) Error
	Data() interface{}
}

Usage with arbitrary error data:

```go

// Error construction
type MyError struct{}
var err1 error = NewErrorWithData(MyError{}, "my message")
...
// Wrapping
var err2 error  = ErrorWrap(err1, "another message")
if (err1 != err2) { panic("should be the same")
...
// Error handling
switch err2.Data().(type){
	case MyError: ...
    default: ...
}

```

func ErrorWrap

func ErrorWrap(cause interface{}, format string, args ...interface{}) Error

func NewError

func NewError(format string, args ...interface{}) Error

New Error with formatted message. The Error's Data will be a FmtError type.

func NewErrorWithData

func NewErrorWithData(data interface{}) Error

New Error with specified data.

type FmtError

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

FmtError is the data type for NewError() (e.g. NewError().Data().(FmtError)) Theoretically it could be used to switch on the format string.

```go

// Error construction
var err1 error = NewError("invalid username %v", "BOB")
var err2 error = NewError("another kind of error")
...
// Error handling
switch err1.Data().(cmn.FmtError).Format() {
	case "invalid username %v": ...
	case "another kind of error": ...
    default: ...
}

```

func (FmtError) Error

func (fe FmtError) Error() string

func (FmtError) Format

func (fe FmtError) Format() string

func (FmtError) String

func (fe FmtError) String() string

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) Equal

func (h Hash) Equal(c Hash) bool

Equal is used to compare whether two hashes are consistent

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) MarshalJSON

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

used by amino codec marshalJSON

func (Hash) MarshalText

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

MarshalText returns the hex representation of h.

func (*Hash) SetBytes

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

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

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.

type HexBytes

type HexBytes []byte

The main purpose of HexBytes is to enable HEX-encoding for json/encoding.

func (HexBytes) Bytes

func (bz HexBytes) Bytes() []byte

Allow it to fulfill various interfaces in light-client, etc...

func (HexBytes) Format

func (bz HexBytes) Format(s fmt.State, verb rune)

func (HexBytes) Marshal

func (bz HexBytes) Marshal() ([]byte, error)

Marshal needed for protobuf compatibility

func (HexBytes) MarshalJSON

func (bz HexBytes) MarshalJSON() ([]byte, error)

This is the point of Bytes.

func (HexBytes) String

func (bz HexBytes) String() string

func (*HexBytes) Unmarshal

func (bz *HexBytes) Unmarshal(data []byte) error

Unmarshal needed for protobuf compatibility

func (*HexBytes) UnmarshalJSON

func (bz *HexBytes) UnmarshalJSON(data []byte) error

This is the point of Bytes.

type KI64Pair

type KI64Pair struct {
	Key   []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Value int64  `protobuf:"varint,2,opt,name=value" json:"value,omitempty"`
}

Define these here for compatibility but use tmlibs/common.KI64Pair.

func (*KI64Pair) Descriptor

func (*KI64Pair) Descriptor() ([]byte, []int)

func (*KI64Pair) GetKey

func (m *KI64Pair) GetKey() []byte

func (*KI64Pair) GetValue

func (m *KI64Pair) GetValue() int64

func (*KI64Pair) ProtoMessage

func (*KI64Pair) ProtoMessage()

func (*KI64Pair) Reset

func (m *KI64Pair) Reset()

func (*KI64Pair) String

func (m *KI64Pair) String() string

type KI64Pairs

type KI64Pairs []KI64Pair

func (KI64Pairs) Len

func (kvs KI64Pairs) Len() int

Sorting

func (KI64Pairs) Less

func (kvs KI64Pairs) Less(i, j int) bool

func (KI64Pairs) Sort

func (kvs KI64Pairs) Sort()

func (KI64Pairs) Swap

func (kvs KI64Pairs) Swap(i, j int)

type KVPair

type KVPair struct {
	Key   []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
}

Define these here for compatibility but use tmlibs/common.KVPair.

func (*KVPair) Descriptor

func (*KVPair) Descriptor() ([]byte, []int)

func (*KVPair) GetKey

func (m *KVPair) GetKey() []byte

func (*KVPair) GetValue

func (m *KVPair) GetValue() []byte

func (*KVPair) ProtoMessage

func (*KVPair) ProtoMessage()

func (*KVPair) Reset

func (m *KVPair) Reset()

func (*KVPair) String

func (m *KVPair) String() string

type KVPairs

type KVPairs []KVPair

func (KVPairs) Len

func (kvs KVPairs) Len() int

Sorting

func (KVPairs) Less

func (kvs KVPairs) Less(i, j int) bool

func (KVPairs) Sort

func (kvs KVPairs) Sort()

func (KVPairs) Swap

func (kvs KVPairs) Swap(i, j int)

type MixedcaseAddress

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

MixedcaseAddress retains the original string, which may or may not be correctly checksummed

func NewMixedcaseAddress

func NewMixedcaseAddress(addr Address) MixedcaseAddress

NewMixedcaseAddress constructor (mainly for testing)

func NewMixedcaseAddressFromString

func NewMixedcaseAddressFromString(hexaddr string) (*MixedcaseAddress, error)

NewMixedcaseAddressFromString is mainly meant for unit-testing

func (*MixedcaseAddress) Address

func (ma *MixedcaseAddress) Address() Address

Address returns the address

func (*MixedcaseAddress) MarshalJSON

func (ma *MixedcaseAddress) MarshalJSON() ([]byte, error)

MarshalJSON marshals the original value

func (*MixedcaseAddress) Original

func (ma *MixedcaseAddress) Original() string

Original returns the mixed-case input string

func (*MixedcaseAddress) String

func (ma *MixedcaseAddress) String() string

String implements fmt.Stringer

func (*MixedcaseAddress) UnmarshalJSON

func (ma *MixedcaseAddress) UnmarshalJSON(input []byte) error

UnmarshalJSON parses MixedcaseAddress

func (*MixedcaseAddress) ValidChecksum

func (ma *MixedcaseAddress) ValidChecksum() bool

ValidChecksum returns true if the address has valid checksum

type Rand

type Rand struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Rand is a prng, that is seeded with OS randomness. The OS randomness is obtained from crypto/rand, however none of the provided methods are suitable for cryptographic usage. They all utilize math/rand's prng internally.

All of the methods here are suitable for concurrent use. This is achieved by using a mutex lock on all of the provided methods.

func NewRand

func NewRand() *Rand

func (*Rand) Bytes

func (r *Rand) Bytes(n int) []byte

Bytes returns n random bytes generated from the internal prng.

func (*Rand) Float32

func (r *Rand) Float32() float32

func (*Rand) Float64

func (r *Rand) Float64() float64

func (*Rand) Int

func (r *Rand) Int() int

func (*Rand) Int16

func (r *Rand) Int16() int16

func (*Rand) Int31

func (r *Rand) Int31() int32

func (*Rand) Int31n

func (r *Rand) Int31n(n int32) int32

func (*Rand) Int32

func (r *Rand) Int32() int32

func (*Rand) Int63

func (r *Rand) Int63() int64

func (*Rand) Int63n

func (r *Rand) Int63n(n int64) int64

func (*Rand) Int64

func (r *Rand) Int64() int64

func (*Rand) Intn

func (r *Rand) Intn(n int) int

Intn returns, as an int, a uniform pseudo-random number in the range [0, n). It panics if n <= 0.

func (*Rand) Perm

func (r *Rand) Perm(n int) []int

Perm returns a pseudo-random permutation of n integers in [0, n).

func (*Rand) Seed

func (r *Rand) Seed(seed int64)

func (*Rand) Str

func (r *Rand) Str(length int) string

Str constructs a random alphanumeric string of given length.

func (*Rand) Time

func (r *Rand) Time() time.Time

func (*Rand) Uint

func (r *Rand) Uint() uint

func (*Rand) Uint16

func (r *Rand) Uint16() uint16

func (*Rand) Uint32

func (r *Rand) Uint32() uint32

func (*Rand) Uint64

func (r *Rand) Uint64() uint64

type Service

type Service interface {
	// Start the service.
	// If it's already started or stopped, will return an error.
	// If OnStart() returns an error, it's returned by Start()
	Start() error
	OnStart() error

	// Stop the service.
	// If it's already stopped, will return an error.
	// OnStop must never error.
	Stop() error
	OnStop()

	// Reset the service.
	// Panics by default - must be overwritten to enable reset.
	Reset() error
	OnReset() error

	// Return true if the service is running
	IsRunning() bool

	// Quit returns a channel, which is closed once service is stopped.
	Quit() <-chan struct{}

	// String representation of the service
	String() string

	// SetLogger sets a logger.
	SetLogger(log.Logger)
}

Service defines a service that can be started, stopped, and reset.

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 UnprefixedAddress

type UnprefixedAddress Address

UnprefixedAddress allows marshaling an Address without 0x prefix.

func (UnprefixedAddress) MarshalText

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

MarshalText encodes the address as hex.

func (*UnprefixedAddress) UnmarshalText

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

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

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 bitutil implements fast bitwise operations.
Package bitutil implements fast bitwise operations.
Package hexutil implements hex encoding with 0x prefix.
Package hexutil implements hex encoding with 0x prefix.
Package math provides integer math utilities.
Package math provides integer math utilities.

Jump to

Keyboard shortcuts

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