utils

package
v2.0.0-dev2.0...-efbdfda Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: GPL-3.0 Imports: 20 Imported by: 13

Documentation

Index

Constants

View Source
const (
	NoRestartFlag string = "no-restart"
	MnemonicFlag  string = "mnemonic"
)

Variables

View Source
var (
	YesFlag *cli.BoolFlag = &cli.BoolFlag{
		Name:    "yes",
		Aliases: []string{"y"},
		Usage:   "Automatically confirm all interactive questions",
	}
	PrintTxDataFlag *cli.BoolFlag = &cli.BoolFlag{
		Name:    "print-tx-data",
		Aliases: []string{"pt"},
		Usage:   "Print the TX data for transactions without signing or submitting them. Useful for masquerade mode or offline wallet operations.",
	}
	SignTxOnlyFlag *cli.BoolFlag = &cli.BoolFlag{
		Name:    "sign-tx-only",
		Aliases: []string{"st"},
		Usage:   "Sign any TXs and print the results, but don't submit it to the network. Useful if you want to save a TX for later or bundle it up with a service like Flashbots.",
	}
	RawFlag *cli.BoolFlag = &cli.BoolFlag{
		Name: "raw",
	}
	ComposeFileFlag *cli.StringSliceFlag = &cli.StringSliceFlag{
		Name:    "compose-file",
		Aliases: []string{"f"},
		Usage:   "Supplemental Docker compose files for custom containers to include when performing service commands such as 'start' and 'stop'; this flag may be defined multiple times",
	}
)

Functions

func Confirm

func Confirm(initialPrompt string) bool

Prompt for confirmation

func ConfirmSecureSession

func ConfirmSecureSession(warning string) bool

Prompts the user to verify that there is nobody looking over their shoulder before printing sensitive information.

func ConfirmWithIAgree

func ConfirmWithIAgree(initialPrompt string) bool

Prompt for 'I agree' confirmation (used on important questions to avoid a quick 'y' response from the user)

func CreateBlockCountSetter

func CreateBlockCountSetter[SettingNameType any](
	name string,
	alias string,
	contractName rocketpool.ContractName,
	settingName SettingNameType,
	runner func(c *cli.Context, contractName rocketpool.ContractName, settingName SettingNameType, value uint64) error,
) *cli.Command

Creates a command to propose a new setting that takes an integer value (number of blocks)

func CreateBoolSetter

func CreateBoolSetter[SettingNameType any](
	name string,
	alias string,
	contractName rocketpool.ContractName,
	settingName SettingNameType,
	runner func(c *cli.Context, contractName rocketpool.ContractName, settingName SettingNameType, value bool) error,
) *cli.Command

Creates a command to propose a new setting that takes a percentage value

func CreateDurationSetter

func CreateDurationSetter[SettingNameType any](
	name string,
	alias string,
	contractName rocketpool.ContractName,
	settingName SettingNameType,
	runner func(c *cli.Context, contractName rocketpool.ContractName, settingName SettingNameType, value time.Duration) error,
) *cli.Command

Creates a command to propose a new setting that takes a time.Duration value

func CreateEthSetter

func CreateEthSetter[SettingNameType any](
	name string,
	alias string,
	contractName rocketpool.ContractName,
	settingName SettingNameType,
	runner func(c *cli.Context, contractName rocketpool.ContractName, settingName SettingNameType, value *big.Int) error,
) *cli.Command

Creates a command to propose a new setting that takes an ETH value

func CreatePercentSetter

func CreatePercentSetter[SettingNameType any](
	name string,
	alias string,
	contractName rocketpool.ContractName,
	settingName SettingNameType,
	runner func(c *cli.Context, contractName rocketpool.ContractName, settingName SettingNameType, value *big.Int) error,
) *cli.Command

Creates a command to propose a new setting that takes a percentage value

func CreateRplSetter

func CreateRplSetter[SettingNameType any](
	name string,
	alias string,
	contractName rocketpool.ContractName,
	settingName SettingNameType,
	runner func(c *cli.Context, contractName rocketpool.ContractName, settingName SettingNameType, value *big.Int) error,
) *cli.Command

Creates a command to propose a new setting that takes an RPL value

func CreateSetterCategory

func CreateSetterCategory(name string, formalName string, alias string, contract rocketpool.ContractName) *cli.Command

Creates a command that acts as a category container for individual setter subcommands

func CreateUintSetter

func CreateUintSetter[SettingNameType any](
	name string,
	alias string,
	contractName rocketpool.ContractName,
	settingName SettingNameType,
	runner func(c *cli.Context, contractName rocketpool.ContractName, settingName SettingNameType, value uint64) error,
) *cli.Command

Creates a command to propose a new setting that takes an unsigned integer value

func CreateUnboundedPercentSetter

func CreateUnboundedPercentSetter[SettingNameType any](
	name string,
	alias string,
	contractName rocketpool.ContractName,
	settingName SettingNameType,
	runner func(c *cli.Context, contractName rocketpool.ContractName, settingName SettingNameType, value *big.Int) error,
) *cli.Command

Creates a command to propose a new setting that takes a percentage value but can go over 100%

func GetDateTimeString

func GetDateTimeString(dateTime uint64) string

Convert a Unix datetime to a string, or `---` if it's zero

func GetDateTimeStringOfTime

func GetDateTimeStringOfTime(dateTime time.Time) string

Convert a Unix datetime to a string, or `---` if it's zero

func GetMultiselectIndices

func GetMultiselectIndices[DataType any](c *cli.Context, flagName string, options []SelectionOption[DataType], prompt string) ([]*DataType, error)

Get the list of elements the user wants to use for a multi-select operation

func GetPrettyAddress

func GetPrettyAddress(address common.Address) string

Gets the hex string of an address, or "none" if it was the 0x0 address

func InstantiateFlag

func InstantiateFlag[FlagType cli.Flag](prototype FlagType, description string) cli.Flag

func ParseFloat

func ParseFloat(c *cli.Context, name string, value string, isFraction bool) (*big.Int, error)

Parses a string representing either a floating point value or a raw wei amount into a *big.Int

func PrettyPrintError

func PrettyPrintError(err error)

Prints an error in a prettier format, removing the "stack trace" if it represents a contract revert message

func PrintDepositMismatchError

func PrintDepositMismatchError(rpNetwork, beaconNetwork uint64, rpDepositAddress, beaconDepositAddress common.Address)

Prints an error message when the Beacon client is not using the deposit contract address that Rocket Pool expects

func PrintMultiTransactionNonceWarning

func PrintMultiTransactionNonceWarning()

Print a warning to the console if the user set a custom nonce, but this operation involves multiple transactions

func PrintNetwork

func PrintNetwork(currentNetwork config.Network, isNew bool) error

Prints what network you're currently on

func PrintTransactionBatchHashes

func PrintTransactionBatchHashes(rp *client.Client, hashes []common.Hash)

Print a batch of transaction hashes to the console.

func PrintTransactionHash

func PrintTransactionHash(rp *client.Client, hash common.Hash)

Print a TX's details to the console.

func PrintTransactionHashNoCancel

func PrintTransactionHashNoCancel(rp *client.Client, hash common.Hash)

Print a TX's details to the console, but inform the user NOT to cancel it.

func Prompt

func Prompt(initialPrompt string, expectedFormat string, incorrectFormatPrompt string) string

Prompt for user input

func PromptPassword

func PromptPassword(initialPrompt string, expectedFormat string, incorrectFormatPrompt string) string

Prompt for password input

func Select

func Select(initialPrompt string, options []string) (int, string)

Prompt for user selection

Types

type SelectionOption

type SelectionOption[DataType any] struct {
	// The underlying element this option represents
	Element *DataType

	// The human-readable ID of the option, used for non-interactive selection
	ID string

	// The text to display for this option when listing the available options
	Display string
}

An option that can be selected from a list of choices in the CLI

type SettingType

type SettingType interface {
	bool | *big.Int | uint64 | time.Duration
}

Valid types for setting values

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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