2

I call:

bitcoind -zmqpubrawtx=ipc:///tmp/bitcoind.tx.raw

or even call:

bitcoind -zmqpubhashtx=tcp://127.0.0.1:9050 - zmqpubrawtx=ipc:///tmp/bitcoind.tx.raw

where 9050 is port from bicoin config. File /tmp/bitcoind.tx.raw is empty i has lenght=0 How can I dump transactions? I read, this file is websocket and I must subscribe to it:

Client side, then, the ZeroMQ subscriber socket must have the ZMQ_SUBSCRIBE 
option set to one or either of these prefixes (for instance, just hash); 
without doing so will result in no messages arriving. Please see 
contrib/zmq/zmq_sub.py for a working example."

How can I read it programically? I try create c++ program from Python sources and https://github.com/plq/zmq.git

include

#include <iostream>
#include <cstdlib>
#include <cstring>

#include "zmq.hpp"

using std::cout;
using std::endl;

void recv_multipart(zmq::socket_t &socket) {
    int64_t more=-1;
    size_t more_size = sizeof (more);
    while(more) {
        zmq::message_t response;
        socket.recv(&response);

        std::string response_str((const char *)response.data(),
                                                             response.size());
        cout << response_str << endl;

        socket.getsockopt(ZMQ_RCVMORE, &more, &more_size);
    }
}


int main(int argc, char **argv) {
    zmq::context_t context(1);
    zmq::socket_t socket(context, ZMQ_SUB);
    socket.setsockopt(ZMQ_SUBSCRIBE, "hashblock");
    socket.setsockopt(ZMQ_SUBSCRIBE, "hashtx");
    socket.setsockopt(ZMQ_SUBSCRIBE, "rawblock");
    socket.setsockopt(ZMQ_SUBSCRIBE, "rawtx");
    //socket.connect(/*argv[2]*/"ipc:///tmp/bitcoind.tx.raw");
    socket.connect("tcp://127.0.0.1:28332");

    size_t arg_len= std::strlen("Unknown");
    zmq::message_t message(arg_len);
    std::memcpy(message.data(), "Unknown", arg_len);
    socket.send(message);        
    recv_multipart(socket);        
    return 0;
}
  • Can I use github.com/zaphoyd/websocketpp ? – Saku Jan 9 '17 at 12:58
  • It is a ZMQ socket. It is not a Websocket. Socket here refers to the old UNIX concept of a bidirectional interprocess pipe represented. ZMQ is a particular network protocol for publishing/subscribing to events. – Pieter Wuille Jan 9 '17 at 13:19
  • soc=socket(PF_INET, SOCK_STREAM, 0); ? , sai.sin_family=PF_INET; sai.sin_port=port; ?//how subscribe and read it? I need source code – Saku Jan 9 '17 at 13:32
  • You need libzmq. – Pieter Wuille Jan 9 '17 at 14:02
  • I have compiled github.com/plq/zmq and this say: zmq <SOCKET_TYPE> <URI> <MSG>; how is SOCKET_TYPE,URI and MSG for this case? – Saku Jan 9 '17 at 14:18
1

First ensure, that is 28332 port used: -zmqpubhashtx=tcp://127.0.0.1:28332 bitcoind parameter, next call python zmq_sub.py. This should work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.