Documentation ¶
Overview ¶
Package common provides common data structures and common utility functions.
Index ¶
- Constants
- Variables
- func AbsInt(x int) int
- func AddrToHex(s string) string
- func ByteToInt32(b []byte) int32
- func ByteToInt64(b []byte) int64
- func ByteToUInt16(b []byte) uint16
- func ByteToUInt32(b []byte) uint32
- func ByteToUInt64(b []byte) uint64
- func ByteToUint64(bs []byte) uint64
- func Bytes2Hex(d []byte) string
- func BytesCombine(pBytes ...[]byte) []byte
- func CopyBytes(b []byte) (copiedBytes []byte)
- func Decode(input string) ([]byte, error)
- func DecodeBig(input string) (*big.Int, error)
- func DecodeUint64(input string) (uint64, error)
- func DecryptWithKey(Key []byte, Data []byte) (result []byte, err error)
- func Encode(b []byte) string
- func EncodeBig(bigint *big.Int) string
- func EncodeUint64(i uint64) string
- func Encrypt(rand io.Reader, pub *PublicKey, msg []byte) (ct []byte, err error)
- func EncryptWithKey(Key []byte, Data []byte) (result []byte, err error)
- func FromHex(s string) []byte
- func Hex2Bytes(str string) []byte
- func InitConf(path string)
- func Int32ToByte(i int32) []byte
- func Int64ToByte(i int64) []byte
- func IsHex(str string) bool
- func IsWeakPassword(password string) bool
- func MustDecode(input string) []byte
- func MustDecodeBig(input string) *big.Int
- func MustDecodeUint64(input string) uint64
- func MustNewLRUCache(size int) *lru.Cache
- func MustNewLRUCacheWithEvictCB(size int, cb func(k, v interface{})) *lru.Cache
- func ParseCoin(s string) (uint64, error)
- func RA2TAS(v uint64) float64
- func Sha256(blockByte []byte) []byte
- func ShortHex(hex string) string
- func ShortHex12(hex string) string
- func TAS2RA(v uint64) uint64
- func ToAddrHex(b []byte) string
- func ToHex(b []byte) string
- func UInt16ToByte(i uint16) []byte
- func UInt32ToByte(i uint32) []byte
- func UInt64ToByte(i uint64) []byte
- func Uint64ToByte(i uint64) []byte
- func UnmarshalAddr(typname string, input, out []byte) error
- func UnmarshalAddrJSON(typ reflect.Type, input, out []byte) error
- func UnmarshalFixedJSON(typ reflect.Type, input, out []byte) error
- func UnmarshalFixedText(typname string, input, out []byte) error
- func UnmarshalFixedUnprefixedText(typname string, input, out []byte) error
- func ValidateAddress(addr string) bool
- type AccountData
- type Address
- func (a Address) AddrPrefixString() string
- func (a Address) BigInteger() *big.Int
- func (a Address) Bytes() []byte
- func (a Address) Hash() Hash
- 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)
- func (a Address) String() string
- func (a *Address) UnmarshalJSON(input []byte) error
- func (a *Address) UnmarshalText(input []byte) error
- type Big
- type Bytes
- type ConfFileManager
- func (cs *ConfFileManager) Del(section string, key string)
- func (cs *ConfFileManager) GetBool(section string, key string, defaultValue bool) bool
- func (cs *ConfFileManager) GetDouble(section string, key string, defaultValue float64) float64
- func (cs *ConfFileManager) GetInt(section string, key string, defaultValue int) int
- func (cs *ConfFileManager) GetSectionManager(section string) SectionConfManager
- func (cs *ConfFileManager) GetString(section string, key string, defaultValue string) string
- func (cs *ConfFileManager) SetBool(section string, key string, value bool)
- func (cs *ConfFileManager) SetDouble(section string, key string, value float64)
- func (cs *ConfFileManager) SetInt(section string, key string, value int)
- func (cs *ConfFileManager) SetString(section string, key string, value string)
- type ConfManager
- type FundModeType
- type Hash
- func (h Hash) Big() *big.Int
- func (h Hash) Bytes() []byte
- func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value
- func (h Hash) Hex() string
- func (h Hash) IsValid() bool
- func (h Hash) MarshalText() ([]byte, error)
- func (h *Hash) Set(other Hash)
- func (h *Hash) SetBytes(b []byte)
- func (h *Hash) SetString(s 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 Hash256
- type PrivateKey
- func (pk *PrivateKey) Bytes() []byte
- func (pk *PrivateKey) Decrypt(rand io.Reader, ct []byte) (m []byte, err error)
- func (pk *PrivateKey) ExportKey() []byte
- func (pk *PrivateKey) GetPubKey() PublicKey
- func (pk *PrivateKey) Hex() string
- func (pk *PrivateKey) ImportKey(key []byte) bool
- func (pk PrivateKey) Sign(hash []byte) (Sign, error)
- type PublicKey
- type SectionConfFileManager
- func (sfm *SectionConfFileManager) Del(key string)
- func (sfm *SectionConfFileManager) GetBool(key string, defaultValue bool) bool
- func (sfm *SectionConfFileManager) GetDouble(key string, defaultValue float64) float64
- func (sfm *SectionConfFileManager) GetInt(key string, defaultValue int) int
- func (sfm *SectionConfFileManager) GetString(key string, defaultValue string) string
- func (sfm *SectionConfFileManager) SetBool(key string, value bool)
- func (sfm *SectionConfFileManager) SetDouble(key string, value float64)
- func (sfm *SectionConfFileManager) SetInt(key string, value int)
- func (sfm *SectionConfFileManager) SetString(key string, value string)
- type SectionConfManager
- type Sign
- type SignData
- type StorageSize
- type TimeMetric
- type TimeStatCtx
- type Uint
- type Uint64
- type UnprefixedHash
Constants ¶
const ( RA uint64 = 1 KRA uint64 = 1000 MRA uint64 = 1000000 ZVC uint64 = 1000000000 )
const ( //Elliptic curve parameters: PubKeyLength = 65 //Length of public key,1 bytes curve, 64 bytes x,y。 SecKeyLength = 97 //length of private key,65 bytes pub, 32 bytes D。 SignLength = 65 //length of signature,32 bytes r & 32 bytes s & 1 byte recid. AddressLength = 32 //Length of Address( golang.SHA3,256-bit) HashLength = 32 //Length of Hash (golang.SHA3, 256-bit)。 MinPasswordLength = 6 MaxPasswordLength = 50 DefaultPassword = "Zvc123" )
const ( // Integer limit values. MaxInt8 = 1<<7 - 1 MinInt8 = -1 << 7 MaxInt16 = 1<<15 - 1 MinInt16 = -1 << 15 MaxInt32 = 1<<31 - 1 MinInt32 = -1 << 31 MaxInt64 = 1<<63 - 1 MinInt64 = -1 << 63 MaxUint8 = 1<<8 - 1 MaxUint16 = 1<<16 - 1 MaxUint32 = 1<<32 - 1 MaxUint64 = 1<<64 - 1 )
const AddrPrefix = "zv"
const ChainDataVersion = 1
const ConsensusVersion = 1
const GzvVersion = "v1.0.11"
const HexPrefix = "0x"
const ProtocolVersion = 1
Variables ¶
var ( ErrEmptyStr = fmt.Errorf("empty string") ErrIllegalStr = fmt.Errorf("illegal gasprice string") )
var ( ErrEmptyString = &decError{"empty hex string"} ErrSyntax = &decError{"invalid hex string"} ErrMissingPrefix = &decError{"hex string without 0x prefix"} ErrMissingAddrPrefix = &decError{"address string without prefix"} ErrOddLength = &decError{"hex string of odd length"} ErrEmptyNumber = &decError{"hex string \"0x\""} ErrLeadingZero = &decError{"hex number with leading zero digits"} ErrUint64Range = &decError{"hex number > 64 bits"} ErrUintRange = &decError{fmt.Sprintf("hex number > %d bits", uintBits)} ErrBig256Range = &decError{"hex number > 256 bits"} )
var ( BonusStorageAddress = BigToAddress(big.NewInt(0)) MinerPoolAddr = BigToAddress(big.NewInt(1)) // The Address storing total stakes of each roles and addresses of all active nodes RewardStoreAddr = BigToAddress(big.NewInt(2)) // The Address storing the block hash corresponding to the reward transaction GroupTopAddress = BigToAddress(big.NewInt(3)) //save the current top group MinerPoolTicketsAddr = BigToAddress(big.NewInt(4)) // The Address storing all miner pool tickets FundGuardNodeAddr = BigToAddress(big.NewInt(5)) // The Address storing all fund gurad nodes FullStakeGuardNodeAddr = BigToAddress(big.NewInt(6)) // The Address storing all full stake guard nodes ScanAllFundGuardStatusAddr = BigToAddress(big.NewInt(7)) // The Address mark is scanned all fund guard nodes )
Special account address Need to access by AccountDBTS for concurrent situations
var ( PrefixMiner = []byte("minfo") PrefixDetail = []byte("dt") PrefixPoolProposal = []byte("p") PrefixPoolVerifier = []byte("v") KeyPoolProposalTotalStake = []byte("totalstake") KeyVote = []byte("votekey") KeyTickets = []byte("tickets") KeyGuardNodes = []byte("guard") KeyScanSixAddFiveNodes = []byte("s1") KeyScanSixAddSixNodes = []byte("s2") )
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) ErrSelectGroupNil = errors.New("selectGroupId is nil") ErrSelectGroupInequal = errors.New("selectGroupId not equal") ErrCreateBlockNil = errors.New("createBlock is nil") ErrGroupNil = errors.New("group is nil") )
var EmptyHash = Hash{}
var InstanceIndex int
var (
MaxBigUint64 = big.NewInt(0).SetUint64(MaxUint64)
)
var PunishmentDetailAddr = BigToAddress(big.NewInt(0))
Functions ¶
func AbsInt ¶
AbsInt returns the absolute value of the x integer.
Special cases are:
AbsInt(minInt) results in a panic (not representable)
func ByteToInt32 ¶
func ByteToInt64 ¶
func ByteToUInt16 ¶
func ByteToUInt32 ¶
func ByteToUInt64 ¶
func ByteToUint64 ¶
ByteToUint64 converts the byte array to a 64-bits unsigned integer
func BytesCombine ¶
BytesCombine combines multiple byte arrays into one byte array
func DecodeBig ¶
DecodeBig decodes a hex string with 0x prefix as a quantity. Numbers larger than 256 bits are not accepted.
func DecodeUint64 ¶
DecodeUint64 decodes a hex string with 0x prefix as a quantity.
func DecryptWithKey ¶
DecryptWithKey implements symmetric decryption with the specified key extract 12 byte nonce from the data and deseal the data if key is incorrect, err return not nil
func EncodeBig ¶
EncodeBig encodes bigint as a hex string with 0x prefix. The sign of the integer is ignored.
func EncodeUint64 ¶
EncodeUint64 encodes i as a hex string with 0x prefix.
func EncryptWithKey ¶
EncryptWithKey implements symmetric encryption with the specified key all data in encrypted within the storage using this function
func Int32ToByte ¶
func Int64ToByte ¶
func IsWeakPassword ¶
func MustDecode ¶
MustDecode decodes a hex string with 0x prefix. It panics for invalid input.
func MustDecodeBig ¶
MustDecodeBig decodes a hex string with 0x prefix as a quantity. It panics for invalid input.
func MustDecodeUint64 ¶
MustDecodeUint64 decodes a hex string with 0x prefix as a quantity. It panics for invalid input.
func MustNewLRUCache ¶
MustNewLRUCache creates a new lru cache. Caution: if fail, the function will cause panic developer should promise size > 0 when use this function
func MustNewLRUCacheWithEvictCB ¶
MustNewLRUCacheWithEvictCB creates a new lru cache with buffer eviction Caution: if fail, the function will cause panic.
func ShortHex12 ¶
func UInt16ToByte ¶
func UInt32ToByte ¶
func UInt64ToByte ¶
func Uint64ToByte ¶
Uint64ToByte converts 64-bits unsigned integer to byte array
func UnmarshalAddr ¶
UnmarshalFixedText decodes the input as a string with 0x prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalText method for fixed-size types.
func UnmarshalAddrJSON ¶
UnmarshalFixedJSON decodes the input as a string with 0x prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalJSON method for fixed-size types.
func UnmarshalFixedJSON ¶
UnmarshalFixedJSON decodes the input as a string with 0x prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalJSON method for fixed-size types.
func UnmarshalFixedText ¶
UnmarshalFixedText decodes the input as a string with 0x prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalText method for fixed-size types.
func UnmarshalFixedUnprefixedText ¶
UnmarshalFixedUnprefixedText decodes the input as a string with optional 0x prefix. The length of out determines the required input length. This function is commonly used to implement the UnmarshalText method for fixed-size types.
func ValidateAddress ¶
Types ¶
type AccountData ¶
type AccountData struct {
// contains filtered or unexported fields
}
type Address ¶
type Address [AddressLength]byte
Address data struct
func BigToAddress ¶
BigToAddress returns the address of the input big integer assignment
func BytesToAddress ¶
BytesToAddress returns the Address imported from the input byte array
func HashToAddress ¶
func StringToAddress ¶
StringToAddress returns the address of the input string assignment
func (Address) AddrPrefixString ¶
ZvPrefixHex returns the hex string representation of a
func (Address) BigInteger ¶
BigInteger returns the big integer representation of a
func (Address) MarshalJSON ¶
MarshalJSON encodes the address as byte array with json format
func (Address) MarshalText ¶
MarshalText returns the hex representation of a.
func (*Address) UnmarshalJSON ¶
UnmarshalJSON parses an address in hex syntax with json format.
func (*Address) UnmarshalText ¶
UnmarshalText parses an address in hex syntax.
type Big ¶
Big marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".
Negative integers are not supported at this time. Attempting to marshal them will return an error. Values larger than 256bits are rejected by Unmarshal but will be marshaled without error.
func (Big) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (*Big) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Big) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler
type Bytes ¶
type Bytes []byte
Bytes marshals/unmarshals as a JSON string with 0x prefix. The empty slice marshals as "0x".
func (Bytes) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (*Bytes) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Bytes) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type ConfFileManager ¶
type ConfFileManager struct {
// contains filtered or unexported fields
}
func (*ConfFileManager) Del ¶
func (cs *ConfFileManager) Del(section string, key string)
func (*ConfFileManager) GetBool ¶
func (cs *ConfFileManager) GetBool(section string, key string, defaultValue bool) bool
func (*ConfFileManager) GetDouble ¶
func (cs *ConfFileManager) GetDouble(section string, key string, defaultValue float64) float64
func (*ConfFileManager) GetInt ¶
func (cs *ConfFileManager) GetInt(section string, key string, defaultValue int) int
func (*ConfFileManager) GetSectionManager ¶
func (cs *ConfFileManager) GetSectionManager(section string) SectionConfManager
func (*ConfFileManager) GetString ¶
func (cs *ConfFileManager) GetString(section string, key string, defaultValue string) string
func (*ConfFileManager) SetBool ¶
func (cs *ConfFileManager) SetBool(section string, key string, value bool)
func (*ConfFileManager) SetDouble ¶
func (cs *ConfFileManager) SetDouble(section string, key string, value float64)
type ConfManager ¶
type ConfManager interface { //read basic conf from tas.conf file //返回section组下的key的值, 若未配置, 则返回默认值defv GetString(section string, key string, defaultValue string) string GetBool(section string, key string, defaultValue bool) bool GetDouble(section string, key string, defaultValue float64) float64 GetInt(section string, key string, defaultValue int) int //set basic conf to tas.conf file SetString(section string, key string, value string) SetBool(section string, key string, value bool) SetDouble(section string, key string, value float64) SetInt(section string, key string, value int) //delete basic conf Del(section string, key string) //获取一个section的配置管理 GetSectionManager(section string) SectionConfManager }
var GlobalConf ConfManager
func NewConfINIManager ¶
func NewConfINIManager(path string) ConfManager
type Hash ¶
type Hash [HashLength]byte
///////////////////////////////////////////////////////////////////////////// Hash data struct (256-bits)
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 larger than len(h), 'b' will be cropped (from the left).
func (*Hash) SetString ¶
SetString sets 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 with json format.
func (*Hash) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
type PrivateKey ¶
type PrivateKey struct {
PrivKey ecdsa.PrivateKey
}
PrivateKey data struct
func BytesToSecKey ¶
func BytesToSecKey(data []byte) (sk *PrivateKey)
BytesToSecKey returns a private key with the byte array imported
func GenerateKey ¶
func GenerateKey(s string) (PrivateKey, error)
GenerateKey creates a Private key by the specified string
func HexToSecKey ¶
func HexToSecKey(s string) (sk *PrivateKey)
HexToSecKey returns a private key with the hex string imported.
func (*PrivateKey) Bytes ¶
func (pk *PrivateKey) Bytes() []byte
Bytes converts the private key to a byte array
func (*PrivateKey) ExportKey ¶
func (pk *PrivateKey) ExportKey() []byte
ExportKey returns a byte array representation of the secure key of private key
func (*PrivateKey) GetPubKey ¶
func (pk *PrivateKey) GetPubKey() PublicKey
GetPubKey returns the public key mapped to the private key
func (*PrivateKey) Hex ¶
func (pk *PrivateKey) Hex() string
Hex converts the private key to a hex string
func (*PrivateKey) ImportKey ¶
func (pk *PrivateKey) ImportKey(key []byte) bool
ImportKey constructs the private key from the input secure key.
type PublicKey ¶
PublicKey data struct
func BytesToPublicKey ¶
BytesToPublicKey returns a public key with the byte array imported
func HexToPubKey ¶
HexToPubKey returns a public key with the hex string imported
func (PublicKey) GetAddress ¶
GetAddress obtains the address mapped from the public key
type SectionConfFileManager ¶
type SectionConfFileManager struct {
// contains filtered or unexported fields
}
func (*SectionConfFileManager) Del ¶
func (sfm *SectionConfFileManager) Del(key string)
func (*SectionConfFileManager) GetBool ¶
func (sfm *SectionConfFileManager) GetBool(key string, defaultValue bool) bool
func (*SectionConfFileManager) GetDouble ¶
func (sfm *SectionConfFileManager) GetDouble(key string, defaultValue float64) float64
func (*SectionConfFileManager) GetInt ¶
func (sfm *SectionConfFileManager) GetInt(key string, defaultValue int) int
func (*SectionConfFileManager) GetString ¶
func (sfm *SectionConfFileManager) GetString(key string, defaultValue string) string
func (*SectionConfFileManager) SetBool ¶
func (sfm *SectionConfFileManager) SetBool(key string, value bool)
func (*SectionConfFileManager) SetDouble ¶
func (sfm *SectionConfFileManager) SetDouble(key string, value float64)
func (*SectionConfFileManager) SetInt ¶
func (sfm *SectionConfFileManager) SetInt(key string, value int)
func (*SectionConfFileManager) SetString ¶
func (sfm *SectionConfFileManager) SetString(key string, value string)
type SectionConfManager ¶
type SectionConfManager interface { //read basic conf from tas.conf file //返回section组下的key的值, 若未配置, 则返回默认值defv GetString(key string, defaultValue string) string GetBool(key string, defaultValue bool) bool GetDouble(key string, defaultValue float64) float64 GetInt(key string, defaultValue int) int //set basic conf to tas.conf file SetString(key string, value string) SetBool(key string, value bool) SetDouble(key string, value float64) SetInt(key string, value int) //delete basic conf Del(key string) }
type Sign ¶
type Sign struct {
// contains filtered or unexported fields
}
Sign Data struct
func BytesToSign ¶
BytesToSign returns a signature with the byte array imported. The length of the byte array must be 65.
func (Sign) RecoverPubkey ¶
RecoverPubkey returns the public key recovered from the signature
type StorageSize ¶
type StorageSize float64
type TimeMetric ¶
type TimeStatCtx ¶
type TimeStatCtx struct { Stats map[string]*TimeMetric // contains filtered or unexported fields }
func NewTimeStatCtx ¶
func NewTimeStatCtx() *TimeStatCtx
func (*TimeStatCtx) Output ¶
func (ts *TimeStatCtx) Output() string
type Uint ¶
type Uint uint
Uint marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".
func (Uint) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Uint) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Uint) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Uint64 ¶
type Uint64 uint64
Uint64 marshals/unmarshals as a JSON string with 0x prefix. The zero value marshals as "0x0".
func (Uint64) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*Uint64) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Uint64) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler
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 ecies implements ECIES encryption/decryption algorithm.
|
Package ecies implements ECIES encryption/decryption algorithm. |
Package ed25519 implements the Ed25519 signature algorithm.
|
Package ed25519 implements the Ed25519 signature algorithm. |
Package secp256k1 wraps the bitcoin secp256k1 C library.
|
Package secp256k1 wraps the bitcoin secp256k1 C library. |