Documentation ¶
Overview ¶
Package common contains various helper functions.
Index ¶
- Constants
- Variables
- func AbsolutePath(Datadir string, filename string) string
- func Bytes2Hex(d []byte) string
- func CheckExists(search Hash, array []Hash) int
- func CopyBytes(b []byte) (copiedBytes []byte)
- func Decode(dst *Hash, src string) error
- func DecodeNumber(key []byte) uint64
- func DecodeNumberUint16(key []byte) uint16
- func DecodeNumberUint32(key []byte) uint32
- func DoubleHashB(b []byte) []byte
- func EmptyHash(h Hash) bool
- func EncodeNumber(number uint64) []byte
- func EncodeNumberUint16(number uint16) []byte
- func EncodeNumberUint32(number uint32) []byte
- func FromHex(s string) []byte
- func GetAbsPath(filename string) string
- func GetWorkPath() string
- func Hex2Bytes(str string) []byte
- func Hex2BytesFixed(str string, flen int) []byte
- func IsExisted(filePath string) bool
- func IsHexAddress(s string) bool
- func IsSystemContractId(contractId []byte) bool
- func IsUserContractId(contractId []byte) bool
- func IsValidAddress(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 Str2Int64(str string) int64
- func Str2Uint64(str string) uint64
- func ToHex(b []byte) string
- func Uint642Str(num uint64) string
- type Address
- func BytesListToAddressList(b []byte) []Address
- func BytesToAddress(b []byte) Address
- func HexToAddress(s string) Address
- func NewAddress(hash160 []byte, ty AddressType) Address
- func PubKeyHashHexToAddress(s string) Address
- func StringToAddress(a string) (Address, error)
- func StringToAddressGodBlessMe(a string) Address
- func (a Address) Big() *big.Int
- func (a Address) Bytes() []byte
- func (a Address) Bytes21() []byte
- func (a *Address) Equal(b Address) bool
- func (a Address) Format(s fmt.State, c rune)
- func (a *Address) GetType() AddressType
- func (a Address) Hash() Hash
- func (a Address) Hex() string
- func (a *Address) IsSystemContractAddress() bool
- func (a *Address) IsZero() bool
- func (a *Address) Less(b Address) bool
- func (a *Address) MarshalJSON() ([]byte, error)
- func (a Address) MarshalText() ([]byte, error)
- func (a *Address) Set(other Address)
- func (a *Address) SetBytes(b []byte)
- func (a *Address) SetString(s string) error
- func (a Address) Str() string
- func (a Address) String() string
- func (a *Address) UnmarshalJSON(input []byte) error
- func (a *Address) UnmarshalText(input []byte) error
- func (a Address) Validate() (AddressType, error)
- type AddressType
- type Addresses
- type Hash
- func (h Hash) Big() *big.Int
- func (h Hash) Bytes() []byte
- 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 (h Hash) IsSelfHash() bool
- func (h Hash) IsZero() bool
- func (h Hash) MarshalText() ([]byte, error)
- func (h *Hash) Set(other Hash)
- func (h *Hash) SetBytes(b []byte)
- func (h *Hash) SetHexString(s string) error
- func (h *Hash) SetString(s string)
- func (h Hash) ShortStr() string
- func (h Hash) Str() string
- func (h Hash) String() string
- func (h Hash) TerminalString() string
- func (h *Hash) UnmarshalJSON(input []byte) error
- func (h *Hash) UnmarshalText(input []byte) error
- type MixedcaseAddress
- type PrettyDuration
- type SignatureError
- type StorageSize
- type UnprefixedHash
Constants ¶
const (
AddressLength = 21 //byte[0:20] is hash160, byte[20] is AddressType
)
const (
HashLength = 32
)
const MaxHashStringSize = HashLength * 2
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
var DestroyAddress = Address{}
销毁地址 P1111111111111111111114oLvT2
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)
Functions ¶
func AbsolutePath ¶
func CheckExists ¶
func Decode ¶
Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.
func DecodeNumber ¶
func DecodeNumberUint16 ¶
func DecodeNumberUint32 ¶
func DoubleHashB ¶
DoubleHashB calculates hash(hash(b)) and returns the resulting bytes.
func EncodeNumber ¶
encodeNumber encodes a number as big endian uint64
func EncodeNumberUint16 ¶
func EncodeNumberUint32 ¶
encodeNumber encodes a number as big endian uint64
func GetAbsPath ¶
func GetWorkPath ¶
func GetWorkPath() string
func Hex2BytesFixed ¶
func IsHexAddress ¶
IsHexAddress verifies whether a string can represent a valid hex-encoded PalletOne address or not.
func IsSystemContractId ¶ added in v1.0.4
判断一个合约是不是系统合约
func IsValidAddress ¶
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 ¶
func Str2Uint64 ¶
func Uint642Str ¶
Types ¶
type Address ¶
type Address [AddressLength]byte
func BytesListToAddressList ¶
func BytesToAddress ¶
func HexToAddress ¶
func NewAddress ¶
func NewAddress(hash160 []byte, ty AddressType) Address
func PubKeyHashHexToAddress ¶
func (Address) Bytes21 ¶
Return address all 21 bytes, you can use SetBytes function to get Address object
func (*Address) Equal ¶
YiRan Returns true when the contents of the two Address are exactly the same
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) GetType ¶
func (a *Address) GetType() AddressType
func (*Address) IsSystemContractAddress ¶
如果是合约地址,那么是不是一个系统合约地址?
func (*Address) MarshalJSON ¶
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.
func (Address) Validate ¶
func (a Address) Validate() (AddressType, error)
type AddressType ¶
type AddressType byte
const ( ErrorAddress AddressType = 0xff PublicKeyHash AddressType = 0 ScriptHash AddressType = 5 ContractHash AddressType = 28 OutchainHash AddressType = 115 //PoXxXx )
type Addresses ¶
type Addresses []Address
Address represents the 35 byte address of an PalletOne account. for personal address, start with P1 (version 0), script address start with P3(version 5), contract address start with Pc(version 28)
type Hash ¶
type Hash [HashLength]byte
Hash represents the 32 byte Keccak256 hash of arbitrary data.
func BytesToHash ¶
func DoubleHashH ¶
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) IsSelfHash ¶ added in v1.0.1
func (Hash) MarshalText ¶
MarshalText returns the hex representation of h.
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) SetHexString ¶
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) String ¶
String implements the stringer interface and is used also by the logger when doing full logging into a file.
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 MixedcaseAddress ¶
type MixedcaseAddress struct {
// contains filtered or unexported fields
}
MixedcaseAddress retains the original string, which may or may not be correctly checksummed. ///////////////(for wallet core tyeps SendTxArgs)
func (*MixedcaseAddress) Address ¶
func (ma *MixedcaseAddress) Address() Address
Address returns the address
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) ValidChecksum ¶
func (ma *MixedcaseAddress) ValidChecksum() bool
ValidChecksum returns true if the address has valid checksum
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 SignatureError ¶
type StorageSize ¶
type StorageSize float64
StorageSize is a wrapper around a float value that supports user friendly formatting.
func (StorageSize) Bytes ¶
func (s StorageSize) Bytes() []byte
func (StorageSize) Float64 ¶
func (s StorageSize) Float64() float64
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 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 bloombits implements bloom filtering on batches of data.
|
Package bloombits implements bloom filtering on batches of data. |
gmsm/sm2
crypto/x509 add sm2 support
|
crypto/x509 add sm2 support |
This file is part of go-palletone.
|
This file is part of go-palletone. |
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 |
discover
Package discover implements the Node Discovery Protocol.
|
Package discover implements the Node Discovery Protocol. |
discv5
Package discv5 implements the RLPx v5 Topic Discovery Protocol.
|
Package discv5 implements the RLPx v5 Topic Discovery Protocol. |
enr
Package enr implements PalletOne Node Records as defined in EIP-778.
|
Package enr implements PalletOne Node Records as defined in EIP-778. |
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. |
protocols
Package protocols is an extension to p2p.
|
Package protocols is an extension to p2p. |
simulations
Package simulations simulates p2p networks.
|
Package simulations simulates p2p networks. |
Package rpc provides access to the exported methods of an object across a network or other I/O connection.
|
Package rpc provides access to the exported methods of an object across a network or other I/O connection. |
Package trie implements Merkle Patricia Tries.
|
Package trie implements Merkle Patricia Tries. |
Package util contains various helper functions.
|
Package util contains various helper functions. |