Documentation ¶
Overview ¶
Package common contains various helper functions.
Index ¶
- Constants
- Variables
- func AbsolutePath(Datadir string, filename string) string
- func Bytes2Hex(d []byte) string
- func ConvertInt64ToBytes(num int64) []byte
- func CopyBytes(b []byte) (copiedBytes []byte)
- func FileExist(filePath string) bool
- func FileOrFolderExists(fileOrFolder string) bool
- func FromHex(s string) []byte
- func GetDefaultDataFolder() string
- func GetTempFolder() string
- func HasHexPrefix(str string) bool
- func Hex2Bytes(str string) []byte
- func Hex2BytesFixed(str string, flen int) []byte
- func IsHex(str string) bool
- func IsHexAddress(s string) bool
- func LeftPadBytes(slice []byte, l int) []byte
- func LoadJSON(file string, val interface{}) error
- func MakeName(name, version string) string
- func PrintDepricationWarning(str string)
- func Report(extra ...interface{})
- func RightPadBytes(slice []byte, l int) []byte
- func ToHex(b []byte) string
- type Address
- func (a Address) Big() *big.Int
- func (a Address) Bytes() []byte
- func (id *Address) Equal(b Address) bool
- func (a Address) Format(s fmt.State, c rune)
- func (a Address) Hash() Hash
- func (a Address) Hex() string
- func (a Address) MarshalText() ([]byte, error)
- func (a *Address) Set(other Address)
- func (a *Address) SetBytes(b []byte)
- func (a *Address) SetString(s string)
- func (a Address) Str() string
- func (a Address) String() string
- func (id *Address) ToHex() string
- func (a *Address) UnmarshalJSON(input []byte) error
- func (a *Address) UnmarshalText(input []byte) error
- type Hash
- func (a Hash) Big() *big.Int
- func (a Hash) Bytes() []byte
- func (a Hash) Equal(b Hash) bool
- func (h Hash) Format(s fmt.State, c rune)
- func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value
- func (h Hash) Hex() string
- func (a Hash) IsEmpty() bool
- func (h Hash) MarshalText() ([]byte, error)
- func (h *Hash) Set(other Hash)
- func (a *Hash) SetBytes(b []byte)
- func (h *Hash) SetString(s string)
- func (h Hash) Str() string
- func (a Hash) String() string
- func (h Hash) TerminalString() string
- func (a Hash) ToHex() string
- func (h *Hash) UnmarshalJSON(input []byte) error
- func (h *Hash) UnmarshalText(input []byte) error
- type PrettyDuration
- type StorageSize
- type UnprefixedAddress
- type UnprefixedHash
Constants ¶
const (
//HashLength = 32
AddressLength = 20
)
const (
// HashLength the leghth of hash
HashLength = 32
)
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(0xff) Big257 = big.NewInt(257) )
Common big integers often used
var ( // PrintLog default is false. If it is true, all logs will be printed in the console, otherwise they will be stored in the file. PrintLog = false // IsDebug default is false. If IsDebug is true, the log level will be DebugLevel, otherwise it is InfoLevel IsDebug = false )
Functions ¶
func AbsolutePath ¶
func ConvertInt64ToBytes ¶
ConvertInt64ToBytes converts a int64 value into a byte array
func FileOrFolderExists ¶
FileOrFolderExists checks if a file or folder exists
func GetDefaultDataFolder ¶
func GetDefaultDataFolder() string
GetDefaultDataFolder gets the default data Folder
func HasHexPrefix ¶
func Hex2BytesFixed ¶
func IsHexAddress ¶
IsHexAddress verifies whether a string can represent a valid hex-encoded Ethereum address or not.
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 PrintDepricationWarning ¶
func PrintDepricationWarning(str string)
PrintDepricationWarning prinst the given string in a box using fmt.Println.
func Report ¶
func Report(extra ...interface{})
Report gives off a warning requesting the user to submit an issue to the github tracker.
func RightPadBytes ¶
Types ¶
type Address ¶
type Address [AddressLength]byte
Address represents the 20 byte address of an Ethereum account.
func BigToAddress ¶
BigToAddress converts a big int to address.
func BytesToAddress ¶
BytesToAddress converts the specified byte array to Address.
func NewAddress ¶
NewAddress converts a byte slice to a Address
func StringToAddress ¶
func BytesToAddress(b []byte) Address { var a Address a.SetBytes(b) return a }
func (Address) Format ¶
Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.
func (Address) MarshalText ¶
MarshalText returns the hex representation of a.
func (*Address) SetBytes ¶
Sets the address to the value of b. If b is larger than len(a) it will panic
func (*Address) UnmarshalJSON ¶
UnmarshalJSON parses a hash in hex syntax.
func (*Address) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
type Hash ¶
type Hash [HashLength]byte
Hash the hash value generated by sha-3
func (Hash) Equal ¶
Equal returns a boolean value indicating whether the hash a is equal to the input hash b.
func (Hash) Format ¶
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) Bytes() []byte { return h[:] } func (h Hash) Big() *big.Int { return new(big.Int).SetBytes(h[:]) }
func (Hash) MarshalText ¶
MarshalText returns the hex representation of h.
func (*Hash) SetBytes ¶
SetBytes sets the hash to the value of b. If b is greater than len(a) it will panic
func (*Hash) SetString ¶
Set string `s` to h. If s is larger than len(h) s will be cropped (from left) to fit.
func (Hash) TerminalString ¶
TerminalString implements log.TerminalStringer, formatting a string for console output during logging.
func (*Hash) UnmarshalJSON ¶
UnmarshalJSON parses a hash in hex syntax.
func (*Hash) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
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
func (StorageSize) Int64 ¶
func (self StorageSize) Int64() int64
func (StorageSize) String ¶
func (self StorageSize) String() string
type UnprefixedAddress ¶
type UnprefixedAddress Address
UnprefixedHash 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.
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 |
Package metrics provides general system and process level metrics collection.
|
Package metrics provides general system and process level metrics collection. |
nat
Package nat provides access to common network port mapping protocols.
|
Package nat provides access to common network port mapping protocols. |
netutil
Package netutil contains extensions to the net package.
|
Package netutil contains extensions to the net package. |