Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
find darkcoin address of stratum pool
#!/usr/bin/python
import subprocess
import os
import simplejson
import datetime
import sys
import math
import re
from time import time
# usage sample
# cpuminer-1.3-avx-aes -t 1 -a X11 -D -P -o stratum+tcp://stratum.domain:3333 -u user -p pass 2>&1 | ./findingnemo.py logname
# to test p2pool, use ./findingnemo.py logname p2pool
def cmd_run(cmd):
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, shell=True)
out, err = p.communicate()
status = p.wait()
if not os.WIFEXITED(status) or os.WEXITSTATUS(status):
return False
return True
__b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
__b58base = len(__b58chars)
def b58decode(v, length):
""" decode v into a string of len bytes
"""
long_value = 0L
for (i, c) in enumerate(v[::-1]):
long_value += __b58chars.find(c) * (__b58base**i)
result = ''
while long_value >= 256:
div, mod = divmod(long_value, 256)
result = chr(mod) + result
long_value = div
result = chr(long_value) + result
nPad = 0
for c in v:
if c == __b58chars[0]: nPad += 1
else: break
result = chr(0)*nPad + result
if length is not None and len(result) != length:
return None
return result
def bc_address_to_hash_160(addr):
bytes = b58decode(addr, 25)
return bytes[1:21]
####
def reverse_hash(h):
# This only revert byte order, nothing more
if len(h) != 64:
raise Exception('hash must have 64 hexa chars')
# return len(h)
return ''.join([ h[56-i:64-i] for i in range(0, 64, 8) ])
####
def cap(s, l):
return s if len(s)<=l else s[62:l-3]+'...'
def lookupcoinabse2(x, prevhash):
sys.stdout.write("\n++")
sys.stdout.flush()
isinlist = False
if prevhash != 'false':
cmdcheckdarkcoin = '/usr/bin/darkcoind getblock ' + prevhash
result = cmd_run(cmdcheckdarkcoin)
if result == False :
pass
else:
print '\n-----> darkcoin : %s' % prevhash
for y in hashlist:
a = re.search(y, x)
b = '-'
c = '-'
if a:
b = hashtopool[y]
c = rlstpooladd[hashtopool[y]]
print '-----> %s\n : %s\n\t--> %s %s' % (cap(x, 100), y, b, c)
tolog = '%s %s %s %s %s\n' % (int(time()), x, b, c, prevhash)
logtestpool(tolog)
isinlist = True
if isinlist == False :
tolog = '%s %s %s %s %s\n' % (int(time()), x, b, c, prevhash)
logtestpool(tolog)
sys.stdout.write(x)
sys.stdout.flush()
################################################
def logtestpool(x):
if testpoolname:
filename = "log/" + testpoolname + ".log"
fout = open(filename, "a")
fout.write(x)
fout.close()
##############################################
p2pool = False
if len(sys.argv) > 1:
testpoolname = sys.argv[1]
if len(sys.argv) == 3 and sys.argv[2] == 'p2pool':
p2pool = True
else:
testpoolname = 'not_specified'
cmdwget = 'wget -O conf/poolname.json http://drk.poolhash.org/blocks/poolname.json'
cmd_run(cmdwget)
###
try:
finpooladd = open("conf/poolname.json", "r")
rlstfinpooladd = finpooladd.read()
rlstpooladd = simplejson.loads(rlstfinpooladd)
finpooladd.close()
except IOError, e:
print 'Error: %s' % e
print '\ndo this\n\nwget -O conf/poolname.json http://drk.poolhash.org/blocks/poolname.json\n'
exit()
hashtopool = {}
hashlist = []
for pkey in rlstpooladd:
hash160 = bc_address_to_hash_160(pkey).encode('hex_codec')
hashtopool[hash160] = pkey
hashlist.append(hash160)
xy = False
#######
n = 0
while 1:
try:
line = sys.stdin.readline()
except KeyboardInterrupt:
break
if not line:
break
# if n > 6 and n < 13:
# print line
regexpcoinabse2 = re.compile("coinbase2:(.*)")
regexpminingnotify = re.compile("method\":\"mining.notify\",\"params\":\[(.*)\]}")
regexpminingnotify2 = re.compile("params\":\[(.*)method\":\"mining.notify")
a = regexpcoinabse2.findall(line.strip().replace(' ', ''))
b = regexpminingnotify.findall(line.strip().replace(' ', ''))
c = regexpminingnotify2.findall(line.strip().replace(' ', ''))
if a:
lookupcoinabse2(a[0], 'false')
if b:
if p2pool:
lookupcoinabse2(b[0].split(',')[3].replace('"', ''), 'fasle')
else:
prevhash = reverse_hash(b[0].split(',')[1].replace('"', ''))
cbase2 = b[0].split(',')[3].replace('"', '')
lookupcoinabse2(cbase2, prevhash)
if c:
if p2pool:
lookupcoinabse2(c[0].split(',')[2].replace('"', ''), 'false')
else:
prevhash = reverse_hash(c[0].split(',')[1].replace('"', ''))
cbase2 = c[0].split(',')[3].replace('"', '')
lookupcoinabse2(cbase2, prevhash)
sys.stdout.write("..")
sys.stdout.flush()
n = n +1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.