siliqua.ui.stdio package

Submodules

siliqua.ui.stdio.commands module

siliqua.ui.stdio.commands.add_account(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, account_id: <siliqua.ui.stdio.params.AccountOption object at 0x7fbd4018b2b0>, public_key: <siliqua.ui.stdio.params.PublicKeyOption object at 0x7fbd4018b400>, private_key: <siliqua.ui.stdio.params.PrivateKeyOption object at 0x7fbd4018b438>)
siliqua.ui.stdio.commands.add_to_address_book(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, account_id: siliqua.ui.stdio.params.AccountParam, name: siliqua.ui.stdio.params.StrParam)
siliqua.ui.stdio.commands.block_to_dict(block, include_block_data=False)

Convert a block into a dict that can be added into a result

Parameters
Returns

Block as a dict

Return type

dict

siliqua.ui.stdio.commands.calculate_key_iteration_count(server, seconds: siliqua.ui.stdio.params.FloatParam)
siliqua.ui.stdio.commands.change_account_representative(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, account_id: siliqua.ui.stdio.params.AccountParam, representative: siliqua.ui.stdio.params.AccountParam, wait_until_confirmed: <siliqua.ui.stdio.params.BoolOption object at 0x7fbd4018b908>, timeout: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd4018b9e8>)
siliqua.ui.stdio.commands.change_encryption(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, new_passphrase: siliqua.ui.stdio.params.SecureStrOption, encrypt_secrets: siliqua.ui.stdio.params.BoolOption, encrypt_wallet: siliqua.ui.stdio.params.BoolOption, key_iteration_count: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd401875f8>)
siliqua.ui.stdio.commands.change_gap_limit(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, gap_limit: <siliqua.ui.stdio.params.IntRangeParam object at 0x7fbd4018b198>)
siliqua.ui.stdio.commands.clear_account_name(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, account_id: siliqua.ui.stdio.params.AccountParam)
siliqua.ui.stdio.commands.clear_block_description(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, block_hash: siliqua.ui.stdio.params.BlockHashParam)
siliqua.ui.stdio.commands.create_wallet(server, wallet_path: <siliqua.ui.stdio.params.FilePathParam object at 0x7fbd401e4470>, seed: siliqua.ui.stdio.params.SecureStrOption, encrypt_secrets: siliqua.ui.stdio.params.BoolOption, encrypt_wallet: siliqua.ui.stdio.params.BoolOption, passphrase: siliqua.ui.stdio.params.SecureStrOption, gap_limit: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd401e4630>, key_iteration_count: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd401e40f0>)
siliqua.ui.stdio.commands.generate_account(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, count: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd4018b470>)
siliqua.ui.stdio.commands.get_account_private_key(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, account_id: siliqua.ui.stdio.params.AccountParam)
siliqua.ui.stdio.commands.get_balance(server, passphrase: siliqua.ui.stdio.params.PassphraseOption)
siliqua.ui.stdio.commands.get_block(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, block_hash: siliqua.ui.stdio.params.BlockHashParam)
siliqua.ui.stdio.commands.get_default_key_iteration_count()

Get default key iteration count. Used as a default value for options.

siliqua.ui.stdio.commands.get_wallet_block(wallet, block_hash)
siliqua.ui.stdio.commands.get_wallet_seed(server, passphrase: siliqua.ui.stdio.params.PassphraseOption)
siliqua.ui.stdio.commands.list_accounts(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, limit: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd4018ba20>, offset: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd4018bb00>, descending: <siliqua.ui.stdio.params.BoolOption object at 0x7fbd4018bb38>)
siliqua.ui.stdio.commands.list_address_book(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, limit: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd4018bc50>, offset: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd4018bcf8>, descending: <siliqua.ui.stdio.params.BoolOption object at 0x7fbd4018bd30>)
siliqua.ui.stdio.commands.list_blocks(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, account_id: siliqua.ui.stdio.params.AccountParam, limit: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd4018bb70>, offset: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd4018bbe0>, descending: <siliqua.ui.stdio.params.BoolOption object at 0x7fbd4018bc18>)
siliqua.ui.stdio.commands.remove_account(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, account_id: siliqua.ui.stdio.params.AccountParam)
siliqua.ui.stdio.commands.remove_from_address_book(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, account_id: siliqua.ui.stdio.params.AccountParam)
siliqua.ui.stdio.commands.send(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, source: siliqua.ui.stdio.params.AccountParam, destination: siliqua.ui.stdio.params.AccountParam, amount: siliqua.ui.stdio.params.AmountParam, wait_until_confirmed: <siliqua.ui.stdio.params.BoolOption object at 0x7fbd4018b668>, txid: siliqua.ui.stdio.params.StrOption, description: siliqua.ui.stdio.params.StrOption, timeout: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd4018b6d8>)
siliqua.ui.stdio.commands.send_many(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, source: siliqua.ui.stdio.params.AccountParam, transactions: <siliqua.ui.stdio.params.RepeatParams object at 0x7fbd4018b710>, wait_until_confirmed: <siliqua.ui.stdio.params.BoolOption object at 0x7fbd4018b898>, timeout: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd4018b8d0>, description: siliqua.ui.stdio.params.StrOption)
siliqua.ui.stdio.commands.set_account_name(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, account_id: siliqua.ui.stdio.params.AccountParam, name: siliqua.ui.stdio.params.StrParam)
siliqua.ui.stdio.commands.set_block_description(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, block_hash: siliqua.ui.stdio.params.BlockHashParam, description: siliqua.ui.stdio.params.StrParam)
siliqua.ui.stdio.commands.sync(server, passphrase: siliqua.ui.stdio.params.PassphraseOption, finish_work: <siliqua.ui.stdio.params.BoolOption object at 0x7fbd4018b550>, finish_sync: <siliqua.ui.stdio.params.BoolOption object at 0x7fbd4018b5c0>, timeout: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd4018b5f8>, result_count: <siliqua.ui.stdio.params.IntRangeOption object at 0x7fbd4018b630>)
siliqua.ui.stdio.commands.wait_result_to_dict_and_error(wait_result)

Convert a wait result into a dict that can be added into a result.

Parameters

wait_result (siliqua.network.WaitResult) – Wait result

Returns

Wait result as a dict

Return type

dict

siliqua.ui.stdio.exceptions module

exception siliqua.ui.stdio.exceptions.StdioError(code, message)

Bases: Exception

Error type with an error code and message that can be printed in a JSON format.

show()
siliqua.ui.stdio.exceptions.create_error(code, message)

Create a StdioError from given code and message

Parameters
  • code (str) – Short code name for error

  • message (str) – Human readable error message

siliqua.ui.stdio.params module

class siliqua.ui.stdio.params.AccountOption(**kwargs)

Bases: siliqua.ui.stdio.params.BaseOption

Account ID option

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.AccountParam(**kwargs)

Bases: siliqua.ui.stdio.params.BaseParam

Account ID parameter

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.AmountParam(**kwargs)

Bases: siliqua.ui.stdio.params.BaseParam

Amount parameter.

Amount is accepted as a single integer (denomination is assumed to be raw) or “<amount> <unit>” string where amount can be a decimal and unit is the NANO denomination.

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.BaseOption(**kwargs)

Bases: siliqua.ui.stdio.params.BaseParam

Base class for different option types

to_cli_parameter()

Convert parameter to a click.Argument

Returns

Click argument

Return type

click.Argument

class siliqua.ui.stdio.params.BaseParam(**kwargs)

Bases: object

Base class for different parameter types

click_callback(ctx, param, value)

Function called by Click to parse the value

get_click_kwargs()

Get a dict of kwargs to pass to the underlying click.Option class

Returns

Dict of keyword arguments

Return type

dict

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

to_cli_parameter()

Convert parameter to a click.Argument

Returns

Click argument

Return type

click.Argument

class siliqua.ui.stdio.params.BlockHashParam(**kwargs)

Bases: siliqua.ui.stdio.params.BaseParam

Block hash parameter.

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.BoolOption(**kwargs)

Bases: siliqua.ui.stdio.params.BaseOption

Bool option that uses two flag parameters.

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

to_cli_parameter()

Convert parameter to a click.Argument

Returns

Click argument

Return type

click.Argument

class siliqua.ui.stdio.params.BoolParam(**kwargs)

Bases: siliqua.ui.stdio.params.BaseParam

Bool parameter. Accepts different string aliases.

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.FilePathParam(**kwargs)

Bases: siliqua.ui.stdio.params.BaseParam

Parameter for a file path

get_click_kwargs()

Get a dict of kwargs to pass to the underlying click.Option class

Returns

Dict of keyword arguments

Return type

dict

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.FloatOption(**kwargs)

Bases: siliqua.ui.stdio.params.BaseOption

Float option. Integers are also accepted.

get_click_kwargs()

Get a dict of kwargs to pass to the underlying click.Option class

Returns

Dict of keyword arguments

Return type

dict

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.FloatParam(**kwargs)

Bases: siliqua.ui.stdio.params.BaseParam

Float parameter. Integers are also accepted.

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.GroupClickOption(*args, **kwargs)

Bases: click.core.Option

Subclass of click.Option that allows options to be grouped with the group_name attribute.

This means that if at least one option in the same group already has a value, no prompts are created for other options in the group.

handle_parse_result(ctx, opts, args)
prompt_for_value(ctx)

This is an alternative flow that can be activated in the full value processing if a value does not exist. It will prompt the user until a valid value exists and then returns the processed value as result.

class siliqua.ui.stdio.params.IntParam(**kwargs)

Bases: siliqua.ui.stdio.params.BaseParam

Integer parameter. Floats are not accepted.

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.IntRangeOption(**kwargs)

Bases: siliqua.ui.stdio.params.BaseOption

Integer range option. Only integers in the given inclusive range are accepted.

get_click_kwargs()

Get a dict of kwargs to pass to the underlying click.Option class

Returns

Dict of keyword arguments

Return type

dict

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.IntRangeParam(**kwargs)

Bases: siliqua.ui.stdio.params.BaseParam

Integer range parameter. Only integers in the given inclusive range are accepted.

get_click_kwargs()

Get a dict of kwargs to pass to the underlying click.Option class

Returns

Dict of keyword arguments

Return type

dict

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.PassphraseOption(**kwargs)

Bases: siliqua.ui.stdio.params.SecureStrOption

Passphrase option.

Is essentially the same as SecureStrOption except that in an interactive session the passphrase prompt is postponed until needed.

to_cli_parameter()

Convert parameter to a click.Argument

Returns

Click argument

Return type

click.Argument

class siliqua.ui.stdio.params.PrivateKeyOption(**kwargs)

Bases: siliqua.ui.stdio.params.SecureStrOption

Private key option. Private key is accepted only in hexadecimal format.

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.PrivateKeyParam(**kwargs)

Bases: siliqua.ui.stdio.params.BaseParam

Private key parameter. Private key is accepted only in hexadecimal format.

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.PublicKeyOption(**kwargs)

Bases: siliqua.ui.stdio.params.BaseOption

Public key option. Public key is accepted only in hexadecimal format.

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.PublicKeyParam(**kwargs)

Bases: siliqua.ui.stdio.params.BaseParam

Public key parameter. Public key is accepted only in hexadecimal format.

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.RepeatParams(names, types, **kwargs)

Bases: siliqua.ui.stdio.params.BaseParam

Parameter that can be repeated indefinitely.

The underlying parameter can consist of a single parameter, or multiple parameters.

click_callback(ctx, param, value)

Function called by Click to parse the value

get_click_kwargs()

Get a dict of kwargs to pass to the underlying click.Option class

Returns

Dict of keyword arguments

Return type

dict

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.SecureStrOption(**kwargs)

Bases: siliqua.ui.stdio.params.BaseOption

Secure string option.

Secure strings can be passed using environment variables or prompted directly from the user in an interactive session

get_click_kwargs()

Get a dict of kwargs to pass to the underlying click.Option class

Returns

Dict of keyword arguments

Return type

dict

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

to_cli_parameter()

Convert parameter to a click.Argument

Returns

Click argument

Return type

click.Argument

class siliqua.ui.stdio.params.StrOption(**kwargs)

Bases: siliqua.ui.stdio.params.BaseOption

String option

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

class siliqua.ui.stdio.params.StrParam(**kwargs)

Bases: siliqua.ui.stdio.params.BaseParam

String parameter

parse(val)

Parse the received value. If the value is invalid ValueError should be raised with a human-readable error message.

Parameters

val (str) – Value to parse

Returns

Parsed value

siliqua.ui.stdio.util module

class siliqua.ui.stdio.util.PaginationResults(results, total_count)

Bases: object

Result object that can be iterated to get paginated results.

Variables
  • results – List of results

  • total_count – Total count of the original list before pagination

results
total_count
class siliqua.ui.stdio.util.StdioResult(data=None, error=None)

Bases: object

Result created by running a command. Result can be successful or a failure.

Result can be printed in JSON format

show()

Print the result to stdio in JSON format

siliqua.ui.stdio.util.cli_command(wallet_required=True, help_text=None, short_help_text=None, start_work=True, start_network=True)

Stdio command decorator that marks a function as a CLI command and allows configuring common behavior.

Parameters
  • wallet_required (bool) – Whether the command requires a wallet to be loaded when called

  • help_text (str) – Long help text

  • short_help_text (str) – Abbreviated help text

  • start_work (bool) – Whether to start the work provider automatically

  • start_network (bool) – Whether to start the network provider automatically

siliqua.ui.stdio.util.get_cli_params(func)

Return a list of stdio command’s parameters by iterating through its annotations

siliqua.ui.stdio.util.paginate_list(entries, limit, offset, descending)

Paginate a list and return a PaginationResults object

Parameters
  • entries (list) – List of entries to paginate

  • limit (int) – Maximum amount of entries to return

  • offset (int) – Amount of entries to skip

  • descending (bool) – Whether to return entries in descending or ascending order

Returns

Pagination results

Return type

PaginationResults

siliqua.ui.stdio.util.parse_manual_params(func, kwargs)

Parse command parameters through a dict instead of the normal CLI interface.

This is used when calling the commands outside the Click-based interface

siliqua.ui.stdio.util.raise_common_error(exc)

Try raising an exception as a StdioError that can be printed in JSON format

siliqua.ui.stdio.util.to_cli_command(func, callback)

Convert a stdio command function into a Click command and return it

siliqua.ui.stdio.util.truncate_ordered_dict(d, max_length=10)

Truncate an ordered dict starting from the oldest entries until it has the given maximum length

Parameters
  • d – OrderedDict instance

  • max_count (int) – Maximum length of the dict

siliqua.ui.stdio.util.unlock_wallet(*args, **kwargs)

Context manager to temporarily unlock the wallet.

Convenience function is also returned that allows secret fields to be read when the wallet is unlocked.

Module contents

class siliqua.ui.stdio.StdioUI(config)

Bases: siliqua.ui.BaseUI

User interface plugin that implements a command-line interface for wallet usage

get_cli()

Get Click command for each individual stdio command

run(server, ctx, cmd_func, **kwargs)

Run the given Click command which contains the underlying wrapped command

siliqua.ui.stdio.wrap_command(cmd_func)

Wrapper used when a command is called using the CLI to ensure the correct function is called.

Any exception/output is captured and printed as a JSON formatted string