interfaces: Add Chain::requestMempoolTransactions

Github-Pull: #15652
Rebased-From: 57908a739c
This commit is contained in:
João Barbosa
2019-03-27 17:00:06 +00:00
committed by MarcoFalke
parent ebf65666c2
commit ed0498af28
2 changed files with 21 additions and 0 deletions

View File

@@ -8,6 +8,7 @@
#include <chainparams.h>
#include <primitives/block.h>
#include <sync.h>
#include <txmempool.h>
#include <uint256.h>
#include <util/system.h>
#include <validation.h>
@@ -177,6 +178,13 @@ public:
LOCK(cs_main);
return GuessVerificationProgress(Params().TxData(), LookupBlockIndex(block_hash));
}
void requestMempoolTransactions(std::function<void(const CTransactionRef&)> fn) override
{
LOCK2(::cs_main, ::mempool.cs);
for (const CTxMemPoolEntry& entry : ::mempool.mapTx) {
fn(entry.GetSharedTx());
}
}
};
} // namespace

View File

@@ -16,6 +16,9 @@ class CBlock;
class CScheduler;
class uint256;
struct CBlockLocator;
class CTransaction;
using CTransactionRef = std::shared_ptr<const CTransaction>;
namespace interfaces {
@@ -127,6 +130,16 @@ public:
//! Estimate fraction of total transactions verified if blocks up to
//! the specified block hash are verified.
virtual double guessVerificationProgress(const uint256& block_hash) = 0;
//! Synchronously send TransactionAddedToMempool notifications about all
//! current mempool transactions to the specified handler and return after
//! the last one is sent. These notifications aren't coordinated with async
//! notifications sent by handleNotifications, so out of date async
//! notifications from handleNotifications can arrive during and after
//! synchronous notifications from requestMempoolTransactions. Clients need
//! to be prepared to handle this by ignoring notifications about unknown
//! removed transactions and already added new transactions.
virtual void requestMempoolTransactions(std::function<void(const CTransactionRef&)> fn) = 0;
};
//! Interface to let node manage chain clients (wallets, or maybe tools for