From 1f6254441ba05487bad76e1101ad55dc7c99a311 Mon Sep 17 00:00:00 2001 From: Dalena Date: Tue, 12 Nov 2024 16:19:52 -0600 Subject: [PATCH 1/6] fix: token flag for cluster pay --- silverback/_cli.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/silverback/_cli.py b/silverback/_cli.py index 043ff5e6..cec07627 100644 --- a/silverback/_cli.py +++ b/silverback/_cli.py @@ -6,6 +6,7 @@ import click import yaml # type: ignore[import-untyped] +from ape import Contract from ape.cli import ( AccountAliasPromptChoice, ConnectedProviderCommand, @@ -546,6 +547,15 @@ def create_payment_stream( sm = platform.get_stream_manager(network.chain_id) product = configuration.get_product_code(account.address, cluster.id) + if token: + try: + token = Contract(token).symbol() + accepted_tokens = platform.get_accepted_tokens(network.chain_id) + if token not in accepted_tokens: + raise click.UsageError(f"Token symbol '{token}' not found in token list.") + except ValueError: + raise click.UsageError(f"Token address '{token}' not found.") + if not token: accepted_tokens = platform.get_accepted_tokens(network.chain_id) token = accepted_tokens.get( From 67fcf969c0030da78a081fd8b277fa612b2e3397 Mon Sep 17 00:00:00 2001 From: Dalena Date: Tue, 12 Nov 2024 16:49:04 -0600 Subject: [PATCH 2/6] fix: check token symbol in list --- silverback/_cli.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/silverback/_cli.py b/silverback/_cli.py index cec07627..a7e85db1 100644 --- a/silverback/_cli.py +++ b/silverback/_cli.py @@ -547,17 +547,18 @@ def create_payment_stream( sm = platform.get_stream_manager(network.chain_id) product = configuration.get_product_code(account.address, cluster.id) + accepted_tokens = platform.get_accepted_tokens(network.chain_id) if token: try: - token = Contract(token).symbol() - accepted_tokens = platform.get_accepted_tokens(network.chain_id) - if token not in accepted_tokens: - raise click.UsageError(f"Token symbol '{token}' not found in token list.") + token_symbol = Contract(token).symbol() + token = accepted_tokens.get(token_symbol) except ValueError: - raise click.UsageError(f"Token address '{token}' not found.") + token = accepted_tokens.get(token) + + if token is None: + raise click.UsageError("Token not found in accepted tokens.") if not token: - accepted_tokens = platform.get_accepted_tokens(network.chain_id) token = accepted_tokens.get( click.prompt( "Select one of the following tokens to fund your stream with", From 041954f573ee9fc32e1442673225e4e54d215dc0 Mon Sep 17 00:00:00 2001 From: Dalena Date: Thu, 14 Nov 2024 10:30:45 -0600 Subject: [PATCH 3/6] fix: use convert to check for address --- silverback/_cli.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/silverback/_cli.py b/silverback/_cli.py index a7e85db1..62e79094 100644 --- a/silverback/_cli.py +++ b/silverback/_cli.py @@ -6,7 +6,7 @@ import click import yaml # type: ignore[import-untyped] -from ape import Contract +from ape import Contract, convert from ape.cli import ( AccountAliasPromptChoice, ConnectedProviderCommand, @@ -15,8 +15,9 @@ ape_cli_context, network_option, ) -from ape.exceptions import Abort, ApeException +from ape.exceptions import Abort, ApeException, ConversionError from ape.logging import LogLevel +from ape.types import AddressType from silverback._click_ext import ( SectionedHelpGroup, @@ -550,13 +551,14 @@ def create_payment_stream( accepted_tokens = platform.get_accepted_tokens(network.chain_id) if token: try: + convert(token, AddressType) token_symbol = Contract(token).symbol() token = accepted_tokens.get(token_symbol) - except ValueError: + except ConversionError: token = accepted_tokens.get(token) if token is None: - raise click.UsageError("Token not found in accepted tokens.") + raise click.UsageError(f"Token not found in {accepted_tokens}.") if not token: token = accepted_tokens.get( From 4c5270d2a34bc2d7a0cf5e4bea40de71f4180d14 Mon Sep 17 00:00:00 2001 From: Dalena Date: Thu, 14 Nov 2024 11:09:19 -0600 Subject: [PATCH 4/6] fix: accepted tokens --- silverback/_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/silverback/_cli.py b/silverback/_cli.py index 62e79094..b28733a6 100644 --- a/silverback/_cli.py +++ b/silverback/_cli.py @@ -558,7 +558,7 @@ def create_payment_stream( token = accepted_tokens.get(token) if token is None: - raise click.UsageError(f"Token not found in {accepted_tokens}.") + raise click.UsageError(f"Token not found in accepted tokens: {accepted_tokens}.") if not token: token = accepted_tokens.get( From eed6e2d2e9669c31aea51a2d4e7920df85bebb10 Mon Sep 17 00:00:00 2001 From: Dalena Date: Tue, 19 Nov 2024 18:15:02 -0500 Subject: [PATCH 5/6] fix: add finally --- silverback/_cli.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/silverback/_cli.py b/silverback/_cli.py index b28733a6..b9047469 100644 --- a/silverback/_cli.py +++ b/silverback/_cli.py @@ -553,9 +553,10 @@ def create_payment_stream( try: convert(token, AddressType) token_symbol = Contract(token).symbol() - token = accepted_tokens.get(token_symbol) except ConversionError: - token = accepted_tokens.get(token) + token_symbol = token + finally: + token = accepted_tokens.get(token_symbol) if token is None: raise click.UsageError(f"Token not found in accepted tokens: {accepted_tokens}.") From 1cfbd19b459cd7202f6953323d69507da88b346c Mon Sep 17 00:00:00 2001 From: El De-dog-lo <3859395+fubuloubu@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:37:17 -0500 Subject: [PATCH 6/6] refactor: use else case, not opposite if --- silverback/_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/silverback/_cli.py b/silverback/_cli.py index b9047469..d5b14aa1 100644 --- a/silverback/_cli.py +++ b/silverback/_cli.py @@ -561,7 +561,7 @@ def create_payment_stream( if token is None: raise click.UsageError(f"Token not found in accepted tokens: {accepted_tokens}.") - if not token: + else: token = accepted_tokens.get( click.prompt( "Select one of the following tokens to fund your stream with",