forked from RavenApp/Vanity-Address-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.py
80 lines (71 loc) · 2.51 KB
/
gen.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
from ravenrpc import Ravencoin # pip install ravenrpc
import sys
import os
import time
def valid_base58(s):
for c in ('0', 'O', 'l', '1'):
if c in s:
print(f'Cannot use charachter "{c}" in prefix!!')
exit()
def success_odds(prefix, ignore_case):
odds = 1
for letter in prefix[1:]:
if letter in ('o', 'l') or not ignore_case:
odds *= 58
else:
odds *= 29
return odds
def create_rvn_inst():
try:
rvn = Ravencoin(sys.argv[1], sys.argv[2])
except IndexError:
print('You must provide a valid rpc username and rpc password!')
exit()
return rvn
def get_args():
try:
prefix = sys.argv[3]
except IndexError:
print('Missing options!\n'
'Usage: `python gen.py <rpcuser> <rpcpass> <prefix> <ignore case (default True)>`')
exit()
ignore_case = sys.argv[4] if len(sys.argv) > 4 else True
if prefix[0] != 'R':
print('Please start your prefix with an "R"\n'
'Usage: `python gen.py <rpcuser> <rpcpass> <prefix> <ignore case (default True)>`')
exit()
return prefix, ignore_case, create_rvn_inst()
def validate_rvn(rvn):
if rvn.getinfo() == '':
print('Run ravend')
exit()
def display_stats(count, start, addr, prefix, odds):
addr_sec = count/(time.time() - start)
os.system('cls' if os.name == 'nt' else 'clear')
print(f'Tried {count} addresses\n'
f'Seconds Spent: {time.time() - start}\n'
f'Ave. Addresses/sec: {addr_sec}\n'
f'Lastest Address: {addr}\n'
f'Prefix: {prefix}\n'
f'You have a 1 in {odds} chance per address!\n'
f'At this rate, you will find your address in ~{odds/addr_sec/60} minutes!\n'
'To stop, press Ctrl-C', flush=True, end='')
def main():
prefix, ignore_case, rvn = get_args()
validate_rvn(rvn)
valid_base58(prefix)
start = time.time()
odds = success_odds(prefix, ignore_case)
count = 0
address = rvn.getnewaddress()['result']
try:
while not address.lower().startswith(prefix.lower()) if ignore_case else address.startswith(prefix):
address = rvn.getnewaddress()['result']
count += 1
if count % 100 == 1:
display_stats(count, start, address, prefix, odds)
except KeyboardInterrupt:
exit()
print(f'\nFound an address that starts with {prefix}!\n It is saved to your wallet. Use it freely!\n{address}')
if __name__ == '__main__':
main()