#!/usr/bin/env python2 import datetime import array import binascii import zmq import bitcoin.core import time import sys port = 28332 zmqContext = zmq.Context() zmqSubSocket = zmqContext.socket(zmq.SUB) zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "hashblock") zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "hashtx") zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "rawblock") zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "rawtx") zmqSubSocket.connect("tcp://127.0.0.1:%i" % port) which = 0 f = sys.stdout try: while True: msg = zmqSubSocket.recv_multipart() topic = str(msg[0]) body = msg[1] if topic == 'rawblock': # or topic == 'rawtx': continue t = time.time() nextwhich = datetime.datetime.now().strftime("%Y%m%d") if int(which) != int(nextwhich): f.close() f = open("seen-txns-blocks.%s" % (nextwhich,), "a") which = nextwhich f.write("%.2f %s %s\n" % (t, topic, binascii.hexlify(body))) f.flush() except KeyboardInterrupt: zmqContext.destroy()