/
ggminer.py
74 lines (63 loc) · 2.63 KB
/
ggminer.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
# ~ main file ~
#
# Provided under the MIT+LGPLv3 rules, see LICENSE file for more info
#
# This miner has been written for learning purpose only,
# heavily inspired from https://github.com/ricmoo/nightminer/
import argparse
import math
import sys
import Utils
from Miner import Miner
from Utils import log, LEVEL_INFO
def test_job(given_miner):
"""
this tests only the old version of CryptoNight (before Cn/V4) and it shows how the miner
behaves when the share has been found properly.
"""
job_msg = {
"blob": "0505ad91b1cb05473f162f06104953ab34112ea403d365f3e83f339c44328ca3dbd87ba7e62f4a00000000557056bfa4105\
abde09055edea9a0a5d3f333412a74bc96417a23bc68f8d73e405",
"job_id": "488788125594146", "target": "285c8f02"
}
blob = job_msg["blob"]
job_id = job_msg["job_id"]
target = job_msg["target"]
difficulty = math.floor((2 ** 32 - 1) / int(target, 16))
given_miner._subscription._id = "dummy"
job = given_miner._subscription.create_job(
job_id=job_id,
blob=blob,
target=target
)
log("start test job", LEVEL_INFO)
for result in job.mine(nonce_start=0x24000000):
log("Found share: " + str(result), LEVEL_INFO)
log("end test job", LEVEL_INFO)
# expected_result = {
# "id": "523289590119384", "job_id": "218283583596348", "nonce": "24000082",
# "result": "df6911d024c62d910e53b012f6b8ed0eedfaf53f60819e261207d91044258202"
# }
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description="CPU-Miner for cryptocurrency using the cryptonight\
pow algorithm and the stratum protocol (JSON RPC2)"
)
parser.add_argument("-a", "--algo", default="cryptonight", choices=["cryptonight"],
help="hashing algorithm to use for proof of work")
parser.add_argument("-o", "--url", help="stratum mining server url (eg: stratum+tcp://foobar.com:3333)")
parser.add_argument("-u", "--user", dest="username", default="", help="username for mining server")
parser.add_argument("-p", "--pass", dest="password", default="", help="password for mining server")
parser.add_argument('-t', '--thread', default="1", help="Number of mining threads to start")
parser.add_argument('-d', '--debug', help="show extra debug information")
options = parser.parse_args(sys.argv[1:])
if options.debug:
Utils.DEBUG = True
if options.url:
miner = Miner(options.url, options.username, options.password, options.algo, int(options.thread))
# dummy test
# test_job(miner)
# sys.exit(1)
miner.serve_forever()
else:
parser.print_help()