Skip to content

Commit

Permalink
Merge pull request #6680
Browse files Browse the repository at this point in the history
d76a8ac use CBlockIndex* insted of uint256 for UpdatedBlockTip signal (Jonas Schnelli)
  • Loading branch information
laanwj committed Sep 30, 2015
2 parents 3f74cd2 + d76a8ac commit 4f44530
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,7 @@ bool ActivateBestChain(CValidationState &state, const CBlock *pblock) {
pnode->PushInventory(CInv(MSG_BLOCK, hashNewTip));
}
// Notify external listeners about the new tip.
GetMainSignals().UpdatedBlockTip(hashNewTip);
GetMainSignals().UpdatedBlockTip(pindexNewTip);
uiInterface.NotifyBlockTip(hashNewTip);
}
} while(pindexMostWork != chainActive.Tip());
Expand Down
5 changes: 3 additions & 2 deletions src/validationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class CBlock;
struct CBlockLocator;
class CBlockIndex;
class CReserveScript;
class CTransaction;
class CValidationInterface;
Expand All @@ -30,7 +31,7 @@ void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL);

class CValidationInterface {
protected:
virtual void UpdatedBlockTip(const uint256 &newHashTip) {}
virtual void UpdatedBlockTip(const CBlockIndex *pindex) {}
virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock) {}
virtual void SetBestChain(const CBlockLocator &locator) {}
virtual void UpdatedTransaction(const uint256 &hash) {}
Expand All @@ -46,7 +47,7 @@ class CValidationInterface {

struct CMainSignals {
/** Notifies listeners of updated block chain tip */
boost::signals2::signal<void (const uint256 &)> UpdatedBlockTip;
boost::signals2::signal<void (const CBlockIndex *)> UpdatedBlockTip;
/** Notifies listeners of updated transaction data (transaction, and optionally the block it is found in. */
boost::signals2::signal<void (const CTransaction &, const CBlock *)> SyncTransaction;
/** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */
Expand Down
2 changes: 1 addition & 1 deletion src/zmq/zmqabstractnotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CZMQAbstractNotifier::~CZMQAbstractNotifier()
assert(!psocket);
}

bool CZMQAbstractNotifier::NotifyBlock(const uint256 &/*hash*/)
bool CZMQAbstractNotifier::NotifyBlock(const CBlockIndex * /*CBlockIndex*/)
{
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion src/zmq/zmqabstractnotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

#include "zmqconfig.h"

class CBlockIndex;
class CZMQAbstractNotifier;

typedef CZMQAbstractNotifier* (*CZMQNotifierFactory)();

class CZMQAbstractNotifier
Expand All @@ -30,7 +32,7 @@ class CZMQAbstractNotifier
virtual bool Initialize(void *pcontext) = 0;
virtual void Shutdown() = 0;

virtual bool NotifyBlock(const uint256 &hash);
virtual bool NotifyBlock(const CBlockIndex *pindex);
virtual bool NotifyTransaction(const CTransaction &transaction);

protected:
Expand Down
4 changes: 2 additions & 2 deletions src/zmq/zmqnotificationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ void CZMQNotificationInterface::Shutdown()
}
}

void CZMQNotificationInterface::UpdatedBlockTip(const uint256 &hash)
void CZMQNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindex)
{
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )
{
CZMQAbstractNotifier *notifier = *i;
if (notifier->NotifyBlock(hash))
if (notifier->NotifyBlock(pindex))
{
i++;
}
Expand Down
3 changes: 2 additions & 1 deletion src/zmq/zmqnotificationinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include <map>

class CBlockIndex;
class CZMQAbstractNotifier;

class CZMQNotificationInterface : public CValidationInterface
Expand All @@ -23,7 +24,7 @@ class CZMQNotificationInterface : public CValidationInterface

protected: // CValidationInterface
void SyncTransaction(const CTransaction &tx, const CBlock *pblock);
void UpdatedBlockTip(const uint256 &newHashTip);
void UpdatedBlockTip(const CBlockIndex *pindex);

private:
CZMQNotificationInterface();
Expand Down
12 changes: 5 additions & 7 deletions src/zmq/zmqpublishnotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ void CZMQAbstractPublishNotifier::Shutdown()
psocket = 0;
}

bool CZMQPublishHashBlockNotifier::NotifyBlock(const uint256 &hash)
bool CZMQPublishHashBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
{
uint256 hash = pindex->GetBlockHash();
LogPrint("zmq", "Publish hash block %s\n", hash.GetHex());
char data[32];
for (unsigned int i = 0; i < 32; i++)
Expand All @@ -137,18 +138,15 @@ bool CZMQPublishHashTransactionNotifier::NotifyTransaction(const CTransaction &t
return rc == 0;
}

bool CZMQPublishRawBlockNotifier::NotifyBlock(const uint256 &hash)
bool CZMQPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
{
LogPrint("zmq", "Publish raw block %s\n", hash.GetHex());
LogPrint("zmq", "Publish raw block %s\n", pindex->GetBlockHash().GetHex());

CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
{
LOCK(cs_main);

CBlock block;
CBlockIndex* pblockindex = mapBlockIndex[hash];

if(!ReadBlockFromDisk(block, pblockindex))
if(!ReadBlockFromDisk(block, pindex))
{
zmqError("Can't read block from disk");
return false;
Expand Down
6 changes: 4 additions & 2 deletions src/zmq/zmqpublishnotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "zmqabstractnotifier.h"

class CBlockIndex;

class CZMQAbstractPublishNotifier : public CZMQAbstractNotifier
{
public:
Expand All @@ -17,7 +19,7 @@ class CZMQAbstractPublishNotifier : public CZMQAbstractNotifier
class CZMQPublishHashBlockNotifier : public CZMQAbstractPublishNotifier
{
public:
bool NotifyBlock(const uint256 &hash);
bool NotifyBlock(const CBlockIndex *pindex);
};

class CZMQPublishHashTransactionNotifier : public CZMQAbstractPublishNotifier
Expand All @@ -29,7 +31,7 @@ class CZMQPublishHashTransactionNotifier : public CZMQAbstractPublishNotifier
class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier
{
public:
bool NotifyBlock(const uint256 &hash);
bool NotifyBlock(const CBlockIndex *pindex);
};

class CZMQPublishRawTransactionNotifier : public CZMQAbstractPublishNotifier
Expand Down

0 comments on commit 4f44530

Please sign in to comment.