From 25d5c195228279b8fd891f2a7767d0529aee0ffd Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Fri, 22 Jun 2012 11:43:34 -0400 Subject: [PATCH] RPC: add 'getrawmempool', listing all transaction ids in memory pool --- src/bitcoinrpc.cpp | 18 ++++++++++++++++++ src/main.cpp | 8 ++++++++ src/main.h | 1 + 3 files changed, 27 insertions(+) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 8c3a615f..9dd67749 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -2194,6 +2194,23 @@ Value getmemorypool(const Array& params, bool fHelp) } } +Value getrawmempool(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getrawmempool\n" + "Returns all transaction ids in memory pool."); + + vector vtxid; + mempool.queryHashes(vtxid); + + Array a; + BOOST_FOREACH(const uint256& hash, vtxid) + a.push_back(hash.ToString()); + + return a; +} + Value getblockhash(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) @@ -2317,6 +2334,7 @@ static const CRPCCommand vRPCCommands[] = { "sendfrom", &sendfrom, false }, { "sendmany", &sendmany, false }, { "addmultisigaddress", &addmultisigaddress, false }, + { "getrawmempool", &getrawmempool, true }, { "getblock", &getblock, false }, { "getblockhash", &getblockhash, false }, { "gettransaction", &gettransaction, false }, diff --git a/src/main.cpp b/src/main.cpp index 2d3e3513..6765ed5f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -652,7 +652,15 @@ bool CTxMemPool::remove(CTransaction &tx) return true; } +void CTxMemPool::queryHashes(std::vector& vtxid) +{ + vtxid.clear(); + LOCK(cs); + vtxid.reserve(mapTx.size()); + for (map::iterator mi = mapTx.begin(); mi != mapTx.end(); ++mi) + vtxid.push_back((*mi).first); +} diff --git a/src/main.h b/src/main.h index 29c9a8bc..bb094ad3 100644 --- a/src/main.h +++ b/src/main.h @@ -1604,6 +1604,7 @@ public: bool fCheckInputs, bool* pfMissingInputs); bool addUnchecked(CTransaction &tx); bool remove(CTransaction &tx); + void queryHashes(std::vector& vtxid); unsigned long size() {