mirror of
https://gitlab.com/pulsechaincom/staking-deposit-cli.git
synced 2025-01-03 01:27:39 +00:00
Apply PR feedback by catching the exceptions. Improve error handling and messages.
This commit is contained in:
parent
2cd1d999ea
commit
aae55a6886
@ -179,7 +179,11 @@ def generate_bls_to_execution_change(
|
|||||||
|
|
||||||
# Check if the given old bls_withdrawal_credentials is as same as the mnemonic generated
|
# Check if the given old bls_withdrawal_credentials is as same as the mnemonic generated
|
||||||
for i, credential in enumerate(credentials.credentials):
|
for i, credential in enumerate(credentials.credentials):
|
||||||
validate_bls_withdrawal_credentials_matching(bls_withdrawal_credentials_list[i], credential)
|
try:
|
||||||
|
validate_bls_withdrawal_credentials_matching(bls_withdrawal_credentials_list[i], credential)
|
||||||
|
except ValidationError as e:
|
||||||
|
click.echo('\n[Error] ' + str(e))
|
||||||
|
return
|
||||||
|
|
||||||
btec_file = credentials.export_bls_to_execution_change_json(bls_to_execution_changes_folder, validator_indices)
|
btec_file = credentials.export_bls_to_execution_change_json(bls_to_execution_changes_folder, validator_indices)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"arg_bls_withdrawal_credentials_list": {
|
"arg_bls_withdrawal_credentials_list": {
|
||||||
"help": "A list of 32-byte old BLS withdrawal credentials of the certain validator(s)",
|
"help": "A list of 32-byte old BLS withdrawal credentials of the certain validator(s)",
|
||||||
"prompt": "Please enter a list of the old BLS withdrawal credentials of your validator(s). Split multiple items with whitespaces or commas."
|
"prompt": "Please enter a list of the old BLS withdrawal credentials of your validator(s). Split multiple items with whitespaces or commas. The withdrawal credentials are in hexadecimal encoded form."
|
||||||
},
|
},
|
||||||
"arg_validator_start_index": {
|
"arg_validator_start_index": {
|
||||||
"help": "The index position for the keys to start generating withdrawal credentials in ERC-2334 format",
|
"help": "The index position for the keys to start generating withdrawal credentials in ERC-2334 format",
|
||||||
|
@ -25,5 +25,12 @@
|
|||||||
},
|
},
|
||||||
"verify_bls_to_execution_change_json": {
|
"verify_bls_to_execution_change_json": {
|
||||||
"msg_bls_to_execution_change_verification": "Verifying your BLSToExecutionChange file:\t"
|
"msg_bls_to_execution_change_verification": "Verifying your BLSToExecutionChange file:\t"
|
||||||
|
},
|
||||||
|
"normalize_bls_withdrawal_credentials_to_bytes" :{
|
||||||
|
"err_incorrect_hex_form": "The given input is not in hexadecimal encoded form."
|
||||||
|
|
||||||
|
},
|
||||||
|
"normalize_input_list": {
|
||||||
|
"err_incorrect_list": "The given input should be a list of the old BLS withdrawal credentials of your validator(s). Split multiple items with whitespaces or commas."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ def captive_prompt_callback(
|
|||||||
raise ValidationError(confirmation_mismatch_msg())
|
raise ValidationError(confirmation_mismatch_msg())
|
||||||
return processed_input
|
return processed_input
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
click.echo(e)
|
click.echo('\n[Error] ' + str(e))
|
||||||
user_input = click.prompt(prompt(), hide_input=hide_input)
|
user_input = click.prompt(prompt(), hide_input=hide_input)
|
||||||
return callback
|
return callback
|
||||||
|
|
||||||
|
@ -210,7 +210,10 @@ def normalize_bls_withdrawal_credentials_to_bytes(bls_withdrawal_credentials: st
|
|||||||
if bls_withdrawal_credentials.startswith('0x'):
|
if bls_withdrawal_credentials.startswith('0x'):
|
||||||
bls_withdrawal_credentials = bls_withdrawal_credentials[2:]
|
bls_withdrawal_credentials = bls_withdrawal_credentials[2:]
|
||||||
|
|
||||||
bls_withdrawal_credentials_bytes = bytes.fromhex(bls_withdrawal_credentials)
|
try:
|
||||||
|
bls_withdrawal_credentials_bytes = bytes.fromhex(bls_withdrawal_credentials)
|
||||||
|
except Exception:
|
||||||
|
raise ValidationError(load_text(['err_incorrect_hex_form']) + '\n')
|
||||||
return bls_withdrawal_credentials_bytes
|
return bls_withdrawal_credentials_bytes
|
||||||
|
|
||||||
|
|
||||||
@ -226,21 +229,25 @@ def validate_bls_withdrawal_credentials(bls_withdrawal_credentials: str) -> byte
|
|||||||
bls_withdrawal_credentials_bytes = normalize_bls_withdrawal_credentials_to_bytes(bls_withdrawal_credentials)
|
bls_withdrawal_credentials_bytes = normalize_bls_withdrawal_credentials_to_bytes(bls_withdrawal_credentials)
|
||||||
|
|
||||||
if is_eth1_address_withdrawal_credentials(bls_withdrawal_credentials_bytes):
|
if is_eth1_address_withdrawal_credentials(bls_withdrawal_credentials_bytes):
|
||||||
raise ValidationError('\n' + load_text(['err_is_already_eth1_form']) + '\n')
|
raise ValidationError(load_text(['err_is_already_eth1_form']) + '\n')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
assert len(bls_withdrawal_credentials_bytes) == 32
|
assert len(bls_withdrawal_credentials_bytes) == 32
|
||||||
assert bls_withdrawal_credentials_bytes[:1] == BLS_WITHDRAWAL_PREFIX
|
assert bls_withdrawal_credentials_bytes[:1] == BLS_WITHDRAWAL_PREFIX
|
||||||
except (ValueError, AssertionError):
|
except (ValueError, AssertionError):
|
||||||
raise ValidationError('\n' + load_text(['err_not_bls_form']) + '\n')
|
raise ValidationError(load_text(['err_not_bls_form']) + '\n')
|
||||||
|
|
||||||
return bls_withdrawal_credentials_bytes
|
return bls_withdrawal_credentials_bytes
|
||||||
|
|
||||||
|
|
||||||
def normalize_input_list(input: str) -> Sequence[str]:
|
def normalize_input_list(input: str) -> Sequence[str]:
|
||||||
input = input.strip('[({})]')
|
try:
|
||||||
input = re.sub(' +', ' ', input)
|
input = input.strip('[({})]')
|
||||||
return re.split(r'; |, | |,|;', input)
|
input = re.sub(' +', ' ', input)
|
||||||
|
result = re.split(r'; |, | |,|;', input)
|
||||||
|
except Exception:
|
||||||
|
raise ValidationError(load_text(['err_incorrect_list']) + '\n')
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def validate_bls_withdrawal_credentials_list(input_bls_withdrawal_credentials_list: str) -> Sequence[bytes]:
|
def validate_bls_withdrawal_credentials_list(input_bls_withdrawal_credentials_list: str) -> Sequence[bytes]:
|
||||||
@ -256,4 +263,4 @@ def validate_validator_indices(input_validator_indices: str) -> Sequence[int]:
|
|||||||
|
|
||||||
def validate_bls_withdrawal_credentials_matching(bls_withdrawal_credentials: bytes, credential: Credential) -> None:
|
def validate_bls_withdrawal_credentials_matching(bls_withdrawal_credentials: bytes, credential: Credential) -> None:
|
||||||
if bls_withdrawal_credentials[1:] != SHA256(credential.withdrawal_pk)[1:]:
|
if bls_withdrawal_credentials[1:] != SHA256(credential.withdrawal_pk)[1:]:
|
||||||
raise ValidationError('\n' + load_text(['err_not_matching']) + '\n')
|
raise ValidationError(load_text(['err_not_matching']) + '\n')
|
||||||
|
Loading…
Reference in New Issue
Block a user