common

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: Apache-2.0 Imports: 19 Imported by: 14

Documentation

Index

Constants

View Source
const (
	AddressIDBytes = 20
	AddressBytes   = AddressIDBytes + 1
)
View Source
const (
	TypeAddress = iota + codec.TypeCustom
	TypeInt
	TypeFloat
)
View Source
const PrefixLen = 4

Variables

View Source
var (
	ErrUnknown         = errors.ErrUnknown
	ErrIllegalArgument = errors.ErrIllegalArgument
	ErrInvalidState    = errors.ErrInvalidState
	ErrUnsupported     = errors.ErrUnsupported
	ErrNotFound        = errors.ErrNotFound
)
View Source
var (
	NullHashBytes  = make([]byte, crypto.HashLen)
	NullHashJSON   = []byte("\"0x" + hex.EncodeToString(NullHashBytes) + "\"")
	NullHashString = "0x" + hex.EncodeToString(NullHashBytes)
)
View Source
var HexIntZero = &hexIntZero
View Source
var TypeCodec = &typeCodec{}

Functions

func AddressEqual added in v0.9.4

func AddressEqual(a, b module.Address) bool

func AnyForJSON added in v0.9.4

func AnyForJSON(o interface{}) (interface{}, error)

func BlockInfoEqual added in v0.9.4

func BlockInfoEqual(bi1 module.BlockInfo, bi2 module.BlockInfo) bool

func BytesOfAddress added in v0.9.10

func BytesOfAddress(addr module.Address) []byte

func BytesToAddress added in v0.9.4

func BytesToAddress(b []byte) (module.Address, error)

func CompactJSON added in v0.9.4

func CompactJSON(js []byte) ([]byte, error)

func Compress

func Compress(bs []byte) []byte

func ConsensusInfoEqual added in v0.9.4

func ConsensusInfoEqual(csi1, csi2 module.ConsensusInfo) bool

func DecodeAny

func DecodeAny(o *codec.TypedObj) (interface{}, error)

func DecodeAnyForJSON

func DecodeAnyForJSON(o *codec.TypedObj) (interface{}, error)

func DecodeAsString

func DecodeAsString(o *codec.TypedObj, s string) string

func Decompress

func Decompress(bs []byte) []byte

func EncodeAny

func EncodeAny(obj interface{}) (*codec.TypedObj, error)

func HexPre

func HexPre(bs []byte) string

HexPre returns hexadecimal string of prefix of byte slice bs.

func MarshalAny

func MarshalAny(c codec.Codec, obj interface{}) ([]byte, error)

func MustDecodeAny

func MustDecodeAny(o *codec.TypedObj) interface{}

func MustEncodeAny

func MustEncodeAny(obj interface{}) *codec.TypedObj

func NewBlockInfo

func NewBlockInfo(height, timestamp int64) module.BlockInfo

func NewConsensusInfo added in v0.9.4

func NewConsensusInfo(
	proposer module.Address,
	voters module.ValidatorList,
	voted []bool,
) module.ConsensusInfo

func ParseHexBool added in v1.3.3

func ParseHexBool(s string) (bool, error)

func StrLeft

func StrLeft(n int, s string) string

func UnixMicroFromTime

func UnixMicroFromTime(t time.Time) int64

func UnmarshalAny

func UnmarshalAny(c codec.Codec, bs []byte) (interface{}, error)

Types

type Address

type Address [AddressBytes]byte

func AddressToPtr added in v0.9.3

func AddressToPtr(addr module.Address) *Address

func MustNewAddress added in v0.9.4

func MustNewAddress(b []byte) *Address

func MustNewAddressFromString added in v0.9.6

func MustNewAddressFromString(s string) *Address

func NewAccountAddress

func NewAccountAddress(b []byte) *Address

func NewAccountAddressFromPublicKey

func NewAccountAddressFromPublicKey(pubKey *crypto.PublicKey) *Address

func NewAddress

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

func NewAddressFromString

func NewAddressFromString(s string) (*Address, error)

func NewAddressWithTypeAndID added in v0.9.4

func NewAddressWithTypeAndID(isContract bool, id []byte) *Address

func NewContractAddress

func NewContractAddress(b []byte) *Address

func ToAddress added in v0.9.10

func ToAddress(addr interface{}) *Address

func (*Address) Bytes

func (a *Address) Bytes() []byte

func (*Address) Equal

func (a *Address) Equal(a2 module.Address) bool

func (*Address) ID

func (a *Address) ID() []byte

BytesPart returns part of address without type prefix.

func (*Address) IsContract

func (a *Address) IsContract() bool

func (Address) MarshalJSON

func (a Address) MarshalJSON() ([]byte, error)

func (*Address) RLPDecodeSelf

func (a *Address) RLPDecodeSelf(d codec.Decoder) error

func (*Address) RLPEncodeSelf

func (a *Address) RLPEncodeSelf(e codec.Encoder) error

func (*Address) Set added in v0.9.3

func (a *Address) Set(address module.Address) *Address

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte) error

func (*Address) SetString

func (a *Address) SetString(s string) error

func (*Address) SetStringStrict added in v0.9.6

func (a *Address) SetStringStrict(s string) error

func (*Address) SetTypeAndID

func (a *Address) SetTypeAndID(ic bool, id []byte)

func (*Address) String

func (a *Address) String() string

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(b []byte) error

type AutoCallLocker

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

func LockForAutoCall

func LockForAutoCall(locker sync.Locker) *AutoCallLocker

func (*AutoCallLocker) CallAfterUnlock

func (m *AutoCallLocker) CallAfterUnlock(f func())

CallAfterUnlock schedules to call f after next unlock. This function shall be called while lock is acquired.

func (*AutoCallLocker) CallBeforeUnlock

func (m *AutoCallLocker) CallBeforeUnlock(f func())

CallBeforeUnlock schedules to call f before next unlock. This function shall be called while lock is acquired.

func (*AutoCallLocker) Unlock

func (m *AutoCallLocker) Unlock()

Unlock calls scheduled functions and releases lock.

type AutoUnlock

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

func Lock

func Lock(l sync.Locker) AutoUnlock

Lock lock the locker and return handle for unlock to be used for deferred unlock.

func (*AutoUnlock) Unlock

func (l *AutoUnlock) Unlock()

type Clock

type Clock interface {
	Now() time.Time
	AfterFunc(d time.Duration, f func()) Timer
	NewTimer(d time.Duration) Timer
	Sleep(d time.Duration)
}

type GoTimeClock

type GoTimeClock struct {
}

func (*GoTimeClock) AfterFunc

func (cl *GoTimeClock) AfterFunc(d time.Duration, f func()) Timer

func (*GoTimeClock) NewTimer

func (cl *GoTimeClock) NewTimer(d time.Duration) Timer

func (*GoTimeClock) Now

func (cl *GoTimeClock) Now() time.Time

func (*GoTimeClock) Sleep

func (cl *GoTimeClock) Sleep(d time.Duration)

type HexBool added in v1.3.3

type HexBool struct {
	Value bool
}

func (*HexBool) MarshalJSON added in v1.3.3

func (i *HexBool) MarshalJSON() ([]byte, error)

func (*HexBool) RLPDecodeSelf added in v1.3.3

func (i *HexBool) RLPDecodeSelf(d codec.Decoder) error

func (*HexBool) RLPEncodeSelf added in v1.3.3

func (i *HexBool) RLPEncodeSelf(e codec.Encoder) error

func (*HexBool) String added in v1.3.3

func (i *HexBool) String() string

func (*HexBool) UnmarshalJSON added in v1.3.3

func (i *HexBool) UnmarshalJSON(b []byte) (err error)

type HexBytes

type HexBytes []byte

func SliceOfHexBytes

func SliceOfHexBytes(bss [][]byte) []HexBytes

func (HexBytes) Bytes

func (hs HexBytes) Bytes() []byte

func (HexBytes) MarshalJSON

func (hs HexBytes) MarshalJSON() ([]byte, error)

func (HexBytes) String

func (hs HexBytes) String() string

func (*HexBytes) UnmarshalJSON

func (hs *HexBytes) UnmarshalJSON(b []byte) error

type HexHash added in v0.9.6

type HexHash []byte

func (HexHash) Bytes added in v0.9.6

func (hs HexHash) Bytes() []byte

func (HexHash) MarshalJSON added in v0.9.6

func (hs HexHash) MarshalJSON() ([]byte, error)

func (HexHash) String added in v0.9.6

func (hs HexHash) String() string

func (*HexHash) UnmarshalJSON added in v0.9.6

func (hs *HexHash) UnmarshalJSON(b []byte) error

type HexInt

type HexInt struct {
	big.Int
}

func NewHexInt

func NewHexInt(v int64) *HexInt

func (*HexInt) AddValue added in v0.9.4

func (i *HexInt) AddValue(x, y *big.Int) *HexInt

func (*HexInt) Bytes

func (i *HexInt) Bytes() []byte

func (*HexInt) Clone

func (i *HexInt) Clone() HexInt

func (*HexInt) MarshalBinary

func (i *HexInt) MarshalBinary() (data []byte, err error)

func (HexInt) MarshalJSON

func (i HexInt) MarshalJSON() ([]byte, error)

func (*HexInt) SetBytes

func (i *HexInt) SetBytes(bs []byte) *big.Int

func (*HexInt) SetValue added in v0.9.4

func (i *HexInt) SetValue(x *big.Int) *HexInt

func (HexInt) String

func (i HexInt) String() string

func (*HexInt) UnmarshalBinary

func (i *HexInt) UnmarshalBinary(data []byte) error

func (*HexInt) UnmarshalJSON

func (i *HexInt) UnmarshalJSON(b []byte) error

func (*HexInt) Value added in v0.9.4

func (i *HexInt) Value() *big.Int

type HexInt16

type HexInt16 struct {
	Value int16
}

func (HexInt16) Bytes

func (i HexInt16) Bytes() []byte

func (HexInt16) MarshalJSON

func (i HexInt16) MarshalJSON() ([]byte, error)

func (*HexInt16) RLPDecodeSelf

func (i *HexInt16) RLPDecodeSelf(d codec.Decoder) error

func (*HexInt16) RLPEncodeSelf

func (i *HexInt16) RLPEncodeSelf(e codec.Encoder) error

func (HexInt16) String

func (i HexInt16) String() string

func (*HexInt16) UnmarshalJSON

func (i *HexInt16) UnmarshalJSON(b []byte) error

type HexInt32

type HexInt32 struct {
	Value int32
}

func (HexInt32) MarshalJSON

func (i HexInt32) MarshalJSON() ([]byte, error)

func (*HexInt32) RLPDecodeSelf

func (i *HexInt32) RLPDecodeSelf(d codec.Decoder) error

func (*HexInt32) RLPEncodeSelf

func (i *HexInt32) RLPEncodeSelf(e codec.Encoder) error

func (HexInt32) String

func (i HexInt32) String() string

func (*HexInt32) UnmarshalJSON

func (i *HexInt32) UnmarshalJSON(b []byte) error

type HexInt64

type HexInt64 struct {
	Value int64
}

func (HexInt64) MarshalJSON

func (i HexInt64) MarshalJSON() ([]byte, error)

func (*HexInt64) RLPDecodeSelf

func (i *HexInt64) RLPDecodeSelf(d codec.Decoder) error

func (*HexInt64) RLPEncodeSelf

func (i *HexInt64) RLPEncodeSelf(e codec.Encoder) error

func (HexInt64) String

func (i HexInt64) String() string

func (*HexInt64) UnmarshalJSON

func (i *HexInt64) UnmarshalJSON(b []byte) error

type HexUint16

type HexUint16 struct {
	Value uint16
}

func (HexUint16) Bytes

func (i HexUint16) Bytes() []byte

func (HexUint16) MarshalJSON

func (i HexUint16) MarshalJSON() ([]byte, error)

func (*HexUint16) RLPDecodeSelf

func (i *HexUint16) RLPDecodeSelf(d codec.Decoder) error

func (*HexUint16) RLPEncodeSelf

func (i *HexUint16) RLPEncodeSelf(e codec.Encoder) error

func (HexUint16) String

func (i HexUint16) String() string

func (*HexUint16) UnmarshalJSON

func (i *HexUint16) UnmarshalJSON(b []byte) error

type HexUint32

type HexUint32 struct {
	Value uint32
}

func (HexUint32) MarshalJSON

func (i HexUint32) MarshalJSON() ([]byte, error)

func (*HexUint32) RLPDecodeSelf

func (i *HexUint32) RLPDecodeSelf(d codec.Decoder) error

func (*HexUint32) RLPEncodeSelf

func (i *HexUint32) RLPEncodeSelf(e codec.Encoder) error

func (HexUint32) String

func (i HexUint32) String() string

func (*HexUint32) UnmarshalJSON

func (i *HexUint32) UnmarshalJSON(b []byte) error

type HexUint64

type HexUint64 struct {
	Value uint64
}

func (HexUint64) MarshalJSON

func (i HexUint64) MarshalJSON() ([]byte, error)

func (*HexUint64) RLPDecodeSelf

func (i *HexUint64) RLPDecodeSelf(d codec.Decoder) error

func (*HexUint64) RLPEncodeSelf

func (i *HexUint64) RLPEncodeSelf(e codec.Encoder) error

func (HexUint64) String

func (i HexUint64) String() string

func (*HexUint64) UnmarshalJSON

func (i *HexUint64) UnmarshalJSON(b []byte) error

type ITimer

type ITimer interface {
	Stop() bool
}

type Mutex

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

Mutex is wrapper for sync.Mutex.

func (*Mutex) CallAfterUnlock

func (m *Mutex) CallAfterUnlock(f func())

CallAfterUnlock schedules to call f after next unlock. This function shall be called while lock is acquired.

func (*Mutex) CallBeforeUnlock

func (m *Mutex) CallBeforeUnlock(f func())

CallBeforeUnlock schedules to call f before next unlock. This function shall be called while lock is acquired.

func (*Mutex) Lock

func (m *Mutex) Lock()

Lock acquires lock.

func (*Mutex) Unlock

func (m *Mutex) Unlock()

Unlock calls scheduled functions and releases lock.

type RawHexBytes

type RawHexBytes []byte

func (RawHexBytes) Bytes

func (rh RawHexBytes) Bytes() []byte

func (RawHexBytes) MarshalJSON

func (rh RawHexBytes) MarshalJSON() ([]byte, error)

func (RawHexBytes) String

func (rh RawHexBytes) String() string

func (*RawHexBytes) UnmarshalJSON

func (rh *RawHexBytes) UnmarshalJSON(b []byte) error

type Signature

type Signature struct {
	Signature *crypto.Signature
}

func (*Signature) MarshalBinary

func (sig *Signature) MarshalBinary() ([]byte, error)

func (Signature) MarshalJSON

func (sig Signature) MarshalJSON() ([]byte, error)

func (Signature) RecoverPublicKey

func (sig Signature) RecoverPublicKey(hash []byte) (*crypto.PublicKey, error)

func (*Signature) UnmarshalBinary

func (sig *Signature) UnmarshalBinary(s []byte) error

func (*Signature) UnmarshalJSON

func (sig *Signature) UnmarshalJSON(s []byte) error

type Timer

type Timer struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

func NewTimer added in v0.9.10

func NewTimer(itm ITimer) Timer

func NewTimerWithChan added in v0.9.10

func NewTimerWithChan(itm ITimer, c chan time.Time) Timer

func (*Timer) Stop

func (timer *Timer) Stop()

Directories

Path Synopsis
* Copyright 2020 ICON Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
* Copyright 2020 ICON Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.
Package errors is replacement package for standard errors package.
Package errors is replacement package for standard errors package.
Package lzw implements the Lempel-Ziv-Welch compressed data format, described in T. A. Welch, “A Technique for High-Performance Data Compression”, Computer, 17(6) (June 1984), pp 8-19.
Package lzw implements the Lempel-Ziv-Welch compressed data format, described in T. A. Welch, “A Technique for High-Performance Data Compression”, Computer, 17(6) (June 1984), pp 8-19.
mta

Jump to

Keyboard shortcuts

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