Just a python script. I don't believe I'm using much resources from the Pool with it. I'm just playing around with searching different nonce levels. I know its a long shot but bored.
import time
from threading import Thread
import requests
import binascii
import hashlib
import logging
import socket
import random
import json
import sys
from random import randint
cHeight = 0
address = 'x'
total_hashes = 0
start_time = time.time()
MAX_TRIES = 800000
RANGE_SIZE = 5000000
time.sleep(3)
starting_nonces = [
654671658,
1441279573,
2956816502,
2352401266,
472208224,
2102228740,
2881970533,
1530604631,
4024481578,
943685187,
1117786712,
907112574,
768940602,
2338731425,
2016252275,
968230052,
3875223122,
2396692019,
4257829239,
3052459910,
3455151780,
1246857225,
252414492,
600924747,
2509341451,
2781522224,
3333155104,
1501981765,
109200089,
2609829245,
2879731983,
923057322,
3913019418,
195108302,
3054800420,
330230909,
911348357,
1664488850,
1247333453,
3740086273,
163678837,
209932568,
1114669616,
4205640766,
1932628653,
3138676257,
2901946034,
716444171,
3794640743,
2136220126,
2851150130,
3097853483,
196694851,
2301273680,
1909177161,
3880828472,
1168124417,
4006964539,
3430046004,
2462160449,
3910375292,
4012812122,
1250823213,
387010416,
1890800524,
2936988664,
948732081,
2620222570,
3636302870,
1381460502,
4004889966,
2368643915,
1351807666,
2430531637,
351462716,
556429157,
2129024138,
996021571,
4188913171,
1119916358,
647049257,
1154280933,
2861704488,
182912513,
3967948799,
3509802166,
3985524095,
23457960,
2673686050,
512604690,
2702069622,
3132810089,
3248963861,
2647475594,
4257913831,
3849093226,
1238358339,
2854203594,
2253339866,
395588634,
2314779712,
2514681106,
3269269542,
1504922956,
1226995608,
2257914680,
1048593102,
2946691408,
3363226210,
1741698758,
2863877468,
820211610,
2131843282,
4207972624,
3061400381,
1557763352,
3428389213,
344153629,
2450515737,
2038601988,
3438333042,
2960795003,
1232831005,
2160632669,
2392633600,
1831357540,
82434471,
1454628133,
348502519
]
def logg(msg):
logging.basicConfig(level=logging.INFO, filename="miner-5-3-23.log", format='%(asctime)s %(message)s') # include timestamp
logging.info(msg)
def get_current_block_height():
# Returns the current network best height
r = requests.get('https://blockchain.info/latestblock')
return int(r.json()['height'])
def newBlockListener():
global cHeight
while True:
network_height = get_current_block_height()
if network_height > cHeight:
logg('[*] Network has new height %d ' % network_height)
logg('[*] Our local is %d' % cHeight)
cHeight = network_height
logg('[*] Our new local after update is %d' % cHeight)
# respect Api
time.sleep(40)
def BitcoinMiner(restart=False):
global total_hashes, start_time
if restart:
time.sleep(2)
logg('[*] Bitcoin Miner Restarted')
else:
logg('[*] Bitcoin Miner Started')
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('solo.ckpool.org', 3333))
sock.sendall(b'{"id": 1, "method": "mining.subscribe", "params": []}\n')
lines = sock.recv(1024).decode().split('\n')
print("Received from the pool: ", lines)
response = json.loads(lines[0])
sub_details, extranonce1, extranonce2_size = response['result']
sock.sendall(b'{"params": ["' + address.encode() + b'", "password"], "id": 2, "method": "mining.authorize"}\n')
response = b''
while response.count(b'\n') < 4 and not (b'mining.notify' in response): response += sock.recv(1024)
print("Received from the pool: ", response.decode())
responses = [json.loads(res) for res in response.decode().split('\n') if
len(res.strip()) > 0 and 'mining.notify' in res]
job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, clean_jobs = responses[0]['params']
target = (nbits[2:] + '00' * (int(nbits[:2], 16) - 3)).zfill(64)
extranonce2 = hex(random.randint(0, 2 ** 32 - 1))[2:].zfill(2 * extranonce2_size) # create random
coinbase = coinb1 + extranonce1 + extranonce2 + coinb2
coinbase_hash_bin = hashlib.sha256(hashlib.sha256(binascii.unhexlify(coinbase)).digest()).digest()
merkle_root = coinbase_hash_bin
for h in merkle_branch:
merkle_root = hashlib.sha256(hashlib.sha256(merkle_root + binascii.unhexlify(h)).digest()).digest()
merkle_root = binascii.hexlify(merkle_root).decode()
merkle_root = ''.join([merkle_root[i] + merkle_root[i + 1] for i in range(0, len(merkle_root), 2)][::-1])
work_on = get_current_block_height()
z = 0 # Initialize z
total_hashes = 0
start_time = time.time() # Initialize the start time
while True:
random_start = random.choice(starting_nonces)
low_range = random_start
high_range = random_start + RANGE_SIZE
for i in range(MAX_TRIES):
if cHeight > work_on:
logg('[*] Restarting Miner')
BitcoinMiner(restart=True)
break
random_nonce = randint(low_range, high_range)
nonce = hex(random_nonce)[2:].zfill(8)
blockheader = version + prevhash + merkle_root + nbits + ntime + nonce + \
'000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000'
hash = hashlib.sha256(hashlib.sha256(binascii.unhexlify(blockheader)).digest()).digest()
hash = binascii.hexlify(hash).decode()
z += 1
elapsed_time = time.time() - start_time
if elapsed_time != 0:
hashes_per_second = total_hashes / elapsed_time
else:
hashes_per_second = 0
print(f"Nonce: {nonce}")
total_hashes += 1
if hash < target:
logg('[*] New block mined')
logg('[*] success!!')
logg(blockheader)
logg('hash: {}'.format(hash))
payload = bytes('{"params": ["' + address + '", "' + job_id + '", "' + extranonce2 \
+ '", "' + ntime + '", "' + nonce + '"], "id": 1, "method": "mining.submit"}\n', 'utf-8')
sock.sendall(payload)
logg(payload)
ret = sock.recv(1024)
logg(ret)
print("Received from the pool: ", ret.decode())
return True
...
if __name__ == '__main__':
Thread(target=newBlockListener).start()
time.sleep(2)
Thread(target=BitcoinMiner).start()