common

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2020 License: LGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AddressLen length in bytes
	AddressLen = 20

	// AddressTypeExternal is the address type for external account.
	AddressTypeExternal = AddressType(1)

	// AddressTypeContract is the address type for contract account.
	AddressTypeContract = AddressType(2)

	// AddressTypeReserved is the reserved address type for system contract.
	// Note, the address type (4 bits) value ranges [0,15], so the system reserved
	// address type value should greater than 15.
	AddressTypeReserved = AddressType(16)
)
View Source
const (

	// SeeleProtoName protoName of Seele service
	SeeleProtoName = "seele"

	// SeeleVersion Version number of Seele protocol
	SeeleVersion uint = 1

	// SeeleVersion for simpler display
	SeeleNodeVersion string = "v1.3.0"

	// ShardCount represents the total number of shards.
	ShardCount = 4

	// MetricsRefreshTime is the time of metrics sleep 1 minute
	MetricsRefreshTime = time.Minute

	// CPUMetricsRefreshTime is the time of metrics monitor cpu
	CPUMetricsRefreshTime = time.Second

	// ConfirmedBlockNumber is the block number for confirmed a block, it should be more than 12 in product
	ConfirmedBlockNumber = 120

	// ForkHeight after this height we change the content of block: hardFork
	ForkHeight = 130000

	// ForkHeight after this height we change the content of block: hardFork
	SecondForkHeight = 145000

	// ForkHeight after this height we change the validation of tx: hardFork
	ThirdForkHeight = 735000

	SmartContractNonceForkHeight = 1100000

	// LightChainDir lightchain data directory based on config.DataRoot
	LightChainDir = "/db/lightchain"

	// EthashAlgorithm miner algorithm ethash
	EthashAlgorithm = "ethash"

	// Sha256Algorithm miner algorithm sha256
	Sha256Algorithm = "sha256"

	// spow miner algorithm
	SpowAlgorithm = "spow"

	// BFT mineralgorithm
	BFTEngine = "bft"

	// BFT data folder
	BFTDataFolder = "bftdata"

	// EVMStackLimit increase evm stack limit to 8192
	EVMStackLimit = 8192

	// BlockPackInterval it's an estimate time.
	BlockPackInterval = 15 * time.Second

	// Height: fix the issue caused by forking from collapse database
	HeightFloor = uint64(707989)
	HeightRoof  = uint64(707996)

	WindowsPipeDir = `\\.\pipe\`
)
View Source
const (
	// HashLength the leghth of hash
	HashLength = 32
)
View Source
const UndefinedShardNumber = uint(0)

UndefinedShardNumber is the default value if shard number not specified.

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 EmptyAddress = Address{}

EmptyAddress presents an empty address

View Source
var EmptyHash = Hash{}

EmptyHash empty hash

View Source
var ErrOnly0xPrefix = errors.New("the string is invalid length only 0x or 0X prefix")

ErrOnly0xPrefix the string is invalid length only 0x or 0X prefix

View Source
var LocalShardNumber uint

LocalShardNumber defines the shard number of coinbase. Generally, it must be initialized during program startup.

View Source
var MaxSystemContractAddress = BytesToAddress([]byte{4, 255})

MaxSystemContractAddress max system contract address

View Source
var (
	//SeeleToFan base feifan coin number
	SeeleToFan = big.NewInt(100000000)
)

Functions

func BigToDecimal

func BigToDecimal(amount *big.Int) string

BigToDecimal simply changes big int to decimal which will miss additional 0 in the last

func ConvertInt64ToBytes

func ConvertInt64ToBytes(num int64) []byte

ConvertInt64ToBytes converts a int64 value into a byte array

func CopyBytes

func CopyBytes(src []byte) []byte

CopyBytes copies and returns a new bytes from the specified source bytes.

func Deserialize

func Deserialize(data []byte, value interface{}) error

Deserialize wrapper decode

func FileOrFolderExists

func FileOrFolderExists(fileOrFolder string) bool

FileOrFolderExists checks if a file or folder exists

func GetDefaultDataFolder

func GetDefaultDataFolder() string

GetDefaultDataFolder gets the default data Folder

func GetDefaultIPCPath

func GetDefaultIPCPath() string

func GetPassword

func GetPassword() (string, error)

GetPassword ask user for password interactively

func GetTempFolder

func GetTempFolder() string

GetTempFolder uses a getter to implement readonly

func IsShardEnabled

func IsShardEnabled() bool

IsShardEnabled returns true if the LocalShardNumber is set. Otherwise, false.

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

LeftPadBytes zero-pads slice to the left up to length l.

func MustNewCache

func MustNewCache(size int) *lru.Cache

MustNewCache creates a LRU cache with specified size. Panics on any error.

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

RightPadBytes zero-pads slice to the right up to length l.

func SaveFile

func SaveFile(filePath string, content []byte) error

SaveFile save file

func Serialize

func Serialize(in interface{}) ([]byte, error)

Serialize wrapper encode

func SerializePanic

func SerializePanic(in interface{}) []byte

SerializePanic serialize the input data to byte array. Panics on error, e.g. unsupported data type for RLP encoding.

func SetPassword

func SetPassword() (string, error)

SetPassword ask user input password twice and get the password interactively

func Shuffle

func Shuffle(slice interface{})

Shuffle shuffles items in slice

Types

type Address

type Address [AddressLen]byte

Address we use public key as node id

func BigToAddress

func BigToAddress(b *big.Int) Address

BigToAddress converts a big int to address.

func BytesToAddress

func BytesToAddress(bs []byte) Address

BytesToAddress converts the specified byte array to Address.

func HexMustToAddres

func HexMustToAddres(id string) Address

HexMustToAddres converts the specified HEX string to address. Panics on any error.

func HexToAddress

func HexToAddress(id string) (Address, error)

HexToAddress converts the specified HEX string to address.

func NewAddress

func NewAddress(b []byte) (Address, error)

NewAddress converts a byte slice to a Address

func PubKeyToAddress

func PubKeyToAddress(pubKey *ecdsa.PublicKey, hashFunc func(interface{}) Hash) Address

PubKeyToAddress converts a ECC public key to an external address.

func (Address) Big

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

Big converts address to a big int.

func (Address) Bytes

func (id Address) Bytes() []byte

Bytes get the actual bytes

Note: if we want to use pointer type, need to change the code snippet in unit test:

BytesToAddress([]byte{1, 2}).Bytes()
->
addrBytes := BytesToAddress([]byte{1, 2})
(&addrBytes).Bytes()

refer link: https://stackoverflow.com/questions/10535743/address-of-a-temporary-in-go

func (*Address) CreateContractAddress

func (id *Address) CreateContractAddress(nonce uint64, hashFunc func(interface{}) Hash) Address

CreateContractAddress returns a contract address that in the same shard of this address.

func (*Address) CreateContractAddressWithHash

func (id *Address) CreateContractAddressWithHash(h Hash) Address

CreateContractAddressWithHash returns a contract address that in the same shard of this address.

func (*Address) Equal

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

Equal checks if this address is the same with the specified address b.

func (Address) Hex

func (id Address) Hex() string

Hex converts address to 0x prefixed HEX format.

func (*Address) IsEVMContract

func (id *Address) IsEVMContract() bool

IsEVMContract indicates whether the address is EVM contract address.

func (*Address) IsEmpty

func (id *Address) IsEmpty() bool

IsEmpty returns true if this address is empty. Otherwise, false.

func (*Address) IsReserved

func (id *Address) IsReserved() bool

IsReserved returns true if the address is reserved

func (Address) MarshalText

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

MarshalText marshals the address to HEX string.

func (*Address) Shard

func (id *Address) Shard() uint

Shard returns the shard number of this address.

func (Address) String

func (id Address) String() string

String implements the fmt.Stringer interface

func (*Address) Type

func (id *Address) Type() AddressType

Type returns the address type

func (*Address) UnmarshalText

func (id *Address) UnmarshalText(json []byte) error

UnmarshalText unmarshals address from HEX string.

func (*Address) Validate

func (id *Address) Validate() error

Validate check whether the address is valid.

type AddressType

type AddressType byte

AddressType represents the address type

type BaseHeapItem

type BaseHeapItem struct {
	// contains filtered or unexported fields
}

BaseHeapItem is base struct of any heap item.

func (*BaseHeapItem) GetHeapIndex

func (item *BaseHeapItem) GetHeapIndex() int

GetHeapIndex returns the item index in heap.

type Bytes

type Bytes []byte

Bytes is a array byte that is converted to hex string display format when marshal

func (Bytes) MarshalText

func (b Bytes) MarshalText() ([]byte, error)

MarshalText implement the TextMarshaler interface

func (*Bytes) UnmarshalText

func (b *Bytes) UnmarshalText(hex []byte) error

UnmarshalText implement the TextUnmarshaler interface

type Hash

type Hash [HashLength]byte

Hash the hash value generated by sha-3

func BigToHash

func BigToHash(b *big.Int) Hash

BigToHash converts a big int to Hash.

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash converts bytes to hash value

func HexToHash

func HexToHash(hex string) (Hash, error)

HexToHash return the hash form of the hex

func MustHexToHash

func MustHexToHash(hex string) Hash

func StringToHash

func StringToHash(s string) Hash

StringToHash converts a string to the hash

func (Hash) Big

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

Big converts this Hash to a big int.

func (Hash) Bytes

func (a Hash) Bytes() []byte

Bytes returns its actual bits

func (*Hash) Equal

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

Equal returns a boolean value indicating whether the hash a is equal to the input hash b.

func (Hash) Hex

func (a Hash) Hex() string

Hex returns the hex form of the hash

func (Hash) IsEmpty

func (a Hash) IsEmpty() bool

IsEmpty return true if this hash is empty. Otherwise, false.

func (Hash) MarshalText

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

MarshalText marshals the Hash to HEX string.

func (*Hash) SetBytes

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

SetBytes sets the hash to the value of b.

func (Hash) String

func (a Hash) String() string

String returns the string representation of the hash

func (*Hash) UnmarshalText

func (a *Hash) UnmarshalText(json []byte) error

UnmarshalText unmarshals Hash from HEX string.

type Heap

type Heap struct {
	// contains filtered or unexported fields
}

Heap is a common used heap for generic type purpose.

func NewHeap

func NewHeap(lessFunc func(HeapItem, HeapItem) bool) *Heap

NewHeap creates a new heap with specified Less func.

func (*Heap) Len

func (h *Heap) Len() int

Len implements the heap.Interface

func (*Heap) Less

func (h *Heap) Less(i, j int) bool

Less implements the heap.Interface

func (*Heap) Peek

func (h *Heap) Peek() interface{}

Peek returns the top value in heap if any. Otherwise, return nil.

func (*Heap) Pop

func (h *Heap) Pop() interface{}

Pop implements the heap.Interface

func (*Heap) Push

func (h *Heap) Push(x interface{})

Push implements the heap.Interface

func (*Heap) Swap

func (h *Heap) Swap(i, j int)

Swap implements the heap.Interface

type HeapItem

type HeapItem interface {
	GetHeapIndex() int // to support delete item from heap by index.
	// contains filtered or unexported methods
}

HeapItem is implemented by any type that support heap manipulations.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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