common

package
v0.18.5 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMarker = " (*)"

Variables

View Source
var (
	// HeightFlag is the flag for specifying block height.
	HeightFlag *flag.FlagSet

	// ForceFlag is a force mode switch.
	ForceFlag *flag.FlagSet

	// AnswerYesFlag answers yes to all questions.
	AnswerYesFlag *flag.FlagSet

	// FormatFlag specifies the command's output format (text/json).
	FormatFlag *flag.FlagSet

	// VerboseFlag specifies the command's verbosity.
	VerboseFlag *flag.FlagSet
)
View Source
var (
	// PromptPassphrase is the standard passphrase prompt.
	PromptPassphrase = &survey.Password{
		Message: "Passphrase:",
	}

	// PromptCreatePassphrase is the standard create a new passphrase prompt.
	PromptCreatePassphrase = &survey.Password{
		Message: "Choose a new passphrase:",
	}

	// PromptRepeatPassphrase is the standard repeat a new passphrase prompt.
	PromptRepeatPassphrase = &survey.Password{
		Message: "Repeat passphrase:",
	}
)
View Source
var (
	// AccountFlag corresponds to the --account selector flag.
	AccountFlag *flag.FlagSet
	// SelectorFlags contains the common selector flags for network/ParaTime/account.
	SelectorFlags *flag.FlagSet
	// SelectorNPFlags contains the common selector flags for network/ParaTime.
	SelectorNPFlags *flag.FlagSet
	// SelectorNFlags contains the common selector flags for network.
	SelectorNFlags *flag.FlagSet
	// SelectorNAFlags contains the common selector flags for network/account.
	SelectorNAFlags *flag.FlagSet
)
View Source
var (
	// TxFlags contains the common consensus transaction flags.
	TxFlags *flag.FlagSet

	// RuntimeTxFlags contains the common runtime transaction flags.
	RuntimeTxFlags *flag.FlagSet
)
View Source
var CompleteAccountAndAddressBookNames = simpleComplete(addressNames)

CompleteAccountAndAddressBookNames provides completion for both wallet accounts and address book entries. Useful for commands that accept either as an address.

View Source
var CompleteAccountNames = simpleComplete(accountNames)

CompleteAccountNames provides completion for wallet account names.

View Source
var CompleteAddressBookNames = simpleComplete(addressBookNames)

CompleteAddressBookNames provides completion for address book entry names.

View Source
var CompleteNetworkNames = simpleComplete(networkNames)

CompleteNetworkNames provides completion for network names.

SurveyStdio is the standard survey option to direct prompts to stderr.

Functions

func AddAccountFlag added in v0.18.2

func AddAccountFlag(cmd *cobra.Command)

AddAccountFlag adds account selector flag with completion.

func AddSelectorFlags added in v0.18.2

func AddSelectorFlags(cmd *cobra.Command)

AddSelectorFlags adds network/paratime/account selector flags with completions.

func AddSelectorNAFlags added in v0.18.2

func AddSelectorNAFlags(cmd *cobra.Command)

AddSelectorNAFlags adds network/account selector flags with completions.

func AddSelectorNFlags added in v0.18.2

func AddSelectorNFlags(cmd *cobra.Command)

AddSelectorNFlags adds network selector flags with completions.

func AddSelectorNPFlags added in v0.18.2

func AddSelectorNPFlags(cmd *cobra.Command)

AddSelectorNPFlags adds network/paratime selector flags with completions.

func Ask added in v0.17.1

func Ask(p survey.Prompt, response interface{}, opts ...survey.AskOpt) error

Ask wraps survey.AskOne while forcing prompts to stderr.

func AskMulti added in v0.17.1

func AskMulti(qs []*survey.Question, response interface{}, opts ...survey.AskOpt) error

AskMulti wraps survey.Ask while forcing prompts to stderr.

func AskNewPassphrase

func AskNewPassphrase() string

AskNewPassphrase asks the user to create a new passphrase.

func BroadcastOrExportTransaction added in v0.4.0

func BroadcastOrExportTransaction(
	ctx context.Context,
	npa *NPASelection,
	conn connection.Connection,
	tx interface{},
	meta interface{},
	result interface{},
) bool

BroadcastOrExportTransaction broadcasts or exports a transaction based on configuration.

When in offline or unsigned mode, it exports the transaction and returns false. Otherwise it broadcasts the transaction and returns true.

func BroadcastTransaction

func BroadcastTransaction(
	ctx context.Context,
	npa *NPASelection,
	conn connection.Connection,
	tx interface{},
	meta interface{},
	result interface{},
)

BroadcastTransaction broadcasts a transaction.

When in offline mode, it outputs the transaction instead.

func CheckAddressIsConsensusCapable added in v0.2.0

func CheckAddressIsConsensusCapable(cfg *config.Config, address string) error

CheckAddressIsConsensusCapable checks whether the given address is derived from any known Ethereum address and is thus unspendable on consensus layer.

func CheckAddressNotReserved

func CheckAddressNotReserved(cfg *config.Config, address string) error

CheckAddressNotReserved checks whether the given native address is potentially unspendable like the reserved addresses for the staking reward and common pool, fee accumulator or the native ParaTime addresses.

func CheckForceErr

func CheckForceErr(err interface{})

CheckForceErr treats error as warning, if --force is provided.

func CompleteNetworkThenParaTime added in v0.18.2

func CompleteNetworkThenParaTime(_ *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective)

CompleteNetworkThenParaTime provides completion for commands that take <network> <paratime> as positional arguments.

func CompleteParaTimeNames added in v0.18.2

func CompleteParaTimeNames(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective)

CompleteParaTimeNames provides completion for ParaTime names. It uses the default network if --network flag is not set.

func Confirm

func Confirm(msg, abortMsg string)

Confirm asks the user for confirmation and aborts when rejected.

func ExportTransaction added in v0.4.0

func ExportTransaction(sigTx interface{})

ExportTransaction exports a (signed) transaction based on configuration.

func FindAccountName added in v0.14.2

func FindAccountName(address string) string

FindAccountName finds account's name (if exists).

func GenAccountEthMap added in v0.18.3

func GenAccountEthMap() map[string]string

GenAccountEthMap generates a map of native address string -> eth hex address (if known). Priority order matches GenAccountNames: test accounts < addressbook < wallet.

func GenAccountNames added in v0.2.0

func GenAccountNames() types.AccountNames

GenAccountNames generates a map of all known native addresses -> account name for pretty printing. It includes test accounts, configured networks (paratimes/ROFL defaults), addressbook and wallet.

Priority order (later entries overwrite earlier): test accounts < network entries < addressbook < wallet.

func GetActualHeight

func GetActualHeight(
	ctx context.Context,
	consensusConn consensus.Backend,
) (int64, error)

GetActualHeight returns the user-selected block height if explicitly specified, or the current latest height.

func GetAnswerYes added in v0.9.0

func GetAnswerYes() bool

GetAnswerYes returns whether all interactive questions should be answered with yes.

func GetHeight

func GetHeight() int64

GetHeight returns the user-selected block height.

func IsForce

func IsForce() bool

IsForce returns force mode.

func IsVerbose added in v0.14.3

func IsVerbose() bool

IsVerbose returns verbose mode.

func JSONMarshalKey

func JSONMarshalKey(k interface{}) (keyJSON []byte, err error)

JSONMarshalKey encodes k as UTF-8 string if valid, or Base64 otherwise.

func JSONMarshalUniversalValue

func JSONMarshalUniversalValue(v interface{}) []byte

JSONMarshalUniversalValue is a wrapper for the built-in JSON encoder which adds support for marshalling map[interface{}]interface{}.

Each key is encoded as string if it contains valid UTF-8 value. Otherwise, Base64 is used.

func JSONPrintKeyValueTuple

func JSONPrintKeyValueTuple(items []contracts.InstanceStorageKeyValue)

JSONPrintKeyValueTuple traverses potentially large number of items and prints JSON representation of them.

Marshalling is done externally without holding resulting JSON string in-memory. Cbor decoding of each value is tried first. If it fails, the binary content is preserved. Universal marshalling of map[interface{}]interface{} types is also supported. Each key is encoded as string if it contains valid UTF-8 value. Otherwise, Base64 is used.

func LoadAccount

func LoadAccount(cfg *config.Config, name string) wallet.Account

LoadAccount loads the given named account.

func LoadAccountConfig added in v0.8.0

func LoadAccountConfig(cfg *config.Config, name string) (*config.Account, error)

LoadAccountConfig loads the config instance of the given named account.

func LoadTestAccount

func LoadTestAccount(name string) (wallet.Account, error)

LoadTestAccount loads the given named test account.

func LoadTestAccountConfig

func LoadTestAccountConfig(name string) (*config.Account, error)

LoadTestAccountConfig loads config for the given named test account.

func ParaTimeAddresses added in v0.18.2

func ParaTimeAddresses(cfg *config.Config) []string

ParaTimeAddresses returns all paratime addresses in "paratime:<name>" format for the given config.

func ParseTestAccountAddress added in v0.8.0

func ParseTestAccountAddress(name string) string

ParseTestAccountAddress extracts test account name from "test:some_test_account" format or returns an empty string, if the format doesn't match.

func PrepareConsensusTransaction added in v0.10.3

func PrepareConsensusTransaction(ctx context.Context, npa *NPASelection, signer coreSignature.Signer, conn connection.Connection, tx *consensusTx.Transaction) (consensusTx.Gas, *quantity.Quantity, error)

PrepareConsensusTransaction initialized nonce and gas fields of the consensus transaction and estimates gas.

Returns the estimated gas limit and total fee amount.

func PrepareParatimeTransaction added in v0.10.3

func PrepareParatimeTransaction(ctx context.Context, npa *NPASelection, account wallet.Account, conn connection.Connection, tx *types.Transaction) (uint64, *quantity.Quantity, types.Denomination, error)

PrepareParatimeTransaction initializes nonce and gas fields of the ParaTime transaction and estimates gas.

Returns the estimated gas limit, total fee amount and fee denominator.

func PrettyAddress added in v0.18.3

func PrettyAddress(addr string) string

PrettyAddress is like PrettyAddressWith but builds a fresh context on each call.

func PrettyAddressWith added in v0.18.3

func PrettyAddressWith(ctx AddressFormatContext, addr string) string

PrettyAddressWith formats the address in native or eth string for display using a precomputed context. Known addresses return "name (preferred_addr)", unknown addresses return the input unchanged.

func PrettyErrorHints added in v0.12.1

func PrettyErrorHints(
	_ context.Context,
	npa *NPASelection,
	_ connection.Connection,
	_ interface{},
	_ interface{},
	failedRes *types.FailedCallResult,
) string

PrettyErrorHints adds any hints based on the error and the transaction context.

func PrettyJSONMarshal

func PrettyJSONMarshal(v interface{}) ([]byte, error)

PrettyJSONMarshal returns pretty-printed JSON encoding of v.

func PrettyJSONMarshalIndent added in v0.13.0

func PrettyJSONMarshalIndent(v interface{}, prefix, indent string) ([]byte, error)

PrettyJSONMarshal returns pretty-printed JSON encoding of v.

func PrettyPrint added in v0.10.4

func PrettyPrint(npa *NPASelection, prefix string, blob interface{}) string

PrettyPrint transforms generic JSON-formatted data into a pretty-printed string. For types implementing consensusPretty.PrettyPrinter, it uses the custom pretty printer. For other types, it does basic JSON indentation and cleanup of common delimiters.

func PrettyPrintWithTxDetails added in v0.18.3

func PrettyPrintWithTxDetails(npa *NPASelection, prefix string, blob interface{}, txDetails *signature.TxDetails) string

PrettyPrintWithTxDetails is like PrettyPrint but passes txDetails to the signature context.

func PrintTransaction added in v0.2.0

func PrintTransaction(npa *NPASelection, tx interface{})

PrintTransaction prints the transaction which can be either signed or unsigned together with information about the selected network/ParaTime.

func PrintTransactionBeforeSigning

func PrintTransactionBeforeSigning(npa *NPASelection, tx interface{}, txDetails *signature.TxDetails)

PrintTransactionBeforeSigning prints the transaction and asks the user for confirmation.

func PrintTransactionRaw added in v0.4.0

func PrintTransactionRaw(npa *NPASelection, tx interface{})

PrintTransactionRaw prints the transaction which can be either signed or unsigned.

func PrintTransactionRawWithTxDetails added in v0.18.3

func PrintTransactionRawWithTxDetails(npa *NPASelection, tx interface{}, txDetails *signature.TxDetails)

PrintTransactionRawWithTxDetails is like PrintTransactionRaw but passes txDetails to the pretty-printer.

func PrintTransactionWithTxDetails added in v0.18.3

func PrintTransactionWithTxDetails(npa *NPASelection, tx interface{}, txDetails *signature.TxDetails)

PrintTransactionWithTxDetails is like PrintTransaction but passes txDetails to the pretty-printer.

func ResolveAddress added in v0.8.0

func ResolveAddress(net *configSdk.Network, address string) (*types.Address, *ethCommon.Address, error)

ResolveAddress resolves a string address into the corresponding account address.

func ResolveLocalAccountOrAddress

func ResolveLocalAccountOrAddress(net *configSdk.Network, address string) (*types.Address, *ethCommon.Address, error)

ResolveLocalAccountOrAddress resolves a string address into the corresponding account address.

func SignConsensusTransaction

func SignConsensusTransaction(
	ctx context.Context,
	npa *NPASelection,
	account wallet.Account,
	conn connection.Connection,
	tx *consensusTx.Transaction,
) (interface{}, error)

SignConsensusTransaction signs a consensus transaction.

func SignParaTimeTransaction

func SignParaTimeTransaction(
	ctx context.Context,
	npa *NPASelection,
	account wallet.Account,
	conn connection.Connection,
	tx *types.Transaction,
	txDetails *signature.TxDetails,
) (interface{}, interface{}, error)

SignParaTimeTransaction signs a ParaTime transaction.

Returns the signed transaction and call format-specific metadata for result decoding.

func WaitForEvent

func WaitForEvent(
	ctx context.Context,
	pt *config.ParaTime,
	conn connection.Connection,
	decoder client.EventDecoder,
	mapFn func(client.DecodedEvent) interface{},
) <-chan interface{}

WaitForEvent waits for a specific ParaTime event.

If no mapFn is specified, the returned channel will contain DecodedEvents, otherwise it will contain whatever mapFn returns.

If mapFn is specified it should return a non-nil value when encountering a matching event.

func Warn added in v0.17.1

func Warn(msg string)

Warn prints a message to stderr.

func Warnf added in v0.17.1

func Warnf(format string, args ...interface{})

Warnf prints a message to stderr with formatting.

Types

type AddressFormatContext added in v0.18.3

type AddressFormatContext struct {
	// Names maps native address string to account name.
	Names types.AccountNames
	// Eth maps native address string to Ethereum hex address string, if known.
	Eth map[string]string
}

AddressFormatContext contains precomputed maps for address formatting.

func GenAddressFormatContext added in v0.18.3

func GenAddressFormatContext() AddressFormatContext

GenAddressFormatContext builds both name and eth address maps for formatting.

type CobraCompletionFunc added in v0.18.2

type CobraCompletionFunc = func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective)

CobraCompletionFunc is the function signature for cobra completions.

func AccountNamesAt added in v0.18.2

func AccountNamesAt(positions ...int) CobraCompletionFunc

AccountNamesAt returns a completion function for wallet account names at specified positions.

func AddressBookNamesAt added in v0.18.2

func AddressBookNamesAt(positions ...int) CobraCompletionFunc

AddressBookNamesAt returns a completion function for address book names at specified positions.

func AddressesAt added in v0.18.2

func AddressesAt(positions ...int) CobraCompletionFunc

AddressesAt returns a completion function for wallet + address book names at specified positions.

func NetworksAt added in v0.18.2

func NetworksAt(positions ...int) CobraCompletionFunc

NetworksAt returns a completion function for network names at specified positions.

func StaticAt added in v0.18.2

func StaticAt(values []string, positions ...int) CobraCompletionFunc

StaticAt returns a completion function for static values at specified positions.

type FormatType added in v0.10.4

type FormatType string

FormatType specifies the type of format for output of commands.

const (
	// Output plain text.
	FormatText FormatType = "text"
	// Output JSON.
	FormatJSON FormatType = "json"
)

Supported output formats for the format flag.

func OutputFormat added in v0.10.4

func OutputFormat() FormatType

OutputFormat returns the format of the command's output.

func (*FormatType) Set added in v0.10.4

func (f *FormatType) Set(v string) error

Set sets the value of the type to the argument given.

func (*FormatType) String added in v0.10.4

func (f *FormatType) String() string

String returns a string representation of the output format type.

func (*FormatType) Type added in v0.10.4

func (f *FormatType) Type() string

Type returns the type of the flag.

type JSONPrettyPrintRoflAppConfig added in v0.16.1

type JSONPrettyPrintRoflAppConfig rofl.AppConfig

JSONPrettyPrintRoflAppConfig is a wrapper around rofl.AppConfig that implements custom JSON marshaling.

func (JSONPrettyPrintRoflAppConfig) MarshalJSON added in v0.16.1

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

MarshalJSON implements custom JSON marshaling.

type JSONPrettyPrintRoflRegistration added in v0.16.1

type JSONPrettyPrintRoflRegistration rofl.Registration

JSONPrettyPrintRoflRegistration is a wrapper around rofl.Registration that implements custom JSON marshaling.

func (JSONPrettyPrintRoflRegistration) MarshalJSON added in v0.16.1

func (r JSONPrettyPrintRoflRegistration) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling.

type NPASelection

type NPASelection struct {
	NetworkName string
	Network     *config.Network

	ParaTimeName string
	ParaTime     *config.ParaTime

	AccountName          string
	Account              *cliConfig.Account
	AccountSetExplicitly bool
}

NPASelection contains the network/ParaTime/account selection.

func GetNPASelection

func GetNPASelection(cfg *cliConfig.Config) *NPASelection

GetNPASelection returns the user-selected network/ParaTime/account combination.

func (*NPASelection) ConsensusDenomination added in v0.8.0

func (npa *NPASelection) ConsensusDenomination() (denom types.Denomination)

ConsensusDenomination returns the denomination used to represent the consensus layer token.

func (*NPASelection) MustHaveAccount added in v0.12.1

func (npa *NPASelection) MustHaveAccount()

MustHaveAccount checks whether Account is populated and fails if it is not.

func (*NPASelection) MustHaveParaTime added in v0.12.1

func (npa *NPASelection) MustHaveParaTime()

MustHaveParaTime checks whether ParaTime is populated and fails if it is not.

func (*NPASelection) PrettyPrintNetwork added in v0.4.0

func (npa *NPASelection) PrettyPrintNetwork() (out string)

PrettyPrintNetwork formats the network name and description, if one exists.

type NodeLookup added in v0.4.0

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

func NewNodeLookup added in v0.4.0

func NewNodeLookup(
	ctx context.Context,
	consensus consensus.Backend,
	registry registry.Backend,
	height int64,
) (*NodeLookup, error)

func (*NodeLookup) ByID added in v0.4.0

func (nl *NodeLookup) ByID(
	ctx context.Context,
	id signature.PublicKey,
) (*node.Node, error)

func (*NodeLookup) SetHeight added in v0.4.0

func (nl *NodeLookup) SetHeight(
	ctx context.Context,
	height int64,
) error

type TransactionConfig

type TransactionConfig struct {
	// Offline is a flag indicating that no online queries are allowed.
	Offline bool

	// Export is a flag indicating that the transaction should be exported instead of broadcast.
	Export bool
}

TransactionConfig contains the transaction-related configuration from flags.

func GetTransactionConfig

func GetTransactionConfig() *TransactionConfig

GetTransactionConfig returns the transaction-related configuration from flags.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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