common

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package common contains various helper functions.

Index

Constants

View Source
const (
	HashLength = 32
	// The first two bytes are used to identify the type of the address, and 0x0001 is the normal address.
	AddressLength = 22
	NonceLength   = 32
	DiffLength    = 4
)
View Source
const (
	AddressTypeNormal      = 0x0000
	AddressTypeCross       = 0x0001
	AddressTypeStake       = 0x0002
	AddressTypeCancel      = 0x0003
	AddressTypeUnStake     = 0x0004
	AddressTypeEvidence    = 0x0005
	AddressTypeERC20       = 0x0010
	AddressTypeEarlyReward = 0x0011
)

address type

View Source
const (
	AddressStake   = "0x00020000000000000000000000000000000000000000"
	AddressCancel  = "0x00030000000000000000000000000000000000000000"
	AddressUnStake = "0x00040000000000000000000000000000000000000000"
)

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

Functions

func AbsolutePath

func AbsolutePath(Datadir string, filename string) string

func Bytes2Hex

func Bytes2Hex(d []byte) string

func CopyBytes

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

Copy bytes

Returns an exact copy of the provided bytes

func FileExist

func FileExist(filePath string) bool

func FromHex

func FromHex(s string) []byte

func Hex2Bytes

func Hex2Bytes(str string) []byte

func Hex2BytesFixed

func Hex2BytesFixed(str string, flen int) []byte

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 MakeName

func MakeName(name, version string) string

MakeName creates a node name that follows the ethereum convention for such names. It adds the operation system name and Go runtime version the name.

func RightPadBytes

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

func ToHex

func ToHex(b []byte) string

Types

type Address

type Address [AddressLength]byte

Dipperin Address

func BigToAddress

func BigToAddress(b *big.Int) Address

func BytesToAddress

func BytesToAddress(b []byte) (result Address)

func HexToAddress

func HexToAddress(s string) Address

func StringToAddress

func StringToAddress(s string) Address

func (Address) Big

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

func (Address) Bytes

func (addr Address) Bytes() []byte

func (*Address) Clear

func (addr *Address) Clear()

func (Address) GetAddressType

func (addr Address) GetAddressType() TxType

GetAddressType get the type of address based on the first two digits of the address

func (Address) GetAddressTypeStr

func (addr Address) GetAddressTypeStr() string

GetAddressTypeStr get a text description of the address type

func (Address) Hash

func (addr Address) Hash() Hash

func (Address) Hex

func (addr Address) Hex() string

func (Address) InSlice

func (addr Address) InSlice(addresses []Address) bool

func (Address) IsEmpty

func (addr Address) IsEmpty() bool

func (Address) IsEqual

func (addr Address) IsEqual(oaddr Address) bool

func (Address) IsEqualWithoutType

func (addr Address) IsEqualWithoutType(oaddr Address) bool

func (Address) MarshalJSON

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

func (*Address) SetBytes

func (addr *Address) SetBytes(b []byte)

Sets the address to the value of b. If b is larger than len(a) it will panic

func (Address) Str

func (addr Address) Str() string

Get the string representation of the underlying address

func (Address) String

func (addr Address) String() string

func (*Address) UnmarshalJSON

func (addr *Address) UnmarshalJSON(input []byte) error

type BlockNonce

type BlockNonce [NonceLength]byte

Dipperin Block Nonce

func BlockNonceFromHex

func BlockNonceFromHex(hexStr string) (result BlockNonce)

func BlockNonceFromInt

func BlockNonceFromInt(i uint32) (result BlockNonce)

func EncodeNonce

func EncodeNonce(i uint64) BlockNonce

EncodeNonce converts the given integer to a block nonce.

func (BlockNonce) Hex

func (bn BlockNonce) Hex() string

calculate hex

func (BlockNonce) IsEqual

func (bn BlockNonce) IsEqual(obn BlockNonce) bool

Compare block nonce

func (BlockNonce) MarshalJSON

func (bn BlockNonce) MarshalJSON() ([]byte, error)

func (*BlockNonce) UnmarshalJSON

func (bn *BlockNonce) UnmarshalJSON(input []byte) error

type Difficulty

type Difficulty [DiffLength]byte

Dipperin BlockHeader Difficulty

func BigToDiff

func BigToDiff(b *big.Int) Difficulty

func BytesToDiff

func BytesToDiff(b []byte) (result Difficulty)

func HexToDiff

func HexToDiff(s string) Difficulty

func StringToDiff

func StringToDiff(s string) Difficulty

func (Difficulty) Big

func (d Difficulty) Big() *big.Int

func (Difficulty) Bytes

func (d Difficulty) Bytes() []byte

func (Difficulty) DiffToTarget

func (d Difficulty) DiffToTarget() (target Hash)

func (Difficulty) Equal

func (d Difficulty) Equal(d2 Difficulty) bool

func (Difficulty) Hex

func (d Difficulty) Hex() string

func (Difficulty) HexWithout0x

func (d Difficulty) HexWithout0x() string

func (Difficulty) MarshalJSON

func (d Difficulty) MarshalJSON() ([]byte, error)

func (*Difficulty) SetBytes

func (d *Difficulty) SetBytes(b []byte)

func (Difficulty) Str

func (d Difficulty) Str() string

func (*Difficulty) UnmarshalJSON

func (d *Difficulty) UnmarshalJSON(input []byte) error

type Hash

type Hash [HashLength]byte

Dipperin hash

func BigToHash

func BigToHash(b *big.Int) Hash

func BytesToHash

func BytesToHash(b []byte) (result Hash)

func CopyHash

func CopyHash(h *Hash) *Hash

Returns an exact copy of the provided bytes

func HexToHash

func HexToHash(s string) Hash

func RlpHashKeccak256

func RlpHashKeccak256(v interface{}) (h Hash)

do rlp hash on an object

func StringToHash

func StringToHash(s string) Hash

func (Hash) Big

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

func (Hash) Bytes

func (h Hash) Bytes() []byte

func (*Hash) Clear

func (h *Hash) Clear()

func (Hash) Cmp

func (h Hash) Cmp(oh Hash) (res int)

compare hash h with hash oh, if h bigger than oh return 1, if h equal to oh return 0,if h smaller than oh return -1

func (Hash) Hex

func (h Hash) Hex() string

func (Hash) HexWithout0x

func (h Hash) HexWithout0x() string

func (Hash) IsEmpty

func (h Hash) IsEmpty() bool

func (Hash) IsEqual

func (h Hash) IsEqual(oh Hash) bool

func (Hash) MarshalJSON

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

func (*Hash) SetBytes

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

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

func (Hash) Str

func (h Hash) Str() string

func (Hash) String

func (h Hash) String() string

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(input []byte) error

func (Hash) ValidHashForDifficulty

func (h Hash) ValidHashForDifficulty(difficulty Difficulty) bool

ValidHashForDifficulty check is it a hash that meets the corresponding difficulty?

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.

func (PrettyDuration) String

func (d PrettyDuration) String() string

String implements the Stringer interface, allowing pretty printing of duration values rounded to three decimals.

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 TxType

type TxType int

func (TxType) String

func (txType TxType) String() string

type UnprefixedAddress

type UnprefixedAddress Address

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.
Package mclock is a wrapper for a monotonic clock source
Package mclock is a wrapper for a monotonic clock source

Jump to

Keyboard shortcuts

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