Initial commit
authorslush <info@bitcoin.cz>
Sun, 9 Sep 2012 15:29:50 +0000 (17:29 +0200)
committerslush <info@bitcoin.cz>
Sun, 9 Sep 2012 15:29:50 +0000 (17:29 +0200)
LICENSE
launcher_demo.tac
scripts/blocknotify.sh

diff --git a/LICENSE b/LICENSE
index 6ea9c40..0fa0ee3 100644 (file)
--- a/LICENSE
+++ b/LICENSE
@@ -1,5 +1,5 @@
 Stratum mining - Bitcoin pool using Stratum protocol
-Copyright (C) 2012  Marek Palatinus
+Copyright (C) 2012  Marek Palatinus <info@bitcoin.cz>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as
index 5e66817..ad59d5b 100644 (file)
@@ -1,4 +1,4 @@
-# Run me with "twistd -ny launcher_demo.tac"
+# Run me with "twistd -ny launcher_demo.tac -l -"
 
 # Add conf directory to python path.
 # Configuration file is standard python module.
index 0311f1a..891b9db 100755 (executable)
@@ -2,6 +2,7 @@
 # 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"
+# This is also very basic example how to use Stratum protocol in native Python
 
 import socket
 import json
@@ -24,21 +25,26 @@ if args.password == None:
        
 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()
+try:
+    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()
+except IOError:
+    print "blocknotify: Cannot connect to the pool"
+    sys.exit()
 
 for line in data.split("\n"):
     if not line.strip():
+       # Skip last line which doesn't contain any message
         continue
 
     message = json.loads(line)
     if message['id'] == 1:
         if message['result'] == True:
-               print "blocknotify done in %.03f sec" % (time.time() - start)
+               print "blocknotify: done in %.03f sec" % (time.time() - start)
         else:
-            print "Error during request:", message['error'][1]
+            print "blocknotify: Error during request:", message['error'][1]
     else:
-        print "Unexpected message from the server:", message
\ No newline at end of file
+        print "blocknotify: Unexpected message from the server:", message