common

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

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 (
	// 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
)
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.

View Source
var TransactionFlags *flag.FlagSet

TransactionFlags contains the common transaction flags.

Functions

func AskNewPassphrase

func AskNewPassphrase() string

AskNewPassphrase asks the user to create a new passphrase.

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 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 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 PrettyJSONMarshal

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

PrettyJSONMarshal returns pretty-printed JSON encoding of v.

func PrintSignedTransaction

func PrintSignedTransaction(sigTx interface{})

PrintSignedTransaction prints a signed transaction.

func PrintTransaction added in v0.2.0

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

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

func PrintTransactionBeforeSigning

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

PrintTransactionBeforeSigning prints the transaction and asks the user for confirmation.

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,
) (*consensusTx.SignedTransaction, error)

SignConsensusTransaction signs a consensus transaction.

func SignParaTimeTransaction

func SignParaTimeTransaction(
	ctx context.Context,
	npa *NPASelection,
	wallet wallet.Account,
	conn connection.Connection,
	tx *types.Transaction,
	txDetails *signature.TxDetails,
) (*types.UnverifiedTransaction, 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.

type TransactionConfig

type TransactionConfig struct {
	// Offline is a flag indicating that no online queries are allowed.
	Offline 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