common

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMarker = " (*)"

Variables

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/wallet.
	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 (
	// YesFlag corresponds to the yes-to-all flag.
	YesFlag *flag.FlagSet

	// TxFlags contains the common consensus transaction flags.
	TxFlags *flag.FlagSet

	// RuntimeTxFlags contains the common runtime transaction flags.
	RuntimeTxFlags *flag.FlagSet
)
View Source
var ForceFlag *flag.FlagSet

ForceFlag is a force mode switch.

View Source
var HeightFlag *flag.FlagSet

HeightFlag is the flag for specifying block height.

Functions

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,
	pt *config.ParaTime,
	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,
	pt *config.ParaTime,
	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 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 GenAccountNames added in v0.2.0

func GenAccountNames() types.AccountNames

GenAccountNames generates a map of all addresses -> account name for pretty printing.

func GetActualHeight

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

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

func GetHeight

func GetHeight() int64

GetHeight returns the user-selected block height.

func IsForce

func IsForce() bool

IsForce returns force 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 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 PrettyJSONMarshal

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

PrettyJSONMarshal returns pretty-printed JSON encoding of v.

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{})

PrintTransactionBeforeSigning prints the transaction and asks the user for confirmation.

func PrintTransactionRaw added in v0.4.0

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

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

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,
	wallet 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.

Types

type NPASelection

type NPASelection struct {
	NetworkName string
	Network     *config.Network

	ParaTimeName string
	ParaTime     *config.ParaTime

	AccountName string
	Account     *cliConfig.Account
}

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) 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.ClientBackend,
	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.

Jump to

Keyboard shortcuts

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