Skip to content

Commit

Permalink
Fixing validation and aligning with new version of click
Browse files Browse the repository at this point in the history
  • Loading branch information
valefar-on-discord committed Aug 27, 2024
1 parent 404c9f7 commit 059ee9d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
10 changes: 5 additions & 5 deletions ethstaker_deposit/cli/partial_deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,24 @@
lambda amount: validate_partial_deposit_amount(amount),
lambda: load_text(['arg_partial_deposit_amount', 'prompt'], func=FUNC_NAME),
default="32",
prompt_if_none=True,
),
default="32",
help=lambda: load_text(['arg_partial_deposit_amount', 'help'], func=FUNC_NAME),
param_decls='--amount',
prompt=lambda: load_text(['arg_partial_deposit_amount', 'prompt'], func=FUNC_NAME),
prompt=False, # the callback handles the prompt
)
@jit_option(
callback=captive_prompt_callback(
lambda address: validate_withdrawal_address(None, None, address),
lambda address: validate_withdrawal_address(None, None, address, True),
lambda: load_text(['arg_withdrawal_address', 'prompt'], func=FUNC_NAME),
lambda: load_text(['arg_withdrawal_address', 'confirm'], func=FUNC_NAME),
lambda: load_text(['arg_withdrawal_address', 'mismatch'], func=FUNC_NAME),
default="",
prompt_if_none=True,
),
default="",
help=lambda: load_text(['arg_withdrawal_address', 'help'], func=FUNC_NAME),
param_decls=['--withdrawal_address', '--execution_address', '--eth1_withdrawal_credentials'],
prompt=lambda: load_text(['arg_withdrawal_address', 'prompt'], func=FUNC_NAME),
prompt=False, # the callback handles the prompt
)
@jit_option(
default=os.getcwd(),
Expand Down
1 change: 1 addition & 0 deletions ethstaker_deposit/intl/en/utils/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"validate_withdrawal_address": {
"err_invalid_ECDSA_hex_addr": "The given execution address is not in hexadecimal encoded form.",
"err_invalid_ECDSA_hex_addr_checksum": "The given execution address is not in checksum form.",
"err_missing_address": "An address must must be providing",
"msg_ECDSA_hex_addr_withdrawal": "**[Warning] you are setting an execution address as your withdrawal address. Please ensure that you have control over this address.**"
},
"validate_partial_deposit_amount": {
Expand Down
28 changes: 14 additions & 14 deletions ethstaker_deposit/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
ETH2GWEI,
EXECUTION_ADDRESS_WITHDRAWAL_PREFIX,
GWEI_DEPOSIT_LIMIT,
MAX_DEPOSIT_AMOUNT,
MIN_DEPOSIT_AMOUNT,
)
from ethstaker_deposit.utils.crypto import SHA256
Expand Down Expand Up @@ -111,7 +110,7 @@ def validate_deposit(deposit_data_dict: Dict[str, Any], credential: Credential =
return False

# Verify deposit amount
if not MIN_DEPOSIT_AMOUNT < amount <= MAX_DEPOSIT_AMOUNT:
if not MIN_DEPOSIT_AMOUNT <= amount <= GWEI_DEPOSIT_LIMIT:
return False

# Verify deposit signature && pubkey
Expand Down Expand Up @@ -157,8 +156,10 @@ def validate_int_range(num: Any, low: int, high: int) -> int:
raise ValidationError(load_text(['err_not_positive_integer']))


def validate_withdrawal_address(cts: click.Context, param: Any, address: str) -> HexAddress:
def validate_withdrawal_address(cts: click.Context, param: Any, address: str, require: bool = False) -> HexAddress:
if address in ("", None):
if require:
raise ValidationError(load_text(['err_missing_address']))
return None
if not is_hex_address(address):
raise ValidationError(load_text(['err_invalid_ECDSA_hex_addr']))
Expand All @@ -177,21 +178,20 @@ def validate_partial_deposit_amount(amount: str) -> int:
'''
try:
decimal_ether = Decimal(amount)
except InvalidOperation:
raise ValidationError(load_text(['err_invalid_amount']))

amount_gwei = decimal_ether * Decimal(ETH2GWEI)
amount_gwei = decimal_ether * Decimal(ETH2GWEI)

if amount_gwei % 1 != 0:
raise ValidationError(load_text(['err_not_gwei_denomination']))
if amount_gwei % 1 != 0:
raise ValidationError(load_text(['err_not_gwei_denomination']))

if amount_gwei < 1 * ETH2GWEI:
raise ValidationError(load_text(['err_min_deposit']))
if amount_gwei < 1 * ETH2GWEI:
raise ValidationError(load_text(['err_min_deposit']))

if amount_gwei > GWEI_DEPOSIT_LIMIT:
raise ValidationError(load_text(['err_max_deposit']))
if amount_gwei > GWEI_DEPOSIT_LIMIT:
raise ValidationError(load_text(['err_max_deposit']))

return int(amount_gwei)
return int(amount_gwei)
except InvalidOperation:
raise ValidationError(load_text(['err_invalid_amount']))


#
Expand Down

0 comments on commit 059ee9d

Please sign in to comment.