package
2.21.1-hedera-beta.0
Repository: https://github.com/smartcontractkit/chainlink.git
Documentation: pkg.go.dev

# README

package utils

StartStopOnce

stateDiagram-v2
    [*] --> Unstarted
    Unstarted --> Starting : StartOnce()
    Starting --> StartFailed
    Starting --> Started
    Started --> Stopping : StopOnce()
    Stopping --> Stopped
    Stopping --> StopFailed
    StartFailed --> [*]
    Stopped --> [*]
    StopFailed --> [*]

# Packages

Package bigmath compensates for awkward big.Int API.

# Functions

AddHexPrefix adds the prefix (0x) to a given hex string.
BatchSplit splits an slices into an slices of slicess with a maximum length.
BytesToHash sets b to hash.
CheckPasswordHash wraps around bcrypt.CompareHashAndPassword for a friendlier API.
ConcatBytes appends a bunch of byte arrays into a single byte array.
ContextFromChan creates a context that finishes when the provided channel receives or is closed.
ContextFromChanWithTimeout creates a context with a timeout that finishes when the provided channel receives or is closed.
DeleteUnstable destructively removes slice element at index i It does no bounds checking and may re-order the slice.
DurationFromNow returns the amount of time since the Time field was last updated.
EnsureDirAndMaxPerms ensures that the given path exists, that it's a directory, and that it has permissions that are no more permissive than the given ones.
EnsureFileMaxPerms ensures that the given file has permissions that are no more permissive than the given ones.
EnsureFilepathMaxPerms ensures that the file at the given filepath has permissions that are no more permissive than the given ones.
FileExists returns true if a file at the passed string exists.
FiniteTicker starts a goroutine to execute the given function periodically, until the returned function is called.
FormatJSON applies indent to format a JSON response.
GetScryptParams fetches ScryptParams from a ScryptConfigReader.
HashPassword wraps around bcrypt.GenerateFromPassword for a friendlier API.
IsEmpty returns true if bytes contains only zero values, or has len 0.
IsFileOwnedByChainlink attempts to read fileInfo to verify file owner.
ISO8601UTC formats given time to ISO8601.
MustUnmarshalToMap performs UnmarshalToMap, panics upon failure.
NewBackoffTicker returns a new BackoffTicker for the given range.
NewBoundedPriorityQueue creates a new BoundedPriorityQueue.
NewBoundedQueue creates a new BoundedQueue instance.
NewBytes32ID returns a randomly generated UUID that conforms to Ethereum bytes32.
NewCronTicker returns a new CrontTicker for the given schedule.
NewDBBackoff is a standard backoff to use for database connection issues.
NewDeferableWriteCloser creates a deferable writercloser.
NewPausableTicker creates a new PausableTicker.
NewRedialBackoff is a standard backoff to use for redialling or reconnecting to unreachable network endpoints.
NewResettableTimer creates a new ResettableTimer.
NewSecret returns a new securely random sequence of n bytes of entropy.
NormalizedJSON returns a JSON representation of an object that has been normalized to produce a consistent output for hashing.
Sha256 returns a hexadecimal encoded string of a hashed input.
StringToHex converts a standard string to a hex encoded string.
ToDecimal converts an input to a decimal TODO: Currently this function does not handle hex string as the input.
TooPermissive checks if the file has more than the allowed permissions.
UnmarshalToMap takes an input json string and returns a map[string]interface i.e.
UnwrapError returns a list of underlying errors if passed error implements joinedError or return the err in a single-element list otherwise.
ValidateCronSchedule returns an error if the given schedule is invalid.
WithCloseChan wraps a context so that it is canceled if the passed in channel is closed.
WithJitter adds +/- 10% to a duration.
WriteFileWithMaxPerms writes `data` to `path` and ensures that the file has permissions that are no more permissive than the given ones.

# Constants

DefaultSecretSize is the entropy in bytes to generate a base64 string of 64 characters.
FastN is a shorter N parameter for testing.
FastP is a shorter P parameter for testing.
PasswordComplexityRequirements defines the complexity requirements message Note that adding an entropy requirement wouldn't add much, since a 16 character password already has an entropy score of 75 even if it's all lowercase characters.

# Variables

DefaultScryptParams is for use in production.
FastScryptParams is for use in tests, where you don't want to wear out your CPU with expensive key derivations, do not use it in production, or your encrypted keys will be easy to brute-force!.

# Structs

BackoffTicker sends ticks with periods that increase over time, over a configured range.
BoundedPriorityQueue stores a series of BoundedQueues with associated priorities and capacities.
BoundedQueue is a FIFO queue that discards older items when it reaches its capacity.
CronTicker is like a time.Ticker but for a cron schedule.
DeferableWriteCloser is to be used in leiu of defer'ing Close on an [io.WriteCloser] (// For more background see https://www.joeshaw.org/dont-defer-close-on-writable-files/) Callers should *both* explicitly call Close and check for errors when done with the underlying writerclose *and* defer the Close() to handle returns before the explicit close For example rather than import "os" f, err := os.Create("./foo") if err != nil { return err} defer f.Close() return f.Write([]bytes("hi")) do import "os" f, err := os.Create("./foo") if err != nil {return nil} wc := NewDeferableWriteCloser(f) defer wc.Close() err = wc.Write([]bytes("hi")) if err != nil {return err} return wc.Close().
ErrorBuffer uses joinedErrors interface to join multiple errors into a single error.
KeyedMutex allows to lock based on particular values.
PausableTicker stores a ticker with a duration.
ResettableTimer stores a timer.

# Interfaces

ThreadControl is a helper for managing a group of goroutines.
TickerBase is an interface for pausable tickers.

# Type aliases

FileSize repesents a file size in bytes.
Hash is a simplified version of go-ethereum's common.Hash to avoid go-ethereum dependency It represents a 32 byte fixed size array that marshals/unmarshals assuming a 0x prefix.
PlainHexBytes marshals/unmarshals as a JSON string without a 0x prefix.
StartStopOnce contains a StartStopOnceState integer Deprecated: use services.StateMachine.
Deprecated: use services.StopChan.
Deprecated: use services.StopRChan.