common

package
v0.0.0-...-7207b0b Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2018 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//HashLength length of hash string
	HashLength = 32
	//AddressLength length of account address
	AddressLength = 20
)

Variables

View Source
var (
	//ErrEmptyString string is empty
	ErrEmptyString = &decError{"empty hex string"}
	//ErrSyntax string format is not hex
	ErrSyntax = &decError{"invalid hex string"}
	//ErrMissingPrefix string for hex without 0x prefix
	ErrMissingPrefix = &decError{"hex string without 0x prefix"}
	//ErrOddLength string length is odd not even
	ErrOddLength = &decError{"hex string of odd length"}
	//ErrEmptyNumber string only contains 0x prefix
	ErrEmptyNumber = &decError{"hex string \"0x\""}
	//ErrLeadingZero hex number with zero beginning
	ErrLeadingZero = &decError{"hex number with leading zero digits"}
	//ErrUint64Range hex number is larger than 64 bit len
	ErrUint64Range = &decError{"hex number > 64 bits"}
	//ErrUintRange hex number is larger than uint len
	ErrUintRange = &decError{fmt.Sprintf("hex number > %d bits", uintBits)}
	//ErrBig256Range hex number is larger than 256 bit len
	ErrBig256Range = &decError{"hex number > 256 bits"}
)
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(0xff)
	Big257 = big.NewInt(257)
)

Common big integers often used

Functions

func CopyBytes

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

CopyBytes returns a duplication of self byte array Input - copiedBytes: pointer to destination Output - copiedBytes: copy byte array to destination

func Decode

func Decode(input string) ([]byte, error)

Decode decodes a hex string with 0x prefix.

func EmptyHash

func EmptyHash(h Hash) bool

func Encode

func Encode(b []byte) string

Encode encodes b as a hex string with 0x prefix.

func EncodeBig

func EncodeBig(bigint *big.Int) string

EncodeBig encodes bigint as a hex string with 0x prefix. The sign of the integer is ignored.

func FileExist

func FileExist(filePath string) bool

func FromHex

func FromHex(s string) []byte

FromHex converts a hex string with 0x prefix to byte array

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes converts a hex string to byte array

func IsHexAddress

func IsHexAddress(s string) bool

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

func LeftPadBytes

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

func LoadJSON

func LoadJSON(file string, val interface{}) error

LoadJSON reads the given file and unmarshals its content.

func MustDecode

func MustDecode(input string) []byte

MustDecode decodes a hex string with 0x prefix. It panics for invalid input.

func Report

func Report(extra ...interface{})

Report gives off a warning requesting the user to submit an issue to the github tracker.

func RightPadBytes

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

func UnmarshalFixedText

func UnmarshalFixedText(typname string, input, out []byte) error

UnmarshalFixedText decodes the input as a string with 0x prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalText method for fixed-size types.

Types

type AbsTime

type AbsTime time.Duration // absolute monotonic time

func Now

func Now() AbsTime

type Address

type Address [AddressLength]byte

Address represents the 20 byte address

func BigToAddress

func BigToAddress(b *big.Int) Address

func BytesToAddress

func BytesToAddress(b []byte) Address

BytesToAddress set the address to the value to b

func HexToAddress

func HexToAddress(s string) Address

HexToAddress set the address to the value of s

func (Address) Big

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

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes convert address to byte slice

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) 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) 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 the stringer interface and is used also by the logger.

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 BlockNonce

type BlockNonce [8]byte

A BlockNonce is a 64-bit hash which proves (combined with the mix-hash) that a sufficient amount of computation has been carried out on a block.

func EncodeNonce

func EncodeNonce(i uint64) BlockNonce

EncodeNonce converts the given integer to a block nonce.

type Bytes

type Bytes []byte

Bytes marshals/unmarshals as a JSON string with 0x prefix. The empty slice marshals as "0x".

func (Bytes) MarshalText

func (b Bytes) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (*Bytes) UnmarshalJSON

func (b *Bytes) UnmarshalJSON(input []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*Bytes) UnmarshalText

func (b *Bytes) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Hash

type Hash [HashLength]byte

Hash represents the 32 byte Keccak256 hash of arbitrary data.

func BigToHash

func BigToHash(b *big.Int) Hash

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash set the hash to the value of b

func HexToHash

func HexToHash(s string) Hash

HexToHash set the hash to the value of s

func (Hash) Big

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

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes convert hash to byte slice

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

func (h Hash) Hex() string

Hex convert hash to hex string

func (Hash) MarshalText

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

MarshalText returns the hex representation of h.

func (*Hash) Set

func (h *Hash) Set(other Hash)

Sets h to other

func (*Hash) SetBytes

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

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

func (*Hash) SetString

func (h *Hash) SetString(s string)

Set string `s` to h. If s is larger than len(h) s will be cropped (from left) to fit.

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 PrettyDuration

type PrettyDuration time.Duration

PrettyDuration is a pretty printed version of a time.Duration value that cuts the unnecessary precision off from the formatted textual representation.

type StorageSize

type StorageSize float64

func (StorageSize) Int64

func (self StorageSize) Int64() int64

func (StorageSize) String

func (self StorageSize) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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