common

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: Apache-2.0 Imports: 18 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MaxSafeJSInt represents max value which JS support
	// It is used for smartContract fields
	// Our staking repo is written in JS, as are many other clients
	// If we use higher value JS will not be able to parse it
	MaxSafeJSInt = uint64(math.Pow(2, 53) - 2)

	IBFTImportantNotice = "***** IMPORTANT NOTICE: IBFT consensus protocol is about to be" +
		" removed from the Edge in the following release. *****\n" +
		"Please migrate to the PolyBFT protocol and plan your activities accordingly.\n" +
		"More information on how to execute the migration process can be found here" +
		"(https://wiki.polygon.technology/docs/edge/operate/ibft-to-polybft/)."
)

Functions

func BigIntDivCeil added in v0.8.0

func BigIntDivCeil(a, b *big.Int) *big.Int

BigIntDivCeil performs integer division and rounds given result to next bigger integer number It is calculated using this formula result = (a + b - 1) / b

func BigMin added in v0.9.0

func BigMin(x, y *big.Int) *big.Int

BigMin returns the smallest of x or y.

func ConvertUnmarshalledUint added in v0.8.0

func ConvertUnmarshalledUint(x interface{}) (uint64, error)

func CreateDirSafe added in v0.8.0

func CreateDirSafe(path string, perms fs.FileMode) error

Creates a directory at path and with perms level permissions. If directory already exists, owner and permissions are verified.

func DirectoryExists

func DirectoryExists(directoryPath string) bool

DirectoryExists checks if the directory at the specified path exists

func EncodeBigInt added in v1.1.1

func EncodeBigInt(b *big.Int) *string

func EncodeBytes added in v1.1.1

func EncodeBytes(b []byte) *string

func EncodeBytesToUint64 added in v0.8.0

func EncodeBytesToUint64(b []byte) uint64

EncodeBytesToUint64 big endian byte slice to uint64

func EncodeUint64 added in v1.1.1

func EncodeUint64(b uint64) *string

func EncodeUint64ToBytes added in v0.8.0

func EncodeUint64ToBytes(value uint64) []byte

EncodeUint64ToBytes encodes provided uint64 to big endian byte slice

func ExtendByteSlice added in v0.8.0

func ExtendByteSlice(b []byte, needLength int) []byte

ExtendByteSlice extends given byte slice by needLength parameter and trims it

func FileExists added in v0.8.0

func FileExists(filePath string) bool

Checks if the file at the specified path exists

func GetTerminationSignalCh

func GetTerminationSignalCh() <-chan os.Signal

GetTerminationSignalCh returns a channel to emit signals by ctrl + c

func IsContextDone added in v1.1.0

func IsContextDone(err error) bool

IsContextDone returns true if the error is due to the context being cancelled or expired. This is useful for determining if a function should retry.

func Max

func Max(a, b uint64) uint64

Max returns the strictly bigger number

func Min

func Min(a, b uint64) uint64

Min returns the strictly lower number

func PadLeftOrTrim added in v0.3.3

func PadLeftOrTrim(bb []byte, size int) []byte

PadLeftOrTrim left-pads the passed in byte array to the specified size, or trims the array if it exceeds the passed in size

func ParseBytes added in v1.1.1

func ParseBytes(val *string) ([]byte, error)

func ParseUint256orHex added in v1.1.1

func ParseUint256orHex(val *string) (*big.Int, error)

func ParseUint64orHex added in v0.9.0

func ParseUint64orHex(val *string) (uint64, error)

ParseUint64orHex parses the given uint64 hex string into the number. It can parse the string with 0x prefix as well.

func RetryForever added in v1.0.0

func RetryForever(ctx context.Context, interval time.Duration, fn func(context.Context) error)

RetryForever will execute a function until it completes without error or the context is cancelled or expired.

func SafeAddUint64 added in v1.3.2

func SafeAddUint64(a, b uint64) (uint64, bool)

SafeAddUint64 sums two unsigned int64 numbers if there is no overflow. In case there is an overflow, it would return 0 and true, otherwise sum and false.

func SaveFileSafe added in v0.8.0

func SaveFileSafe(path string, data []byte, perms fs.FileMode) error

Creates a file at path and with perms level permissions. If file already exists, owner and permissions are verified, and the file is overwritten.

func SetupDataDir

func SetupDataDir(dataDir string, paths []string, perms fs.FileMode) error

SetupDataDir sets up the data directory and the corresponding sub-directories

Types

type Duration added in v0.9.0

type Duration struct {
	time.Duration
}

Duration is a wrapper struct for time.Duration which implements json (un)marshaling

func (Duration) MarshalJSON added in v0.9.0

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON added in v0.9.0

func (d *Duration) UnmarshalJSON(b []byte) error

type JSONNumber added in v0.3.0

type JSONNumber struct {
	Value uint64
}

JSONNumber is the number represented in decimal or hex in json

func (*JSONNumber) MarshalJSON added in v0.3.0

func (d *JSONNumber) MarshalJSON() ([]byte, error)

func (*JSONNumber) UnmarshalJSON added in v0.3.0

func (d *JSONNumber) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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