Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions data/subscribe-block.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!python3
import sys
import zmq
import struct
from binascii import hexlify, unhexlify

# Connect to the public block service.
url = 'tcp://mainnet.libbitcoin.net:9093'
if len(sys.argv) > 1:
url = sys.argv[1]

context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect(url)
socket.setsockopt(zmq.SUBSCRIBE, '')

while True:
# Collect the response in parts.
sequence = struct.unpack('<H', socket.recv())[0]
height = struct.unpack('<I', socket.recv())[0]
block_data = hexlify(socket.recv()).decode('ascii')

print '[Seq:{}] Block {} received {}'.format(
sequence, height, block_data)
22 changes: 22 additions & 0 deletions data/subscribe-heartbeat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!python3
import sys
import zmq
import struct

# Connect to the public heartbeat service.
url = 'tcp://mainnet.libbitcoin.net:9092'
if len(sys.argv) > 1:
url = sys.argv[1]

context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect(url)
socket.setsockopt(zmq.SUBSCRIBE, '')

while True:
# Collect the response in parts.
sequence = struct.unpack('<H', socket.recv())[0]
height = struct.unpack('<Q', socket.recv())[0]

print '[Seq:{}] Heartbeat received with height {}'.format(
sequence, height)
22 changes: 22 additions & 0 deletions data/subscribe-tx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!python3
import sys
import zmq
import struct
from binascii import hexlify, unhexlify

# Connect to the public transaction service.
url = 'tcp://mainnet.libbitcoin.net:9094'
if len(sys.argv) > 1:
url = sys.argv[1]

context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect(url)
socket.setsockopt(zmq.SUBSCRIBE, '')

while True:
# Collect the response in parts.
sequence = struct.unpack('<H', socket.recv())[0]
transaction = hexlify(socket.recv()).decode('ascii')

print '[Seq:{}] Transaction received: {}'.format(sequence, transaction)
2 changes: 1 addition & 1 deletion src/services/heartbeat_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void heartbeat_service::publish(zmq::socket& publisher)
return;

// [ sequence:2 ]
// [ height:4 ]
// [ height:8 ]
zmq::message message;
message.enqueue_little_endian(++sequence_);
message.enqueue_little_endian(node_.top_block().height());
Expand Down