2 # Send notification to Stratum mining instance on localhost that there's new bitcoin block
3 # You can use this script directly as an variable for -blocknotify argument:
4 # ./bitcoind -blocknotify="blocknotify.sh --password admin_password"
14 parser = argparse.ArgumentParser(description='Send notification to Stratum instance about new bitcoin block.')
15 parser.add_argument('--password', dest='password', type=str, help='use admin password from Stratum server config')
16 parser.add_argument('--host', dest='host', type=str, default='localhost', help='hostname of Stratum mining instance')
17 parser.add_argument('--port', dest='port', type=int, default=3333, help='port of Stratum mining instance')
19 args = parser.parse_args()
21 if args.password == None:
25 message = {'id': 1, 'method': 'mining.update_block', 'params': [args.password]}
27 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
28 s.connect((args.host, args.port))
29 s.sendall(json.dumps(message)+"\n")
33 for line in data.split("\n"):
37 message = json.loads(line)
38 if message['id'] == 1:
39 if message['result'] == True:
40 print "blocknotify done in %.03f sec" % (time.time() - start)
42 print "Error during request:", message['error'][1]
44 print "Unexpected message from the server:", message