From 30a1f1292c09dc3afb06c6745636dfc93d57df72 Mon Sep 17 00:00:00 2001 From: slush Date: Wed, 5 Sep 2012 18:13:51 +0200 Subject: [PATCH 1/1] Helper script for ./bitcoind -blocknotify --- scripts/blocknotify.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 44 insertions(+), 0 deletions(-) create mode 100755 scripts/blocknotify.sh diff --git a/scripts/blocknotify.sh b/scripts/blocknotify.sh new file mode 100755 index 0000000..0311f1a --- /dev/null +++ b/scripts/blocknotify.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# Send notification to Stratum mining instance on localhost that there's new bitcoin block +# You can use this script directly as an variable for -blocknotify argument: +# ./bitcoind -blocknotify="blocknotify.sh --password admin_password" + +import socket +import json +import sys +import argparse +import time + +start = time.time() + +parser = argparse.ArgumentParser(description='Send notification to Stratum instance about new bitcoin block.') +parser.add_argument('--password', dest='password', type=str, help='use admin password from Stratum server config') +parser.add_argument('--host', dest='host', type=str, default='localhost', help='hostname of Stratum mining instance') +parser.add_argument('--port', dest='port', type=int, default=3333, help='port of Stratum mining instance') + +args = parser.parse_args() + +if args.password == None: + parser.print_help() + sys.exit() + +message = {'id': 1, 'method': 'mining.update_block', 'params': [args.password]} + +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +s.connect((args.host, args.port)) +s.sendall(json.dumps(message)+"\n") +data = s.recv(16000) +s.close() + +for line in data.split("\n"): + if not line.strip(): + continue + + message = json.loads(line) + if message['id'] == 1: + if message['result'] == True: + print "blocknotify done in %.03f sec" % (time.time() - start) + else: + print "Error during request:", message['error'][1] + else: + print "Unexpected message from the server:", message \ No newline at end of file -- 1.7.1