# Buggy code
def events(general_config, staker_options, config_file, event_name):
    """See blockchain events associated to a staker"""

    # Setup
    emitter = setup_emitter(general_config)
    STAKEHOLDER = staker_options.create_character(emitter, config_file)

    _client_account, staking_address = select_client_account_for_staking(
        emitter=emitter,
        stakeholder=STAKEHOLDER,
        staking_address=staker_options.staking_address,
        individual_allocation=STAKEHOLDER.individual_allocation,
        force=True,
    )

    title = f" {STAKEHOLDER.staking_agent.contract_name} Events ".center(40, "-")
    emitter.echo(f"\n{title}\n", bold=True, color="green")
    if event_name:
        events = [STAKEHOLDER.staking_agent.contract.events[event_name]]
    else:
        raise click.BadOptionUsage(
            message="You must specify an event name with --event-name"
        )
        # TODO: Doesn't work for the moment
        # event_names = STAKEHOLDER.staking_agent.events.names
        # events = [STAKEHOLDER.staking_agent.contract.events[e] for e in event_names]
        # events = [e for e in events if 'staker' in e.argument_names]

    for event in events:
        emitter.echo(f"{event.event_name}:", bold=True, color="yellow")
        event_filter = event.createFilter(
            fromBlock=0, toBlock="latest", argument_filters={"staker": staking_address}
        )
        entries = event_filter.get_all_entries()
        for event_record in entries:
            emitter.echo(f"  - {EventRecord(event_record)}")


# Traceback (builtins.ValueError)
2020-09-23T14:29:04+0000 [twisted.internet.defer#critical] Unhandled error in Deferred:
2020-09-23T14:29:04+0000 [twisted.internet.defer#critical]
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/base.py", line 1283, in run
self.mainLoop()
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/base.py", line 1292, in mainLoop
self.runUntilCurrent()
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/base.py", line 913, in runUntilCurrent
call.func(*call.args, call.kw)
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/task.py", line 239, in call
d = defer.maybeDeferred(self.f, *self.a, self.kw)
--- <exception caught here> ---
File "/usr/local/lib/python3.6/dist-packages/twisted/internet/defer.py", line 151, in maybeDeferred
result = f(*args, **kw)
File "/usr/local/lib/python3.6/dist-packages/nucypher/utilities/prometheus/metrics.py", line 147, in collect_prometheus_metrics
collector.collect()
File "/usr/local/lib/python3.6/dist-packages/nucypher/utilities/prometheus/collector.py", line 77, in collect
self._collect_internal()
File "/usr/local/lib/python3.6/dist-packages/nucypher/utilities/prometheus/collector.py", line 303, in _collect_internal
events = self.event_filter.get_new_entries()
File "/usr/local/lib/python3.6/dist-packages/web3/_utils/filters.py", line 159, in get_new_entries
log_entries = self._filter_valid_entries(self.web3.eth.getFilterChanges(self.filter_id))
File "/usr/local/lib/python3.6/dist-packages/web3/eth.py", line 493, in getFilterChanges
RPC.eth_getFilterChanges, [filter_id],
File "/usr/local/lib/python3.6/dist-packages/web3/manager.py", line 153, in request_blocking
raise ValueError(response["error"])
builtins.ValueError: {'code': -32000, 'message': 'filter not found'}

# Fixed code
def events(general_config, staker_options, config_file, event_name):
    """See blockchain events associated to a staker"""

    # Setup
    emitter = setup_emitter(general_config)
    STAKEHOLDER = staker_options.create_character(emitter, config_file)

    _client_account, staking_address = select_client_account_for_staking(
        emitter=emitter,
        stakeholder=STAKEHOLDER,
        staking_address=staker_options.staking_address,
        individual_allocation=STAKEHOLDER.individual_allocation,
        force=True,
    )

    title = f" {STAKEHOLDER.staking_agent.contract_name} Events ".center(40, "-")
    emitter.echo(f"\n{title}\n", bold=True, color="green")
    if event_name:
        events = [STAKEHOLDER.staking_agent.contract.events[event_name]]
    else:
        raise click.BadOptionUsage(
            message="You must specify an event name with --event-name"
        )
        # TODO: Doesn't work for the moment
        # event_names = STAKEHOLDER.staking_agent.events.names
        # events = [STAKEHOLDER.staking_agent.contract.events[e] for e in event_names]
        # events = [e for e in events if 'staker' in e.argument_names]

    for event in events:
        emitter.echo(f"{event.event_name}:", bold=True, color="yellow")
        entries = event.getLogs(
            fromBlock=0, toBlock="latest", argument_filters={"staker": staking_address}
        )
        for event_record in entries:
            emitter.echo(f"  - {EventRecord(event_record)}")