-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
93 lines (86 loc) · 3.42 KB
/
cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import argparse
import sys
from vanityhdwallet.currencies import (
CURRENCIES,
ENGLISH,
ETH,
LANGUAGES,
PHRASE_LENGHTS,
)
from vanityhdwallet.exceptions import (
InvalidCurrencyException,
InvalidLanguageException,
InvalidPhraseLengthException,
InvalidVanityException,
)
from vanityhdwallet.helpers import (
check_vanity_validity,
generate_multi_vanity_wallet,
generate_vanity_wallet,
)
class VanityHDWallet:
def __init__(self):
parser = argparse.ArgumentParser()
parser.add_argument("command", choices=["generate", "multigenerate"])
args = parser.parse_args(sys.argv[1:2])
command = args.command
getattr(self, command)()
def generate(self):
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--vanity", type=str)
parser.add_argument("-c", "--currency", type=str, default=ETH)
parser.add_argument("-l", "--language", type=str, default=ENGLISH)
parser.add_argument("-w", "--words", type=int, default=12)
parser.add_argument("--case-sensitive", action="store_true")
args = parser.parse_args(sys.argv[2:])
vanity = args.vanity
currency = args.currency.upper()
language = args.language
words = args.words
case_sensitive = args.case_sensitive
if not currency in CURRENCIES:
raise InvalidCurrencyException(currency)
if not check_vanity_validity(currency, vanity):
raise InvalidVanityException(vanity, currency)
if not language in LANGUAGES:
raise InvalidLanguageException(language)
if not words in PHRASE_LENGHTS:
raise InvalidPhraseLengthException(words)
generate_vanity_wallet(currency, vanity, language, words, case_sensitive)
def multigenerate(self):
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--vanities", type=str)
parser.add_argument("-c", "--currencies", type=str, default=ETH)
parser.add_argument("-l", "--language", type=str, default=ENGLISH)
parser.add_argument("-w", "--words", type=int, default=12)
parser.add_argument("--case-sensitive", action="store_true")
args = parser.parse_args(sys.argv[2:])
vanities = args.vanities.split(",")
currencies = [currency.upper() for currency in args.currencies.split(",")]
language = args.language
words = args.words
case_sensitive = args.case_sensitive
if invalid_currencies := [
currency for currency in currencies if not currency in CURRENCIES
]:
raise InvalidCurrencyException(invalid_currencies[0])
if invalid_vanities_with_currencies := [
(vanity, currencies[i])
for i, vanity in enumerate(vanities)
if not check_vanity_validity(currencies[i], vanity)
]:
invalid_vanities, corresponding_currencies = zip(
*invalid_vanities_with_currencies
)
raise InvalidVanityException(
invalid_vanities[0], corresponding_currencies[0]
)
if not language in LANGUAGES:
raise InvalidLanguageException(language)
if not words in PHRASE_LENGHTS:
raise InvalidPhraseLengthException(words)
generate_multi_vanity_wallet(
currencies, vanities, language, words, case_sensitive
)
if __name__ == "__main__":
VanityHDWallet()