2 # Send notification to Stratum mining instance on localhost that there's new novacoin block
3 # You can use this script directly as an variable for -blocknotify argument:
4 # ./novacoind -blocknotify="blocknotify.sh --password admin_password"
5 # This is also very basic example how to use Stratum protocol in native Python
15 parser = argparse.ArgumentParser(description='Send notification to Stratum instance about new novacoin block.')
16 parser.add_argument('--password', dest='password', type=str, help='use admin password from Stratum server config')
17 parser.add_argument('--host', dest='host', type=str, default='localhost', help='hostname of Stratum mining instance')
18 parser.add_argument('--port', dest='port', type=int, default=3333, help='port of Stratum mining instance')
20 args = parser.parse_args()
22 if args.password == None:
26 message = {'id': 1, 'method': 'mining.update_block', 'params': [args.password]}
29 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
30 s.connect((args.host, args.port))
31 s.sendall(json.dumps(message)+"\n")
35 print "blocknotify: Cannot connect to the pool"
38 for line in data.split("\n"):
40 # Skip last line which doesn't contain any message
43 message = json.loads(line)
44 if message['id'] == 1:
45 if message['result'] == True:
46 print "blocknotify: done in %.03f sec" % (time.time() - start)
48 print "blocknotify: Error during request:", message['error'][1]
50 print "blocknotify: Unexpected message from the server:", message