utils

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T constraints.Integer](x T) T

Abs provides a way of taking the absolute value of an integer

func AbsDiff

func AbsDiff[T constraints.Integer](x T, y T) T

AbsDiff provides a way of taking the absolute difference between two integers

func CheckContextDone

func CheckContextDone(ctx context.Context) bool

CheckContextDone checks if a provided context has indicated it is done, and returns a boolean indicating if it is.

func ConstrainIntegerToBitLength

func ConstrainIntegerToBitLength(b *big.Int, signed bool, bitLength int) *big.Int

ConstrainIntegerToBitLength takes a provided big integer, signed indicator, and bit length and ensures that the provided integer is represented in those bounds. In effect, this simulates overflow and underflow. Returns the constrained integer.

func ConstrainIntegerToBounds

func ConstrainIntegerToBounds(b *big.Int, min *big.Int, max *big.Int) *big.Int

ConstrainIntegerToBounds takes a provided big integer and minimum/maximum bounds (inclusive) and ensures that the provided integer is represented in those bounds. In effect, this simulates overflow and underflow. Returns the constrained integer.

func CopyChainConfig

func CopyChainConfig(config *params.ChainConfig) (*params.ChainConfig, error)

CopyChainConfig takes a chain configuration and creates a copy. Returns the copy of the chain configuration, or an error if one occurs.

func CopyDirectory

func CopyDirectory(sourcePath string, targetPath string, recursively bool) error

CopyDirectory copies a directory from a source path to a destination path. If recursively, all subdirectories will be copied. If not, only files within the directory will be copied. Returns an error if one occurs.

func CopyFile

func CopyFile(sourcePath string, targetPath string) error

CopyFile copies a file from a source path to a destination path. File permissions are retained. Returns an error if one occurs.

func CreateFile added in v0.1.1

func CreateFile(path string, fileName string) (*os.File, error)

CreateFile will create a file at the given path and file name combination. If the path is the empty string, the file will be created in the current working directory

func DeleteDirectory

func DeleteDirectory(directoryPath string) error

DeleteDirectory deletes a directory at the provided path. Returns an error if one occurred.

func GetFileNameWithoutExtension

func GetFileNameWithoutExtension(filePath string) string

GetFileNameWithoutExtension obtains a filename without the extension. This does not contain any preceding directory paths.

func GetFilePathWithoutExtension

func GetFilePathWithoutExtension(filePath string) string

GetFilePathWithoutExtension obtains a file path without the extension. This retains all preceding directory paths.

func GetIntegerConstraints

func GetIntegerConstraints(signed bool, bitLength int) (*big.Int, *big.Int)

GetIntegerConstraints takes a given signed indicator and bit length for a prospective integer and determines the minimum/maximum value boundaries. Returns the minimum and maximum value for the provided integer properties. Minimums and maximums are inclusive.

func GetPrivateKey added in v0.1.1

func GetPrivateKey(b []byte) (*ecdsa.PrivateKey, error)

GetPrivateKey will return a private key object given a byte slice. Only slices between lengths 1 and 32 (inclusive) are valid.

func HexStringToAddress

func HexStringToAddress(addressHexString string) (common.Address, error)

HexStringToAddress converts a hex string (with or without the "0x" prefix) to a common.Address. Returns the parsed address, or an error if one occurs during conversion.

func HexStringsToAddresses

func HexStringsToAddresses(addressHexStrings []string) ([]common.Address, error)

HexStringsToAddresses converts hex strings (with or without the "0x" prefix) to common.Address objects. Returns the parsed address, or an error if one occurs during conversion.

func IsLinuxEnvironment

func IsLinuxEnvironment() bool

IsLinuxEnvironment returns a boolean indicating whether the current execution environment is a Linux platform.

func IsMacOSEnvironment

func IsMacOSEnvironment() bool

IsMacOSEnvironment returns a boolean indicating whether the current execution environment is a macOS platform.

func IsWindowsEnvironment

func IsWindowsEnvironment() bool

IsWindowsEnvironment returns a boolean indicating whether the current execution environment is a Windows platform.

func MakeDirectory

func MakeDirectory(dirToMake string) error

MakeDirectory creates a directory at the given path, including any parent directories which do not exist. Returns an error, if one occurred.

func Max

func Max[T constraints.Ordered](x T, y T) T

Max provides generic support for various integer types to be compared and the maximum of two values returned. Returns the maximum of the two values provided.

func MessageToTransaction

func MessageToTransaction(msg *core.Message) *types.Transaction

MessageToTransaction derives a types.Transaction from a types.Message.

func Min

func Min[T constraints.Ordered](x T, y T) T

Min provides generic support for various integer types to be compared and the minimum of two values returned. Returns the minimum of the two values provided.

func PermutationsWithRepetition added in v0.1.2

func PermutationsWithRepetition[T any](choices []T, n int) [][]T

PermutationsWithRepetition will take in an array and an integer, n, where n represents how many items need to be selected from the array. The function returns an array of all permutations of size n

func RunCommandWithOutputAndError

func RunCommandWithOutputAndError(command *exec.Cmd) ([]byte, []byte, []byte, error)

RunCommandWithOutputAndError runs a given exec.Cmd and returns the stdout, stderr, and combined output as bytes, or an error if one occurred.

func SlicePointersToValues

func SlicePointersToValues[T any](x []*T) []T

SlicePointersToValues takes a slice of pointers and returns a slice of values de-referenced from them.

func SliceSelect

func SliceSelect[T any, K any](x []T, f func(x T) K) []K

SliceSelect provides a way of querying a specific element from a slice's elements into a slice of its own.

func SliceValuesToPointers

func SliceValuesToPointers[T any](x []T) []*T

SliceValuesToPointers takes a slice of values and returns a slice of pointers to them.

func SliceWhere

func SliceWhere[T any](x []T, f func(x T) bool) []T

SliceWhere provides a way of querying specific elements which fit some criteria into a new slice.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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