common

package
v0.0.0-...-376a440 Latest Latest
Warning

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

Go to latest
Published: May 10, 2020 License: LGPL-3.0 Imports: 14 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 Base58Decode

func Base58Decode(s string) []byte

Base58Decode ...

func Base58Encode

func Base58Encode(raw []byte) string

Base58Encode ...

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 IsWitness

func IsWitness(w string, witnessList []string) bool

IsWitness will judage if a public key is a witness.

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 Ripemd160

func Ripemd160(raw []byte) []byte

Ripemd160 ...

func SetMode

func SetMode(m ModeType)

SetMode will set the mode of iserver.

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 UnifyDecimal

func UnifyDecimal(a *Fixed, b *Fixed) (*Fixed, *Fixed, error)

UnifyDecimal make two fix point number have same decimal.

func WitnessOfNanoSec

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

WitnessOfNanoSec will return which witness is the current time.

Types

type Fixed

type Fixed struct {
	Value   int64
	Decimal int
	Err     error
}

Fixed implements fixed point number for user of token balance

func NewFixed

func NewFixed(amount string, decimal int) (*Fixed, error)

NewFixed generate Fixed from string and decimal, will truncate if decimal is smaller. Decimal < 0 means auto detecting decimal

func UnmarshalFixed

func UnmarshalFixed(s string) (*Fixed, error)

UnmarshalFixed unmarshal from string

func (*Fixed) Add

func (f *Fixed) Add(other *Fixed) *Fixed

Add ...

func (*Fixed) BiggerThan

func (f *Fixed) BiggerThan(other *Fixed) bool

BiggerThan ...

func (*Fixed) ChangeDecimal

func (f *Fixed) ChangeDecimal(targetDecimal int) *Fixed

ChangeDecimal change decimal to give decimal, without changing its real value

func (*Fixed) Div

func (f *Fixed) Div(i int64) *Fixed

Div divide by a scalar

func (*Fixed) Equals

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

Equals check equal

func (*Fixed) IsNegative

func (f *Fixed) IsNegative() bool

IsNegative ...

func (*Fixed) IsPositive

func (f *Fixed) IsPositive() bool

IsPositive ...

func (*Fixed) IsZero

func (f *Fixed) IsZero() bool

IsZero checks whether the value is zero

func (*Fixed) LessThan

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

LessThan ...

func (*Fixed) Marshal

func (f *Fixed) Marshal() string

Marshal ...

func (*Fixed) Multiply

func (f *Fixed) Multiply(other *Fixed) *Fixed

Multiply ...

func (*Fixed) Neg

func (f *Fixed) Neg() *Fixed

Neg get negative number

func (*Fixed) ShrinkDecimal

func (f *Fixed) ShrinkDecimal() *Fixed

ShrinkDecimal remove trailing 0s

func (*Fixed) Sub

func (f *Fixed) Sub(other *Fixed) *Fixed

Sub ...

func (*Fixed) Times

func (f *Fixed) Times(i int64) *Fixed

Times multiply a int scalar

func (*Fixed) TimesF

func (f *Fixed) TimesF(v float64) *Fixed

TimesF multiply a float scalar

func (*Fixed) ToFloat

func (f *Fixed) ToFloat() float64

ToFloat ...

func (*Fixed) ToString

func (f *Fixed) ToString() string

ToString generate string of Fixed without post zero

func (*Fixed) ToStringWithDecimal

func (f *Fixed) ToStringWithDecimal() string

ToStringWithDecimal convert to string with tailing 0s

type ModeType

type ModeType uint

ModeType is the type of mode.

const (
	ModeNormal ModeType = iota
	ModeSync
	ModeInit
)

Constant of mode type.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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