Skip to content

Commit

Permalink
fix[python]: add validity checks to enc-config.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Montspy committed Jun 23, 2022
1 parent 0f892df commit 4912520
Showing 1 changed file with 42 additions and 9 deletions.
51 changes: 42 additions & 9 deletions python/enc-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@

from utils import generate_paths, save_config_json, print_exception_secret

def input_while(prompt: str, validate: callable, is_abort: callable, retry_msg: str, hidden: bool = False):
from getpass import getpass
while True:
value, valid, result = None, False, None
try:
value = input(prompt) if not hidden else getpass(prompt)
if is_abort(value):
sys.exit("User aborted")
valid, result = validate(value)
if valid:
return result
except Exception as err:
pass
print(retry_msg.format(value))

# Parse CLI arguments
def parse_args():
# check for command line arguments
Expand Down Expand Up @@ -54,11 +69,20 @@ def main():

if args.mint:
address = input("Minter Address: ")
l2_pk = getpass("Layer 2 Private Key: ")
phrase = b64encode(getpass("Passphrase: ").encode("utf-8"))
royalty = input("Default Royalty (0-10): ")
nft_type = input("NFT Type [0 = ERC1155, 1 = ERC721]: ")
token = input("Fee Token [0 = ETH, 1 = LRC]: ")
try:
l2_pk = getpass("Layer 2 Private Key: ")
except Exception as err:
print_exception_secret()
sys.exit(f"Unable to get Layer 2 Private Key")
try:
phrase = b64encode(getpass("Passphrase: ").encode("utf-8"))
except Exception as err:
print_exception_secret()
sys.exit(f"Unable to encode passphrase")

royalty = input_while("Default Royalty (0-10): ", lambda x: (int(x) >= 0 and int(x) <= 10, int(x)), lambda x: x == "", "Invalid Royalty percentage: '{}'")
nft_type = input_while("NFT Type [0 = ERC1155, 1 = ERC721]: ", lambda x: (int(x) in [0,1], int(x)), lambda x: x == "", "Invalid NFT Type type: '{}'")
token = input_while("Fee Token [0 = ETH, 1 = LRC]: ", lambda x: (int(x) in [0,1], int(x)), lambda x: x == "", "Invalid Fee Token: '{}'")

config_json = {
"minter": address,
Expand All @@ -70,10 +94,19 @@ def main():

if args.transfer:
address = input("From Address: ")
l1_pk = getpass("Layer 1 Private Key: ")
l2_pk = getpass("Layer 2 Private Key: ")
phrase = b64encode(getpass("Passphrase: ").encode("utf-8"))
token = input("Fee Token [0 = ETH, 1 = LRC]: ")
try:
l1_pk = getpass("Layer 1 Private Key: ")
l2_pk = getpass("Layer 2 Private Key: ")
except Exception as err:
print_exception_secret()
sys.exit(f"Unable to get Layer 1/2 Private Keys")
try:
phrase = b64encode(getpass("Passphrase: ").encode("utf-8"))
except Exception as err:
print_exception_secret()
sys.exit(f"Unable to encode passphrase")

token = input_while("Fee Token [0 = ETH, 1 = LRC]: ", lambda x: (int(x) in [0,1], int(x)), lambda x: x == "", "Invalid Fee Token: '{}'")

config_json = {
"sender": address,
Expand Down

0 comments on commit 4912520

Please sign in to comment.