common

package
v3.11.4 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: LGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxBlockGasLimit  = int64(800000000)
	MaxTxTimeLimit    = 200 * time.Millisecond
	MaxBlockTimeLimit = 400 * time.Millisecond
)

Constant of limit

View Source
var (
	VoteInterval       = int64(1200)
	SlotInterval       = 3 * time.Second
	BlockInterval      = 500 * time.Millisecond
	BlockNumPerWitness = 6
)

Witness

Functions

func AppendIfNotExists added in v3.7.0

func AppendIfNotExists(arr *[]string, elem string)

func Base58Decode

func Base58Decode(s string) []byte

Base58Decode ...

func Base58Encode

func Base58Encode(raw []byte) string

Base58Encode ...

func BelongsTo added in v3.7.0

func BelongsTo(elem string, arr []string) bool

BelongsTo will judage if a public key is a witness.

func BytesToInt32

func BytesToInt32(b []byte) int32

BytesToInt32 converts byte slice to int32.

func BytesToInt64

func BytesToInt64(b []byte) int64

BytesToInt64 converts byte slice to int64.

func Int32ToBytes

func Int32ToBytes(n int32) []byte

Int32ToBytes converts int32 to byte slice.

func Int64ToBytes

func Int64ToBytes(n int64) []byte

Int64ToBytes converts int64 to byte slice.

func LoadYamlAsViper

func LoadYamlAsViper(configfile string) *viper.Viper

LoadYamlAsViper load yaml file as viper object

func Mode

func Mode() string

Mode will return the mode of iserver.

func NextSlot

func NextSlot() int64

NextSlot will return the slot number in the next slot.

func Parity

func Parity(bit []byte) []byte

Parity ...

func ParseHex

func ParseHex(s string) []byte

ParseHex ...

func RescalePair added in v3.7.1

func RescalePair(a *Decimal, b *Decimal) (*Decimal, *Decimal, error)

RescalePair make two decimal number have same scale.

func Ripemd160

func Ripemd160(raw []byte) []byte

Ripemd160 ...

func SetMode

func SetMode(m ModeType)

SetMode will set the mode of iserver.

func Sha256

func Sha256(raw []byte) []byte

Sha256 ...

func Sha3

func Sha3(raw []byte) []byte

Sha3 ...

func SlotOfUnixNano

func SlotOfUnixNano(unixnano int64) int64

SlotOfUnixNano will return the slot number of unixnano.

func StringSliceEqual

func StringSliceEqual(a, b []string) bool

StringSliceEqual is compare two strings

func TimeOfBlock

func TimeOfBlock(slot int64, num int64) time.Time

TimeOfBlock will return the block time for specific slots and num.

func ToHex

func ToHex(data []byte) string

ToHex ...

func WitnessIndexOfNanoSec added in v3.9.2

func WitnessIndexOfNanoSec(nanosec int64, witnessList []string) int64

WitnessOfNanoSec will return which witness is the current time.

func WitnessOfNanoSec

func WitnessOfNanoSec(nanosec int64, witnessList []string) string

WitnessOfNanoSec will return which witness is the current time.

Types

type ACCConfig

type ACCConfig struct {
	ID        string
	SecKey    string
	Algorithm string
}

ACCConfig account of the system

type Config

type Config struct {
	ACC      *ACCConfig
	Genesis  string
	VM       *VMConfig
	DB       *DBConfig
	Snapshot *SnapshotConfig
	P2P      *P2PConfig
	RPC      *RPCConfig
	Log      *LogConfig
	Metrics  *MetricsConfig
	Debug    *DebugConfig
	Version  *VersionConfig
	SPV      *SPVConfig
	Stop     int64
}

Config provide all configuration for the application

func NewConfig

func NewConfig(configfile string) *Config

NewConfig returns a new instance of Config

func (*Config) YamlString

func (c *Config) YamlString() string

YamlString config to string

type ConsoleLogConfig

type ConsoleLogConfig struct {
	Level  string
	Enable bool
}

ConsoleLogConfig is the config for consolewriter of ilog.

type DBConfig

type DBConfig struct {
	LdbPath string
}

DBConfig config of the database

type DebugConfig

type DebugConfig struct {
	ListenAddr string
}

DebugConfig is the config of debug.

type Decimal added in v3.7.1

type Decimal struct {
	Value int64
	Scale int
	Err   error
}

Decimal implements decimal number for use of token balance

func NewDecimalExp10 added in v3.7.1

func NewDecimalExp10(i int) *Decimal

func NewDecimalFromInt added in v3.7.1

func NewDecimalFromInt(v int) *Decimal

func NewDecimalFromIntWithScale added in v3.7.1

func NewDecimalFromIntWithScale(v int, s int) *Decimal

func NewDecimalFromString added in v3.7.1

func NewDecimalFromString(amount string, scale int) (*Decimal, error)

NewDecimalFromString generate Decimal from string and scale, will truncate if scale is smaller. scale < 0 means auto detecting scale

func NewDecimalZero added in v3.8.5

func NewDecimalZero() *Decimal

func UnmarshalDecimal added in v3.7.1

func UnmarshalDecimal(s string) (*Decimal, error)

UnmarshalDecimal unmarshal from string

func (*Decimal) Add added in v3.7.1

func (f *Decimal) Add(other *Decimal) *Decimal

Add ...

func (*Decimal) DivInt added in v3.7.1

func (f *Decimal) DivInt(i int64) *Decimal

DivInt divide by a scalar

func (*Decimal) Equals added in v3.7.1

func (f *Decimal) Equals(other *Decimal) bool

Equals check equal

func (*Decimal) Float64 added in v3.7.1

func (f *Decimal) Float64() float64

Float64 ...

func (*Decimal) FloorInt added in v3.7.1

func (f *Decimal) FloorInt() int64

func (*Decimal) GreaterThan added in v3.7.1

func (f *Decimal) GreaterThan(other *Decimal) bool

GreaterThan ...

func (*Decimal) IsNegative added in v3.7.1

func (f *Decimal) IsNegative() bool

IsNegative ...

func (*Decimal) IsPositive added in v3.7.1

func (f *Decimal) IsPositive() bool

IsPositive ...

func (*Decimal) IsZero added in v3.7.1

func (f *Decimal) IsZero() bool

IsZero checks whether the value is zero

func (*Decimal) LessThan added in v3.7.1

func (f *Decimal) LessThan(other *Decimal) bool

LessThan ...

func (*Decimal) Marshal added in v3.7.1

func (f *Decimal) Marshal() string

Marshal ...

func (*Decimal) Mul added in v3.7.1

func (f *Decimal) Mul(other *Decimal) *Decimal

Mul ...

func (*Decimal) MulFloat added in v3.7.1

func (f *Decimal) MulFloat(v float64) *Decimal

MulFloat multiply a float

func (*Decimal) MulInt added in v3.7.1

func (f *Decimal) MulInt(i int64) *Decimal

MulInt multiply a int

func (*Decimal) Neg added in v3.7.1

func (f *Decimal) Neg() *Decimal

Neg get negative number

func (*Decimal) Rescale added in v3.7.1

func (f *Decimal) Rescale(targetScale int) *Decimal

Rescale change scale to given scale, without changing its real value

func (*Decimal) ShrinkScale added in v3.7.1

func (f *Decimal) ShrinkScale() *Decimal

ShrinkScale remove trailing 0s

func (*Decimal) String added in v3.7.1

func (f *Decimal) String() string

String generate string of Decimal without post zero

func (*Decimal) Sub added in v3.7.1

func (f *Decimal) Sub(other *Decimal) *Decimal

Sub ...

func (*Decimal) ToStringWithFullScale added in v3.7.1

func (f *Decimal) ToStringWithFullScale() string

ToStringWithFullScale convert to string with tailing 0s

type FileLogConfig

type FileLogConfig struct {
	Path   string
	Level  string
	Enable bool
}

FileLogConfig is the config for filewriter of ilog.

type GenesisConfig

type GenesisConfig struct {
	CreateGenesis    bool
	InitialTimestamp string
	TokenInfo        *TokenInfo
	WitnessInfo      []*Witness
	ContractPath     string
	AdminInfo        *Witness
	FoundationInfo   *Witness
}

GenesisConfig config of the genesis bloc

type LogConfig

type LogConfig struct {
	FileLog           *FileLogConfig
	ConsoleLog        *ConsoleLogConfig
	AsyncWrite        bool
	EnableContractLog bool
}

LogConfig is the config of ilog.

type MetricsConfig

type MetricsConfig struct {
	PushAddr string
	Username string
	Password string
	Enable   bool
	ID       string
}

MetricsConfig is the config of metrics.

type ModeType

type ModeType uint

ModeType is the type of mode.

const (
	ModeNormal ModeType = iota
	ModeSync
	ModeInit
)

Constant of mode type.

type P2PConfig

type P2PConfig struct {
	ListenAddr   string
	SeedNodes    []string
	ChainID      uint32
	Version      uint16
	DataPath     string
	InboundConn  int
	OutboundConn int
	BlackPID     []string
	BlackIP      []string
	AdminPort    string
	DisableMplex bool
}

P2PConfig is the config for p2p network.

type RPCConfig

type RPCConfig struct {
	Enable       bool
	GatewayAddr  string
	GRPCAddr     string
	AllowOrigins []string
	TryTx        bool
	ExecTx       bool
}

RPCConfig is the config for RPC Server.

type SPVConfig

type SPVConfig struct {
	IsSPV         bool
	SyncFromBlock int64
	SeedServer    string
}

type SimpleDecoder

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

SimpleDecoder is a simple decoder used to convert bytes to other types. Not used now!!!

func NewSimpleDecoder

func NewSimpleDecoder(input []byte) *SimpleDecoder

NewSimpleDecoder returns a new SimpleDecoder instance.

func (*SimpleDecoder) ParseByte

func (sd *SimpleDecoder) ParseByte() (byte, error)

ParseByte parse input, return first byte

func (*SimpleDecoder) ParseBytes

func (sd *SimpleDecoder) ParseBytes() ([]byte, error)

ParseBytes parse input, return first byte array

func (*SimpleDecoder) ParseInt32

func (sd *SimpleDecoder) ParseInt32() (int32, error)

ParseInt32 parse input, return first int32

type SimpleEncoder

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

SimpleEncoder is a simple encoder used to convert struct to bytes.

func NewSimpleEncoder

func NewSimpleEncoder() *SimpleEncoder

NewSimpleEncoder returns a new SimpleEncoder instance.

func (*SimpleEncoder) Bytes

func (se *SimpleEncoder) Bytes() []byte

Bytes returns the result bytes of buffer.

func (*SimpleEncoder) Reset

func (se *SimpleEncoder) Reset()

Reset resets the buffer.

func (*SimpleEncoder) WriteByte

func (se *SimpleEncoder) WriteByte(b byte)

WriteByte writes a byte to buffer.

func (*SimpleEncoder) WriteBytes

func (se *SimpleEncoder) WriteBytes(bs []byte)

WriteBytes writes a byte slice to buffer.

func (*SimpleEncoder) WriteBytesSlice

func (se *SimpleEncoder) WriteBytesSlice(p [][]byte)

WriteBytesSlice writes a bytes slice to buffer.

func (*SimpleEncoder) WriteInt32

func (se *SimpleEncoder) WriteInt32(i int32)

WriteInt32 writes a int32 to buffer.

func (*SimpleEncoder) WriteInt64

func (se *SimpleEncoder) WriteInt64(i int64)

WriteInt64 writes a int64 to buffer.

func (*SimpleEncoder) WriteMapStringToI64

func (se *SimpleEncoder) WriteMapStringToI64(m map[string]int64)

WriteMapStringToI64 writes a map[string]int64 to buffer.

func (*SimpleEncoder) WriteString

func (se *SimpleEncoder) WriteString(s string)

WriteString writes a string to buffer.

func (*SimpleEncoder) WriteStringSlice

func (se *SimpleEncoder) WriteStringSlice(p []string)

WriteStringSlice writes a string slice to buffer.

type SnapshotConfig

type SnapshotConfig struct {
	Enable   bool
	FilePath string
}

SnapshotConfig is the config of snapshot

type TokenInfo

type TokenInfo struct {
	FoundationAccount string
	IOSTTotalSupply   int64
	IOSTDecimal       int64
}

TokenInfo config of the genesis block

type VMConfig

type VMConfig struct {
	JsPath   string
	LogLevel string
}

VMConfig config of the v8vm

type VersionConfig

type VersionConfig struct {
	NetName         string
	ProtocolVersion string
}

VersionConfig contrains netname(mainnet / testnet etc) and protocol info

type Witness

type Witness struct {
	ID             string
	Owner          string
	Active         string
	SignatureBlock string
	Balance        int64
}

Witness config of the genesis block

Jump to

Keyboard shortcuts

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