Documentation ¶
Overview ¶
Package common contains various helper functions.
Index ¶
- Constants
- Variables
- func AbsolutePath(Datadir string, filename string) string
- func Bytes2Hex(d []byte) string
- func CopyBytes(b []byte) (copiedBytes []byte)
- func FileExist(filePath string) bool
- func FromHex(s string) []byte
- func Hex2Bytes(str string) []byte
- func Hex2BytesFixed(str string, flen int) []byte
- func LeftPadBytes(slice []byte, l int) []byte
- func LoadJSON(file string, val interface{}) error
- func MakeName(name, version string) string
- func RightPadBytes(slice []byte, l int) []byte
- func ToHex(b []byte) string
- type Address
- func (addr Address) Big() *big.Int
- func (addr Address) Bytes() []byte
- func (addr *Address) Clear()
- func (addr Address) GetAddressType() TxType
- func (addr Address) GetAddressTypeStr() string
- func (addr Address) Hash() Hash
- func (addr Address) Hex() string
- func (addr Address) InSlice(addresses []Address) bool
- func (addr Address) IsEmpty() bool
- func (addr Address) IsEqual(oaddr Address) bool
- func (addr Address) IsEqualWithoutType(oaddr Address) bool
- func (addr Address) MarshalJSON() ([]byte, error)
- func (addr *Address) SetBytes(b []byte)
- func (addr Address) Str() string
- func (addr Address) String() string
- func (addr *Address) UnmarshalJSON(input []byte) error
- type BlockNonce
- type Difficulty
- func (d Difficulty) Big() *big.Int
- func (d Difficulty) Bytes() []byte
- func (d Difficulty) DiffToTarget() (target Hash)
- func (d Difficulty) Equal(d2 Difficulty) bool
- func (d Difficulty) Hex() string
- func (d Difficulty) HexWithout0x() string
- func (d Difficulty) MarshalJSON() ([]byte, error)
- func (d *Difficulty) SetBytes(b []byte)
- func (d Difficulty) Str() string
- func (d *Difficulty) UnmarshalJSON(input []byte) error
- type Hash
- func (h Hash) Big() *big.Int
- func (h Hash) Bytes() []byte
- func (h *Hash) Clear()
- func (h Hash) Cmp(oh Hash) (res int)
- func (h Hash) Hex() string
- func (h Hash) HexWithout0x() string
- func (h Hash) IsEmpty() bool
- func (h Hash) IsEqual(oh Hash) bool
- func (h Hash) MarshalJSON() ([]byte, error)
- func (h *Hash) SetBytes(b []byte)
- func (h Hash) Str() string
- func (h Hash) String() string
- func (h *Hash) UnmarshalJSON(input []byte) error
- func (h Hash) ValidHashForDifficulty(difficulty Difficulty) bool
- type PrettyDuration
- type StorageSize
- type TxType
- type UnprefixedAddress
Constants ¶
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 )
const ( AddressTypeNormal = 0x0000 AddressTypeCross = 0x0001 AddressTypeStake = 0x0002 AddressTypeCancel = 0x0003 AddressTypeUnStake = 0x0004 AddressTypeEvidence = 0x0005 AddressTypeERC20 = 0x0010 AddressTypeEarlyReward = 0x0011 )
address type
const ( AddressStake = "0x00020000000000000000000000000000000000000000" AddressCancel = "0x00030000000000000000000000000000000000000000" AddressUnStake = "0x00040000000000000000000000000000000000000000" )
Variables ¶
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 Hex2BytesFixed ¶
func LeftPadBytes ¶
func MakeName ¶
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 ¶
Types ¶
type Address ¶
type Address [AddressLength]byte
Dipperin Address
func BigToAddress ¶
func BytesToAddress ¶
func HexToAddress ¶
func StringToAddress ¶
func (Address) GetAddressType ¶
GetAddressType get the type of address based on the first two digits of the address
func (Address) GetAddressTypeStr ¶
GetAddressTypeStr get a text description of the address type
func (Address) IsEqualWithoutType ¶
func (Address) MarshalJSON ¶
func (*Address) SetBytes ¶
Sets the address to the value of b. If b is larger than len(a) it will panic
func (*Address) UnmarshalJSON ¶
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) 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 BytesToHash ¶
func StringToHash ¶
func (Hash) Cmp ¶
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) HexWithout0x ¶
func (Hash) MarshalJSON ¶
func (*Hash) 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) UnmarshalJSON ¶
func (Hash) ValidHashForDifficulty ¶
func (h Hash) ValidHashForDifficulty(difficulty Difficulty) bool
ValidHashForDifficulty check is it a hash that meets the corresponding difficulty?
type PrettyDuration ¶
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 UnprefixedAddress ¶
type UnprefixedAddress Address
Source Files ¶
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 |