common

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: GPL-3.0, GPL-3.0 Imports: 22 Imported by: 2

Documentation

Overview

Package common contains various helper functions.

Index

Constants

View Source
const (
	AddressLength = 21 //byte[0:20] is hash160, byte[20] is AddressType
)
View Source
const (
	HashLength = 32
)
View Source
const MaxHashStringSize = HashLength * 2

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

View Source
var DestroyAddress = Address{}

销毁地址 P1111111111111111111114oLvT2

View Source
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)

Functions

func AbsolutePath

func AbsolutePath(Datadir string, filename string) string

func Bytes2Hex

func Bytes2Hex(d []byte) string

func CheckExists

func CheckExists(search Hash, array []Hash) int

func CopyBytes

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

Copy bytes

Returns an exact copy of the provided bytes

func Decode

func Decode(dst *Hash, src string) error

Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.

func DecodeNumber

func DecodeNumber(key []byte) uint64

func DecodeNumberUint16

func DecodeNumberUint16(key []byte) uint16

func DecodeNumberUint32

func DecodeNumberUint32(key []byte) uint32

func DoubleHashB

func DoubleHashB(b []byte) []byte

DoubleHashB calculates hash(hash(b)) and returns the resulting bytes.

func EmptyHash

func EmptyHash(h Hash) bool

func EncodeNumber

func EncodeNumber(number uint64) []byte

encodeNumber encodes a number as big endian uint64

func EncodeNumberUint16

func EncodeNumberUint16(number uint16) []byte

func EncodeNumberUint32

func EncodeNumberUint32(number uint32) []byte

encodeNumber encodes a number as big endian uint64

func FromHex

func FromHex(s string) []byte

func GetAbsPath

func GetAbsPath(filename string) string

func GetWorkPath

func GetWorkPath() string

func Hex2Bytes

func Hex2Bytes(str string) []byte

func Hex2BytesFixed

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

func IsExisted

func IsExisted(filePath string) bool

func IsHexAddress

func IsHexAddress(s string) bool

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

func IsSystemContractId added in v1.0.4

func IsSystemContractId(contractId []byte) bool

判断一个合约是不是系统合约

func IsUserContractId added in v1.0.4

func IsUserContractId(contractId []byte) bool

判断一个合约是不是用户合约

func IsValidAddress

func IsValidAddress(s string) bool

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 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 RightPadBytes(slice []byte, l int) []byte

func Str2Int64

func Str2Int64(str string) int64

str to uint64

func Str2Uint64

func Str2Uint64(str string) uint64

func ToHex

func ToHex(b []byte) string

func Uint642Str

func Uint642Str(num uint64) string

Types

type Address

type Address [AddressLength]byte

func BytesListToAddressList

func BytesListToAddressList(b []byte) []Address

func BytesToAddress

func BytesToAddress(b []byte) Address

func HexToAddress

func HexToAddress(s string) Address

func NewAddress

func NewAddress(hash160 []byte, ty AddressType) Address

func PubKeyHashHexToAddress

func PubKeyHashHexToAddress(s string) Address

func StringToAddress

func StringToAddress(a string) (Address, error)

将一个字符串格式的Address转换为Address对象

func StringToAddressGodBlessMe

func StringToAddressGodBlessMe(a string) Address

func (Address) Big

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

func (Address) Bytes

func (a Address) Bytes() []byte

Return account 20 bytes without address type

func (Address) Bytes21

func (a Address) Bytes21() []byte

Return address all 21 bytes, you can use SetBytes function to get Address object

func (*Address) Equal

func (a *Address) Equal(b Address) bool

YiRan Returns true when the contents of the two Address are exactly the same

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

func (a *Address) GetType() AddressType

func (Address) Hash

func (a Address) Hash() Hash

func (Address) Hex

func (a Address) Hex() string

func (*Address) IsSystemContractAddress

func (a *Address) IsSystemContractAddress() bool

如果是合约地址,那么是不是一个系统合约地址?

func (*Address) IsZero

func (a *Address) IsZero() bool

func (*Address) Less

func (a *Address) Less(b Address) bool

func (*Address) MarshalJSON

func (a *Address) MarshalJSON() ([]byte, error)

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

MarshalText returns the hex representation of a.

func (*Address) Set

func (a *Address) Set(other Address)

Sets a to other

func (*Address) SetBytes

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

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

func (*Address) SetString

func (a *Address) SetString(s string) error

Set string `s` to a. If s is larger than len(a) it will panic

func (Address) Str

func (a Address) Str() string

Get the string representation of the underlying address

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.

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)

func (Addresses) Len

func (a Addresses) Len() int

func (Addresses) Less

func (a Addresses) Less(i, j int) bool

func (Addresses) Swap

func (a Addresses) Swap(i, j int)

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

func DoubleHashH

func DoubleHashH(b []byte) Hash

func HexToHash

func HexToHash(s string) Hash

func NewSelfHash added in v1.0.1

func NewSelfHash() Hash

这是一个特殊Hash,表示引用自身

func (Hash) Big

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

func (Hash) Bytes

func (h Hash) Bytes() []byte

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

func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value

Generate implements testing/quick.Generator.

func (Hash) Hex

func (h Hash) Hex() string

func (Hash) IsSelfHash added in v1.0.1

func (h Hash) IsSelfHash() bool

func (Hash) IsZero

func (h Hash) IsZero() bool

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)

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 (h *Hash) SetHexString(s string) error

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) ShortStr added in v1.0.7

func (h Hash) ShortStr() string

func (Hash) Str

func (h Hash) Str() string

Get the string representation of the underlying hash

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

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 SignatureError

type SignatureError struct {
	InputIndex uint32
	MsgIndex   uint32
	Error      error
}

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.

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
p2p
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.

Jump to

Keyboard shortcuts

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