mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Add verbose boolean to getrawmempool
Also changes mempool to store CTxMemPoolEntries to keep track of when they enter/exit the pool.
This commit is contained in:
@@ -153,28 +153,79 @@ Value settxfee(const Array& params, bool fHelp)
|
||||
|
||||
Value getrawmempool(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
"getrawmempool\n"
|
||||
"getrawmempool ( verbose )\n"
|
||||
"\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n"
|
||||
"\nResult:\n"
|
||||
"[ (json array of string)\n"
|
||||
"\nArguments:\n"
|
||||
"1. verbose (boolean, optional, default=false) true for a json object, false for array of transaction ids\n"
|
||||
"\nResult: (for verbose = false):\n"
|
||||
"[ (json array of string)\n"
|
||||
" \"transactionid\" (string) The transaction id\n"
|
||||
" ,...\n"
|
||||
"]\n"
|
||||
"\nResult: (for verbose = true):\n"
|
||||
"{ (json object)\n"
|
||||
" \"transactionid\" : { (json object)\n"
|
||||
" \"size\" : n, (numeric) transaction size in bytes\n"
|
||||
" \"fee\" : n, (numeric) transaction fee in bitcoins\n"
|
||||
" \"time\" : n, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT\n"
|
||||
" \"height\" : n, (numeric) block height when transaction entered pool\n"
|
||||
" \"startingpriority\" : n, (numeric) priority when transaction entered pool\n"
|
||||
" \"currentpriority\" : n, (numeric) transaction priority now\n"
|
||||
" \"depends\" : [ (array) unconfirmed transactions used as inputs for this transaction\n"
|
||||
" \"transactionid\", (string) parent transaction id\n"
|
||||
" ... ]\n"
|
||||
" }, ...\n"
|
||||
"]\n"
|
||||
"\nExamples\n"
|
||||
+ HelpExampleCli("getrawmempool", "")
|
||||
+ HelpExampleRpc("getrawmempool", "")
|
||||
+ HelpExampleCli("getrawmempool", "true")
|
||||
+ HelpExampleRpc("getrawmempool", "true")
|
||||
);
|
||||
|
||||
vector<uint256> vtxid;
|
||||
mempool.queryHashes(vtxid);
|
||||
bool fVerbose = false;
|
||||
if (params.size() > 0)
|
||||
fVerbose = params[0].get_bool();
|
||||
|
||||
Array a;
|
||||
BOOST_FOREACH(const uint256& hash, vtxid)
|
||||
a.push_back(hash.ToString());
|
||||
if (fVerbose)
|
||||
{
|
||||
LOCK(mempool.cs);
|
||||
Object o;
|
||||
BOOST_FOREACH(const PAIRTYPE(uint256, CTxMemPoolEntry)& entry, mempool.mapTx)
|
||||
{
|
||||
const uint256& hash = entry.first;
|
||||
const CTxMemPoolEntry& e = entry.second;
|
||||
Object info;
|
||||
info.push_back(Pair("size", (int)e.GetTxSize()));
|
||||
info.push_back(Pair("fee", ValueFromAmount(e.GetFee())));
|
||||
info.push_back(Pair("time", (boost::int64_t)e.GetTime()));
|
||||
info.push_back(Pair("height", (int)e.GetHeight()));
|
||||
info.push_back(Pair("startingpriority", e.GetPriority(e.GetHeight())));
|
||||
info.push_back(Pair("currentpriority", e.GetPriority(chainActive.Height())));
|
||||
const CTransaction& tx = e.GetTx();
|
||||
set<string> setDepends;
|
||||
BOOST_FOREACH(const CTxIn& txin, tx.vin)
|
||||
{
|
||||
if (mempool.exists(txin.prevout.hash))
|
||||
setDepends.insert(txin.prevout.hash.ToString());
|
||||
}
|
||||
Array depends(setDepends.begin(), setDepends.end());
|
||||
info.push_back(Pair("depends", depends));
|
||||
o.push_back(Pair(hash.ToString(), info));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector<uint256> vtxid;
|
||||
mempool.queryHashes(vtxid);
|
||||
|
||||
return a;
|
||||
Array a;
|
||||
BOOST_FOREACH(const uint256& hash, vtxid)
|
||||
a.push_back(hash.ToString());
|
||||
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
Value getblockhash(const Array& params, bool fHelp)
|
||||
|
||||
Reference in New Issue
Block a user