removes unused cli code

pull/3334/head
Kieran Prasch 2023-11-02 21:14:48 +01:00 committed by KPrasch
parent b05f742d86
commit 6a8fdc0c3c
6 changed files with 0 additions and 242 deletions

View File

@ -5,9 +5,6 @@
FORCE_MODE_WARNING = "WARNING: Force is enabled"
DEVELOPMENT_MODE_WARNING = "WARNING: Running in Development mode"
# Blockchain
CONNECTING_TO_BLOCKCHAIN = "Reading Latest Chaindata..."
# Events
CONFIRM_OVERWRITE_EVENTS_CSV_FILE = "Overwrite existing CSV events file - {csv_file}?"
@ -65,12 +62,3 @@ CONFIRM_URSULA_IPV4_ADDRESS = (
"Detected IPv4 address ({rest_host}) - " + CONFIRM_IPV4_ADDRESS_QUESTION
)
COLLECT_URSULA_IPV4_ADDRESS = "Enter Ursula's public-facing IPv4 address"
# Deployment
NO_HARDWARE_WALLET_WARNING = "WARNING: --no-hw-wallet is enabled."
ETHERSCAN_FLAG_ENABLED_WARNING = """
WARNING: --etherscan is enabled. A browser tab will be opened with deployed contracts and TXs as provided by Etherscan.
"""
ETHERSCAN_FLAG_DISABLED_WARNING = """
WARNING: --etherscan is disabled. If you want to see deployed contracts and TXs in your browser, activate --etherscan.
"""

View File

@ -7,7 +7,6 @@ import click
from nucypher.blockchain.eth.constants import TACO_CONTRACT_NAMES
from nucypher.cli.types import (
EIP55_CHECKSUM_ADDRESS,
EXISTING_READABLE_FILE,
GWEI,
MIN_AUTHORIZATION,
@ -84,12 +83,6 @@ option_registry_filepath = click.option(
type=EXISTING_READABLE_FILE,
)
option_signer_uri = click.option("--signer", "signer_uri", "-S", default=None, type=str)
option_staking_provider = click.option(
"--staking-provider",
help="Staking provider ethereum address",
type=EIP55_CHECKSUM_ADDRESS,
required=True,
)
option_teacher_uri = click.option(
"--teacher",
"teacher_uri",
@ -174,31 +167,3 @@ def group_options(option_class, **options):
return wrapper
return _decorator
def wrap_option(handler, **options):
assert len(options) == 1
name = list(options)[0]
dec = options[name]
@functools.wraps(handler)
def _decorator(func):
@functools.wraps(func)
def wrapper(**kwargs):
if name not in kwargs:
raise ValueError(
f"When trying to wrap a CLI option with {handler}, "
f"{name} was not found among arguments")
option_val = kwargs[name]
option_name, new_val = handler(option_val)
del kwargs[name]
kwargs[option_name] = new_val
return func(**kwargs)
wrapper = dec(wrapper)
return wrapper
return _decorator

View File

@ -1,84 +0,0 @@
import maya
from nucypher.config.constants import SEEDNODES
def build_fleet_state_status(ursula) -> str:
return str(ursula.known_nodes.current_state)
def paint_node_status(emitter, ursula, start_time):
ursula.mature() # Just to be sure
# Build Learning status line
learning_status = "Unknown"
if ursula._learning_task.running:
learning_status = "Learning at {}s Intervals".format(ursula._learning_task.interval)
elif not ursula._learning_task.running:
learning_status = "Not Learning"
teacher = 'Current Teacher ..... No Teacher Connection'
if ursula._current_teacher_node:
teacher = 'Current Teacher ..... {}'.format(ursula._current_teacher_node)
# Build FleetState status line
fleet_state = build_fleet_state_status(ursula=ursula)
stats = ['⇀URSULA {}'.format(ursula.nickname.icon),
'{}'.format(ursula),
'Uptime .............. {}'.format(maya.now() - start_time),
'Start Time .......... {}'.format(start_time.slang_time()),
'Fleet State.......... {}'.format(fleet_state),
'Learning Status ..... {}'.format(learning_status),
'Learning Round ...... Round #{}'.format(ursula._learning_round),
'Rest Interface ...... {}'.format(ursula.rest_url()),
'Node Storage Type ... {}'.format(ursula.node_storage._name.capitalize()),
'Known Nodes ......... {}'.format(len(ursula.known_nodes)),
teacher]
operator_address = 'Operator Address ...... {}'.format(ursula.operator_address)
stats.extend([operator_address])
emitter.echo('\n' + '\n'.join(stats) + '\n')
def paint_known_nodes(emitter, ursula) -> None:
# Gather Data
known_nodes = ursula.known_nodes
number_of_known_nodes = len(ursula.node_storage.all())
seen_nodes = len(ursula.node_storage.all(certificates_only=True))
# Heading
label = "Known Nodes (connected {} / seen {})".format(number_of_known_nodes, seen_nodes)
heading = '\n' + label + " " * (45 - len(label))
emitter.echo(heading, bold=True)
# Build FleetState status line
fleet_state = build_fleet_state_status(ursula=ursula)
fleet_status_line = 'Fleet State {}'.format(fleet_state)
emitter.echo(fleet_status_line, color='blue', bold=True)
# Legend
color_index = {
'self': 'yellow',
'known': 'white',
'seednode': 'blue'
}
# Legend
# for node_type, color in color_index.items():
# emitter.echo('{0:<6} | '.format(node_type), color=color, nl=False)
# emitter.echo('\n')
seednode_addresses = list(bn.checksum_address for bn in SEEDNODES)
for node in known_nodes:
row_template = "{} | {}"
node_type = 'known'
if node.checksum_address == ursula.checksum_address:
node_type = 'self'
row_template += ' ({})'.format(node_type)
elif node.checksum_address in seednode_addresses:
node_type = 'seednode'
row_template += ' ({})'.format(node_type)
emitter.echo(row_template.format(node.rest_url().ljust(20), node), color=color_index[node_type])

View File

@ -1,34 +0,0 @@
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
from nucypher.blockchain.eth.utils import etherscan_url
def paint_receipt_summary(
emitter,
receipt,
chain_name: str = None,
transaction_type=None,
blockchain_endpoint: str = None,
):
tx_hash = receipt["transactionHash"].hex()
emitter.echo("OK", color="green", nl=False, bold=True)
if transaction_type:
emitter.echo(f" | {transaction_type} | {tx_hash}", color='yellow', nl=False)
else:
emitter.echo(f" | {tx_hash}", color='yellow', nl=False)
emitter.echo(f" ({receipt['gasUsed']} gas)")
emitter.echo(f"Block #{receipt['blockNumber']} | {receipt['blockHash'].hex()}")
if not chain_name:
blockchain = BlockchainInterfaceFactory.get_interface(
endpoint=blockchain_endpoint
)
chain_name = blockchain.client.chain_name
try:
url = etherscan_url(item=tx_hash, network=chain_name)
except ValueError as e:
emitter.log.info("Failed Etherscan URL construction: " + str(e))
else:
emitter.echo(f" See {url}\n")

View File

@ -1,14 +1,9 @@
from decimal import Decimal, DecimalException
from ipaddress import ip_address
from pathlib import Path
import click
from cryptography.exceptions import InternalError
from eth_utils import to_checksum_address
from nucypher_core.umbral import PublicKey
from nucypher.blockchain.eth import domains
from nucypher.blockchain.eth.token import TToken
@ -107,38 +102,19 @@ class NuCypherDomainName(click.ParamType):
return value
class UmbralPublicKeyHex(click.ParamType):
name = 'nucypher_umbral_public_key'
def __init__(self, validate: bool = True):
self.validate = bool(validate)
def convert(self, value, param, ctx):
if self.validate:
try:
_key = PublicKey.from_compressed_bytes(bytes.fromhex(value))
except (InternalError, ValueError):
self.fail(f"'{value}' is not a valid nucypher public key.")
return value
# Ethereum
EIP55_CHECKSUM_ADDRESS = ChecksumAddress()
WEI = click.IntRange(min=1, clamp=False) # TODO: Better validation for ether and wei values?
GWEI = DecimalRange(min=0)
__min_authorization = TToken(40_000, "T").to_tokens() # TODO right spot for this?
MIN_AUTHORIZATION = Decimal(__min_authorization)
STAKED_TOKENS_RANGE = DecimalRange(min=__min_authorization)
# Filesystem
EXISTING_WRITABLE_DIRECTORY = click.Path(exists=True, dir_okay=True, file_okay=False, writable=True, path_type=Path)
EXISTING_READABLE_FILE = click.Path(exists=True, dir_okay=False, file_okay=True, readable=True, path_type=Path)
# Network
NETWORK_PORT = click.IntRange(min=0, max=65535, clamp=False)
IPV4_ADDRESS = IPv4Address()
OPERATOR_IP = OperatorIPAddress()
PRE_PAYMENT_METHOD_CHOICES = click.Choice(list(PRE_PAYMENT_METHODS))

View File

@ -1,5 +1,3 @@
import os
from distutils.util import strtobool
from pathlib import Path
@ -11,10 +9,6 @@ from web3.types import BlockIdentifier
from nucypher.blockchain.eth.agents import EthereumContractAgent
from nucypher.blockchain.eth.domains import TACoDomain
from nucypher.blockchain.eth.events import EventRecord
from nucypher.blockchain.eth.interfaces import (
BlockchainInterface,
BlockchainInterfaceFactory,
)
from nucypher.blockchain.eth.registry import (
ContractRegistry,
LocalRegistrySource,
@ -27,12 +21,7 @@ from nucypher.cli.actions.auth import (
)
from nucypher.cli.literature import (
CONFIRM_OVERWRITE_EVENTS_CSV_FILE,
CONNECTING_TO_BLOCKCHAIN,
ETHERSCAN_FLAG_DISABLED_WARNING,
ETHERSCAN_FLAG_ENABLED_WARNING,
NO_HARDWARE_WALLET_WARNING,
)
from nucypher.config.constants import DEFAULT_CONFIG_ROOT
from nucypher.utilities.emitters import StdoutEmitter
from nucypher.utilities.events import write_events_to_csv_file
@ -114,32 +103,6 @@ def get_registry(
return registry
def connect_to_blockchain(
emitter: StdoutEmitter,
blockchain_endpoint: str,
debug: bool = False,
light: bool = False,
) -> BlockchainInterface:
try:
# Note: Conditional for test compatibility.
if not BlockchainInterfaceFactory.is_interface_initialized(
endpoint=blockchain_endpoint
):
BlockchainInterfaceFactory.initialize_interface(
endpoint=blockchain_endpoint, light=light, emitter=emitter
)
emitter.echo(message=CONNECTING_TO_BLOCKCHAIN)
blockchain = BlockchainInterfaceFactory.get_interface(
endpoint=blockchain_endpoint
)
return blockchain
except Exception as e:
if debug:
raise
emitter.echo(str(e), bold=True, color='red')
raise click.Abort
def get_env_bool(var_name: str, default: bool) -> bool:
if var_name in os.environ:
# TODO: which is better: to fail on an incorrect envvar, or to use the default?
@ -149,22 +112,6 @@ def get_env_bool(var_name: str, default: bool) -> bool:
return default
def ensure_config_root(config_root: Path) -> None:
"""Ensure config root exists, because we need a default place to put output files."""
config_root = config_root or DEFAULT_CONFIG_ROOT
if not config_root.exists():
config_root.mkdir(parents=True)
def deployer_pre_launch_warnings(emitter: StdoutEmitter, etherscan: bool, hw_wallet: bool) -> None:
if not hw_wallet:
emitter.echo(NO_HARDWARE_WALLET_WARNING, color='yellow')
if etherscan:
emitter.echo(ETHERSCAN_FLAG_ENABLED_WARNING, color='yellow')
else:
emitter.echo(ETHERSCAN_FLAG_DISABLED_WARNING, color='yellow')
def parse_event_filters_into_argument_filters(event_filters: Tuple[str]) -> Dict:
"""
Converts tuple of entries of the form <filter_name>=<filter_value> into a dict