Changeset View
Changeset View
Standalone View
Standalone View
src/zmq/zmqpublishnotifier.cpp
// Copyright (c) 2015-2016 The Bitcoin Core developers | // Copyright (c) 2015-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <zmq/zmqpublishnotifier.h> | #include <zmq/zmqpublishnotifier.h> | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <primitives/blockhash.h> | |||||
#include <primitives/txid.h> | |||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <cstdarg> | #include <cstdarg> | ||||
static std::multimap<std::string, CZMQAbstractPublishNotifier *> | static std::multimap<std::string, CZMQAbstractPublishNotifier *> | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | bool CZMQAbstractPublishNotifier::SendMessage(const char *command, | ||||
/* increment memory only sequence number after sending */ | /* increment memory only sequence number after sending */ | ||||
nSequence++; | nSequence++; | ||||
return true; | return true; | ||||
} | } | ||||
bool CZMQPublishHashBlockNotifier::NotifyBlock(const CBlockIndex *pindex) { | bool CZMQPublishHashBlockNotifier::NotifyBlock(const CBlockIndex *pindex) { | ||||
uint256 hash = pindex->GetBlockHash(); | BlockHash hash = pindex->GetBlockHash(); | ||||
LogPrint(BCLog::ZMQ, "zmq: Publish hashblock %s\n", hash.GetHex()); | LogPrint(BCLog::ZMQ, "zmq: Publish hashblock %s\n", hash.GetHex()); | ||||
char data[32]; | char data[32]; | ||||
for (unsigned int i = 0; i < 32; i++) { | for (unsigned int i = 0; i < 32; i++) { | ||||
data[31 - i] = hash.begin()[i]; | data[31 - i] = hash.begin()[i]; | ||||
} | } | ||||
return SendMessage(MSG_HASHBLOCK, data, 32); | return SendMessage(MSG_HASHBLOCK, data, 32); | ||||
} | } | ||||
bool CZMQPublishHashTransactionNotifier::NotifyTransaction( | bool CZMQPublishHashTransactionNotifier::NotifyTransaction( | ||||
const CTransaction &transaction) { | const CTransaction &transaction) { | ||||
uint256 txid = transaction.GetId(); | TxId txid = transaction.GetId(); | ||||
LogPrint(BCLog::ZMQ, "zmq: Publish hashtx %s\n", txid.GetHex()); | LogPrint(BCLog::ZMQ, "zmq: Publish hashtx %s\n", txid.GetHex()); | ||||
char data[32]; | char data[32]; | ||||
for (unsigned int i = 0; i < 32; i++) { | for (unsigned int i = 0; i < 32; i++) { | ||||
data[31 - i] = txid.begin()[i]; | data[31 - i] = txid.begin()[i]; | ||||
} | } | ||||
return SendMessage(MSG_HASHTX, data, 32); | return SendMessage(MSG_HASHTX, data, 32); | ||||
} | } | ||||
Show All 15 Lines | CDataStream ss(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); | ||||
ss << block; | ss << block; | ||||
} | } | ||||
return SendMessage(MSG_RAWBLOCK, &(*ss.begin()), ss.size()); | return SendMessage(MSG_RAWBLOCK, &(*ss.begin()), ss.size()); | ||||
} | } | ||||
bool CZMQPublishRawTransactionNotifier::NotifyTransaction( | bool CZMQPublishRawTransactionNotifier::NotifyTransaction( | ||||
const CTransaction &transaction) { | const CTransaction &transaction) { | ||||
uint256 txid = transaction.GetId(); | TxId txid = transaction.GetId(); | ||||
LogPrint(BCLog::ZMQ, "zmq: Publish rawtx %s\n", txid.GetHex()); | LogPrint(BCLog::ZMQ, "zmq: Publish rawtx %s\n", txid.GetHex()); | ||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); | CDataStream ss(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()); | ||||
ss << transaction; | ss << transaction; | ||||
return SendMessage(MSG_RAWTX, &(*ss.begin()), ss.size()); | return SendMessage(MSG_RAWTX, &(*ss.begin()), ss.size()); | ||||
} | } |