common

package
v0.0.0-...-19ae9e6 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: Apache-2.0 Imports: 28 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 HeightFlag *flag.FlagSet

HeightFlag is the flag for specifying block height.

View Source
var SelectorFlags *flag.FlagSet

SelectorFlags contains the common selector flags for network/paratime/wallet.

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 CheckLocalAccountIsConsensusCapable

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

CheckLocalAccountIsConsensusCapable is a safety check for withdrawals or consensus layer transfers to potentially known native addresses which key pairs are not compatible with consensus or the address is a derivation of a known Ethereum address.

func Confirm

func Confirm(msg, abortMsg string)

Confirm asks the user for confirmation and aborts when rejected.

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 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 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, 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,
) (*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