From b1436a3596800fe4f0c1f90d4ff99584ca9433d4 Mon Sep 17 00:00:00 2001 From: "Kieran R. Prasch" Date: Fri, 13 Dec 2019 14:43:58 -0800 Subject: [PATCH] Fixes #1154 - Do not present indivisible stakes to the stakeholder for division via CLI. --- nucypher/cli/actions.py | 15 ++++++++++----- nucypher/cli/characters/stake.py | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/nucypher/cli/actions.py b/nucypher/cli/actions.py index f72e57a75..b8321dc9c 100644 --- a/nucypher/cli/actions.py +++ b/nucypher/cli/actions.py @@ -366,12 +366,17 @@ def make_cli_character(character_config, return CHARACTER -def select_stake(stakeholder, emitter) -> Stake: +def select_stake(stakeholder, emitter, divisible: bool = False) -> Stake: stakes = stakeholder.all_stakes - active_stakes = sorted((stake for stake in stakes if stake.is_active), - key=lambda some_stake: some_stake.address_index_ordering_key) - enumerated_stakes = dict(enumerate(active_stakes)) - painting.paint_stakes(stakes=active_stakes, emitter=emitter) + stakes = sorted((stake for stake in stakes if stake.is_active), key=lambda s: s.address_index_ordering_key) + if divisible: + emitter.echo("NOTE: Showing divisible stakes only", color='yellow') + stakes = list(filter(lambda s: bool(s.value >= stakeholder.economics.minimum_allowed_locked*2), stakes)) + if not stakes: + emitter.echo(f"No divisible stakes found.", color='red') + raise click.Abort + enumerated_stakes = dict(enumerate(stakes)) + painting.paint_stakes(stakes=stakes, emitter=emitter) choice = click.prompt("Select Stake", type=click.IntRange(min=0, max=len(enumerated_stakes)-1)) chosen_stake = enumerated_stakes[choice] return chosen_stake diff --git a/nucypher/cli/characters/stake.py b/nucypher/cli/characters/stake.py index ef33ebd9f..a94a227b6 100644 --- a/nucypher/cli/characters/stake.py +++ b/nucypher/cli/characters/stake.py @@ -542,7 +542,7 @@ def divide(click_config, STAKEHOLDER.stakes.refresh() current_stake = STAKEHOLDER.stakes[index] else: - current_stake = select_stake(stakeholder=STAKEHOLDER, emitter=emitter) + current_stake = select_stake(stakeholder=STAKEHOLDER, emitter=emitter, divisible=True) # # Stage Stake