Merge pull request #6680

d76a8ac use CBlockIndex* insted of uint256 for UpdatedBlockTip signal (Jonas Schnelli)
This commit is contained in:
Wladimir J. van der Laan 2015-09-30 11:07:54 +02:00
commit 4f44530bc3
No known key found for this signature in database
GPG key ID: 74810B012346C9A6
8 changed files with 21 additions and 17 deletions

View file

@ -2320,7 +2320,7 @@ bool ActivateBestChain(CValidationState &state, const CBlock *pblock) {
pnode->PushInventory(CInv(MSG_BLOCK, hashNewTip)); pnode->PushInventory(CInv(MSG_BLOCK, hashNewTip));
} }
// Notify external listeners about the new tip. // Notify external listeners about the new tip.
GetMainSignals().UpdatedBlockTip(hashNewTip); GetMainSignals().UpdatedBlockTip(pindexNewTip);
uiInterface.NotifyBlockTip(hashNewTip); uiInterface.NotifyBlockTip(hashNewTip);
} }
} while(pindexMostWork != chainActive.Tip()); } while(pindexMostWork != chainActive.Tip());

View file

@ -11,6 +11,7 @@
class CBlock; class CBlock;
struct CBlockLocator; struct CBlockLocator;
class CBlockIndex;
class CReserveScript; class CReserveScript;
class CTransaction; class CTransaction;
class CValidationInterface; class CValidationInterface;
@ -30,7 +31,7 @@ void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL);
class CValidationInterface { class CValidationInterface {
protected: protected:
virtual void UpdatedBlockTip(const uint256 &newHashTip) {} virtual void UpdatedBlockTip(const CBlockIndex *pindex) {}
virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock) {} virtual void SyncTransaction(const CTransaction &tx, const CBlock *pblock) {}
virtual void SetBestChain(const CBlockLocator &locator) {} virtual void SetBestChain(const CBlockLocator &locator) {}
virtual void UpdatedTransaction(const uint256 &hash) {} virtual void UpdatedTransaction(const uint256 &hash) {}
@ -46,7 +47,7 @@ protected:
struct CMainSignals { struct CMainSignals {
/** Notifies listeners of updated block chain tip */ /** 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. */ /** Notifies listeners of updated transaction data (transaction, and optionally the block it is found in. */
boost::signals2::signal<void (const CTransaction &, const CBlock *)> SyncTransaction; 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). */ /** Notifies listeners of an updated transaction without new data (for now: a coinbase potentially becoming visible). */

View file

@ -11,7 +11,7 @@ CZMQAbstractNotifier::~CZMQAbstractNotifier()
assert(!psocket); assert(!psocket);
} }
bool CZMQAbstractNotifier::NotifyBlock(const uint256 &/*hash*/) bool CZMQAbstractNotifier::NotifyBlock(const CBlockIndex * /*CBlockIndex*/)
{ {
return true; return true;
} }

View file

@ -7,7 +7,9 @@
#include "zmqconfig.h" #include "zmqconfig.h"
class CBlockIndex;
class CZMQAbstractNotifier; class CZMQAbstractNotifier;
typedef CZMQAbstractNotifier* (*CZMQNotifierFactory)(); typedef CZMQAbstractNotifier* (*CZMQNotifierFactory)();
class CZMQAbstractNotifier class CZMQAbstractNotifier
@ -30,7 +32,7 @@ public:
virtual bool Initialize(void *pcontext) = 0; virtual bool Initialize(void *pcontext) = 0;
virtual void Shutdown() = 0; virtual void Shutdown() = 0;
virtual bool NotifyBlock(const uint256 &hash); virtual bool NotifyBlock(const CBlockIndex *pindex);
virtual bool NotifyTransaction(const CTransaction &transaction); virtual bool NotifyTransaction(const CTransaction &transaction);
protected: protected:

View file

@ -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(); ) for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )
{ {
CZMQAbstractNotifier *notifier = *i; CZMQAbstractNotifier *notifier = *i;
if (notifier->NotifyBlock(hash)) if (notifier->NotifyBlock(pindex))
{ {
i++; i++;
} }

View file

@ -9,6 +9,7 @@
#include <string> #include <string>
#include <map> #include <map>
class CBlockIndex;
class CZMQAbstractNotifier; class CZMQAbstractNotifier;
class CZMQNotificationInterface : public CValidationInterface class CZMQNotificationInterface : public CValidationInterface
@ -23,7 +24,7 @@ public:
protected: // CValidationInterface protected: // CValidationInterface
void SyncTransaction(const CTransaction &tx, const CBlock *pblock); void SyncTransaction(const CTransaction &tx, const CBlock *pblock);
void UpdatedBlockTip(const uint256 &newHashTip); void UpdatedBlockTip(const CBlockIndex *pindex);
private: private:
CZMQNotificationInterface(); CZMQNotificationInterface();

View file

@ -116,8 +116,9 @@ void CZMQAbstractPublishNotifier::Shutdown()
psocket = 0; 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()); LogPrint("zmq", "Publish hash block %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++)
@ -137,18 +138,15 @@ bool CZMQPublishHashTransactionNotifier::NotifyTransaction(const CTransaction &t
return rc == 0; 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); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
{ {
LOCK(cs_main); LOCK(cs_main);
CBlock block; CBlock block;
CBlockIndex* pblockindex = mapBlockIndex[hash]; if(!ReadBlockFromDisk(block, pindex))
if(!ReadBlockFromDisk(block, pblockindex))
{ {
zmqError("Can't read block from disk"); zmqError("Can't read block from disk");
return false; return false;

View file

@ -7,6 +7,8 @@
#include "zmqabstractnotifier.h" #include "zmqabstractnotifier.h"
class CBlockIndex;
class CZMQAbstractPublishNotifier : public CZMQAbstractNotifier class CZMQAbstractPublishNotifier : public CZMQAbstractNotifier
{ {
public: public:
@ -17,7 +19,7 @@ public:
class CZMQPublishHashBlockNotifier : public CZMQAbstractPublishNotifier class CZMQPublishHashBlockNotifier : public CZMQAbstractPublishNotifier
{ {
public: public:
bool NotifyBlock(const uint256 &hash); bool NotifyBlock(const CBlockIndex *pindex);
}; };
class CZMQPublishHashTransactionNotifier : public CZMQAbstractPublishNotifier class CZMQPublishHashTransactionNotifier : public CZMQAbstractPublishNotifier
@ -29,7 +31,7 @@ public:
class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier
{ {
public: public:
bool NotifyBlock(const uint256 &hash); bool NotifyBlock(const CBlockIndex *pindex);
}; };
class CZMQPublishRawTransactionNotifier : public CZMQAbstractPublishNotifier class CZMQPublishRawTransactionNotifier : public CZMQAbstractPublishNotifier