-
Notifications
You must be signed in to change notification settings - Fork 2
/
miner.py
69 lines (56 loc) · 1.95 KB
/
miner.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
#!/usr/bin/env python
# -*- coding: utf8 -*-
import random
import string
import time
import hashlib
import pickle
import os
from version import __version__
class Miner(object):
"""
Peniscoin-Miner
"""
def __init__(self):
# read balance and last hash from wallet.dat
try:
self.load_wallet()
except IOError: # if wallet.dat don't exists
self.create_wallet()
def __str__(self):
return self.hashes + ', ' + self.seconds + ' Sekunden'
def save_wallet(self, coins, last_hash):
with open('wallet.dat', 'wb') as f:
pickle.dump(coins, f)
pickle.dump(last_hash, f)
def load_wallet(self):
with open('wallet.dat', 'rb') as f:
self.coins = pickle.load(f)
self.last_hash = pickle.load(f)
def create_wallet(self):
self.save_wallet(0, 'f6952d6eef555ddd87aca66e56b91530222d6e318414816f3ba7cf5bf694bf0f') # bootstrap hash
def mine(self):
self.start = time.clock()
self.i = 0
while True:
self.current_hash = hashlib.sha256(''.join(random.choice(string.ascii_lowercase) for x in range(5)).encode('utf-8')).hexdigest()
self.i += 1
if (self.i % 10000) == 0: # every 10.000 run
self.now = time.clock()
self.seconds = self.now - self.start # seconds the programm run
self.hashes = int(self.i / self.seconds) # hashes / seconds
if self.hashes > 1000000:
self.hashes = '{0:.2f} GHash/s'.format(self.hashes / 1000000)
elif self.hashes > 1000:
self.hashes = '{0:.2f} MHash/s'.format(self.hashes / 1000)
else:
self.hashes = '{0} Hash/s'.format(self.hashes)
os.system('cls' if os.name=='nt' else 'clear') # Unix and Windows clear screen
print(time.strftime('%Y-%m-%d %H:%M:%S ') + self.hashes + ' ' + str(self.coins) + ' Peniscoins mined in ' + '{0:.{1}f}'.format(self.seconds, 3) + ' seconds')
if self.current_hash == self.last_hash:
self.coins += 1
self.save_wallet(self.coins, self.current_hash)
if __name__ == '__main__':
print("Peniscoin-Miner Version " + __version__)
m = Miner()
m.mine()