forked from m0mchil/poclbm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
poclbm.py
171 lines (152 loc) · 3.87 KB
/
poclbm.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/python
import sys
if sys.version_info < (2, 7):
print 'Sorry: you must use Python 2.7'
sys.exit(1)
try:
import pyopencl
cl = True
except ImportError:
cl = False
import argparse
import logging
from BitcoinMiner import *
from DeviceFinder import *
PROGRAM_VERSION = 2
PROGRAM_NAME = 'OpenPyCoiner Version %d' % PROGRAM_VERSION
if __name__ == '__main__':
# start the logging framework
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s | %(levelname)s | %(name)s | %(message)s')
log = logging.getLogger("Main")
# first show a list of known warnings
if not cl:
print 'WARNING: No OpenCL libary found. Please install "pyOpenCL" to enable GPU prossesing\n'
if sys.subversion[0] != 'CPython':
print 'WARNING: Not running on "CPython", this is untested\n'
# set op the argument parser
parser = argparse.ArgumentParser(
description='A OpenCL client for BitCoin minning',
epilog='See https://github.com/TheBiggerGuy/poclbm for more'
)
parser.add_argument('--version', action='version', version=PROGRAM_NAME)
parser.add_argument(
'--user',
action='store',
nargs='?',
default='bitcoin',
type=str,
help='User name',
dest='user'
)
parser.add_argument(
'--password',
action='store',
nargs='?',
default='password',
type=str,
help='Password',
dest='password'
)
parser.add_argument(
'--host',
action='store',
nargs='?',
default='localhost',
type=str,
help='Address to the server',
dest='host'
)
parser.add_argument(
'--port',
action='store',
nargs='?',
default=8332,
type=int,
help='Server port number',
dest='port'
)
parser.add_argument(
'--secure',
action='store_true',
help='Force https (SSL) connection',
dest='secure'
)
parser.add_argument(
'--device',
action='store',
nargs='*',
default=[0],
type=int,
help='Device number, see --list for a list of devices',
dest='devices'
)
parser.add_argument(
'--list',
action='store_true',
help='List all devices',
dest='list'
)
parser.add_argument(
'--verbose',
action='store_true',
help='Show alot of rubish',
dest='verbose'
)
args = parser.parse_args()
# check port number
if args.port < 0 or args.port > 0xFFFF:
print 'Invalid port (0 <= port => 4,294,967,296)'
parser.print_usage()
sys.exit(1)
# search for all devices
sysDevices = DeviceList()
# only asked to list devices
if args.list:
sysDevices.showAllDevices()
sys.exit(0)
# invalid device number given
for device in args.devices:
if device < 0 or device >= len(sysDevices):
print 'Please select a real device (0 to %d)' % (len(sysDevices)-1)
sysDevices.showAllDevices()
sys.exit(1)
# TODO
for device in args.devices:
if sysDevices[device].getType() != Device.TYPE_OPENCL:
print 'Sorry only OpenCL devices supported currently'
sysDevices.showAllDevices()
sys.exit(1)
# Main loop ##################################################################
print "-"*76
miners = []
try:
# build all the minners
for device in args.devices:
miner = BitcoinMiner(
sysDevices[device].getOpenCL(),
args.host,
args.user,
args.password,
args.port,
secure=args.secure,
userAgentString=PROGRAM_NAME
)
miners.append(miner)
# start all the minners
for miner in miners:
miner.mine()
except KeyboardInterrupt:
print # try to clean the carret
log.warn('Ctrl-C - Exiting ...')
sys.exit(0)
finally:
# kill and wait for all the minners to die
for miner in miners:
if miner != None:
miner.exit()
while not miner.isStopped:
pass
log.warn('a minner died :(')
log.warn('finished')
print "-"*76
print "The End"