common

package
v0.0.0-...-77b6ffe Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2020 License: MIT Imports: 13 Imported by: 1

Documentation

Overview

Package common contains various helper functions.

Index

Constants

View Source
const (
	MAX_GAS_LIMIT    = "max_gas_limit"
	MAX_EXTRA_LENGTH = "max_extra_length"
	MAX_BLOCK_NUM    = "max_block_num"
)
View Source
const (
	// P2P Message Type
	OkMsg         = "OkMsg"
	RouteSyncReq  = "RouteSyncReq"
	RouteSyncResp = "RouteSyncResp"

	ConsensusMsg     = "ConsensusMsg"
	ConsensusPeerMsg = "ConsensusPeerMsg"
	ProposeBlockMsg  = "ProposeBlockMsg"
	ReadyBlockMsg    = "ReadyBlockMsg"

	NewTxMsg = "NewTxMsg"

	// Consensus Type
	SoloEngine    = "solo"
	PowEngine     = "pow"
	VrfBftEngine  = "vrf_bft"
	DposBftEngine = "dpos_bft"

	/* ---- Configuration field ------ */
	// consensus
	EngineName       = "consensus.engine"
	IsMiner          = "consensus.miner"
	ConsensusPrivKey = "consensus.private_key"
	BlockGasLimit    = "consensus.block_gas_limit"
	Difficulty       = "consensus.difficulty"
	ExtraData        = "consensus.extra_data"

	// P2P
	RouteFilePath = "p2p.route_file_path"
	Port          = "p2p.port"
	NetPrivKey    = "p2p.private_key"
	Seeds         = "p2p.seeds"
	MaxPeers      = "p2p.max_peers"

	// VM
	VMType = "vm.type"

	// Transaction Pool
	MaxTxSize     = "txpool.max_tx_size"
	PriceBump     = "txpool.price_bump"     // percent
	BatchTimeout  = "txpool.batch_timeout"  // ms
	BatchCapacity = "txpool.batch_capacity" // transaction

	// Block Pool
	MaxBlockSize = "blockpool.max_block_size"
)
View Source
const (
	HashLength    = 32
	AddressLength = 20
)

Variables

This section is empty.

Functions

func Bytes2Hex

func Bytes2Hex(d []byte) string

Bytes2Hex returns the hexadecimal encoding of d.

func Bytes2Uint

func Bytes2Uint(d []byte) uint64

func CopyBytes

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

CopyBytes returns an exact copy of the provided bytes.

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func GetLogger

func GetLogger(namespace string) *logging.Logger

func Hex

func Hex(b []byte) []byte

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func Hex2BytesFixed

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

Hex2BytesFixed returns bytes of a specified fixed length flen.

func LeftPadBytes

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

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

func RightPadBytes

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

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

func Uint2Bytes

func Uint2Bytes(v uint64) []byte

Types

type Address

type Address [AddressLength]byte

func BigToAddress

func BigToAddress(b *big.Int) Address

func BytesToAddress

func BytesToAddress(b []byte) Address

func CreateAddress

func CreateAddress(addr Address, nonce uint64) Address

func GenAddrByPrivkey

func GenAddrByPrivkey(key crypto.PrivKey) (Address, error)

Generate address by private key

func GenAddrByPubkey

func GenAddrByPubkey(key crypto.PubKey) (Address, error)

Generate address by public key

func HashToAddr

func HashToAddr(hash Hash) Address

func HexToAddress

func HexToAddress(d string) Address

Decode address in hex format to common.Address

func (Address) Big

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

func (Address) Bytes

func (addr Address) Bytes() []byte

func (Address) Hex

func (addr Address) Hex() string

func (Address) Nil

func (addr Address) Nil() bool

func (Address) String

func (addr Address) String() string

type Config

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

func NewConfig

func NewConfig(path string) *Config

func (*Config) Get

func (c *Config) Get(key string) interface{}

func (*Config) GetBool

func (c *Config) GetBool(key string) bool

func (*Config) GetDuration

func (c *Config) GetDuration(key string) time.Duration

func (*Config) GetInt

func (c *Config) GetInt(key string) int

func (*Config) GetInt64

func (c *Config) GetInt64(key string) int64

func (*Config) GetSlice

func (c *Config) GetSlice(key string) []string

func (*Config) GetString

func (c *Config) GetString(key string) string

type Hash

type Hash [HashLength]byte

func BigToHash

func BigToHash(b *big.Int) Hash

BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.

func BytesToHash

func BytesToHash(d []byte) Hash

func DecodeHash

func DecodeHash(data []byte) Hash

Decode hash string with "0x...." format to Hash type

func HexToHash

func HexToHash(s string) Hash

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func Sha256

func Sha256(d []byte) Hash

func (Hash) Big

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

func (Hash) Bytes

func (h Hash) Bytes() []byte

func (Hash) Hex

func (h Hash) Hex() string

func (Hash) Nil

func (h Hash) Nil() bool

func (Hash) String

func (h Hash) String() string

type Logger

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

type LoggerMgr

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

func NewLoggerMgr

func NewLoggerMgr() *LoggerMgr

func (*LoggerMgr) AddLogger

func (mgr *LoggerMgr) AddLogger(log *Logger)

func (*LoggerMgr) GetLogger

func (mgr *LoggerMgr) GetLogger(namespace string) *logging.Logger

type Protocol

type Protocol interface {
	// Typ should match the message type
	Type() string

	// Run func handles the message from the stream
	Run(pid peer.ID, message *pb.Message) error

	// Error func handles the error returned from the stream
	Error(error)
}

Protocol represents the callback handler

Directories

Path Synopsis
Package cache provides interface and implementation of a cache algorithms.
Package cache provides interface and implementation of a cache algorithms.

Jump to

Keyboard shortcuts

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