Browse Source

Refactor logic for converting mempool entries to JSON

0.13
Suhas Daftuar 9 years ago
parent
commit
5ec0cde371
  1. 58
      src/rpc/blockchain.cpp

58
src/rpc/blockchain.cpp

@ -183,16 +183,27 @@ UniValue getdifficulty(const UniValue& params, bool fHelp)
return GetDifficulty(); return GetDifficulty();
} }
UniValue mempoolToJSON(bool fVerbose = false) std::string EntryDescriptionString()
{ {
if (fVerbose) return " \"size\" : n, (numeric) transaction size in bytes\n"
{ " \"fee\" : n, (numeric) transaction fee in " + CURRENCY_UNIT + "\n"
LOCK(mempool.cs); " \"modifiedfee\" : n, (numeric) transaction fee with fee deltas used for mining priority\n"
UniValue o(UniValue::VOBJ); " \"time\" : n, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT\n"
BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) " \"height\" : n, (numeric) block height when transaction entered pool\n"
{ " \"startingpriority\" : n, (numeric) priority when transaction entered pool\n"
const uint256& hash = e.GetTx().GetHash(); " \"currentpriority\" : n, (numeric) transaction priority now\n"
UniValue info(UniValue::VOBJ); " \"descendantcount\" : n, (numeric) number of in-mempool descendant transactions (including this one)\n"
" \"descendantsize\" : n, (numeric) size of in-mempool descendants (including this one)\n"
" \"descendantfees\" : n, (numeric) modified fees (see above) of in-mempool descendants (including this one)\n"
" \"depends\" : [ (array) unconfirmed transactions used as inputs for this transaction\n"
" \"transactionid\", (string) parent transaction id\n"
" ... ]\n";
}
void entryToJSON(UniValue &info, const CTxMemPoolEntry &e)
{
AssertLockHeld(mempool.cs);
info.push_back(Pair("size", (int)e.GetTxSize())); info.push_back(Pair("size", (int)e.GetTxSize()));
info.push_back(Pair("fee", ValueFromAmount(e.GetFee()))); info.push_back(Pair("fee", ValueFromAmount(e.GetFee())));
info.push_back(Pair("modifiedfee", ValueFromAmount(e.GetModifiedFee()))); info.push_back(Pair("modifiedfee", ValueFromAmount(e.GetModifiedFee())));
@ -218,6 +229,19 @@ UniValue mempoolToJSON(bool fVerbose = false)
} }
info.push_back(Pair("depends", depends)); info.push_back(Pair("depends", depends));
}
UniValue mempoolToJSON(bool fVerbose = false)
{
if (fVerbose)
{
LOCK(mempool.cs);
UniValue o(UniValue::VOBJ);
BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx)
{
const uint256& hash = e.GetTx().GetHash();
UniValue info(UniValue::VOBJ);
entryToJSON(info, e);
o.push_back(Pair(hash.ToString(), info)); o.push_back(Pair(hash.ToString(), info));
} }
return o; return o;
@ -251,20 +275,8 @@ UniValue getrawmempool(const UniValue& params, bool fHelp)
"\nResult: (for verbose = true):\n" "\nResult: (for verbose = true):\n"
"{ (json object)\n" "{ (json object)\n"
" \"transactionid\" : { (json object)\n" " \"transactionid\" : { (json object)\n"
" \"size\" : n, (numeric) transaction size in bytes\n" + EntryDescriptionString()
" \"fee\" : n, (numeric) transaction fee in " + CURRENCY_UNIT + "\n" + " }, ...\n"
" \"modifiedfee\" : n, (numeric) transaction fee with fee deltas used for mining priority\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"
" \"descendantcount\" : n, (numeric) number of in-mempool descendant transactions (including this one)\n"
" \"descendantsize\" : n, (numeric) size of in-mempool descendants (including this one)\n"
" \"descendantfees\" : n, (numeric) modified fees (see above) of in-mempool descendants (including this one)\n"
" \"depends\" : [ (array) unconfirmed transactions used as inputs for this transaction\n"
" \"transactionid\", (string) parent transaction id\n"
" ... ]\n"
" }, ...\n"
"}\n" "}\n"
"\nExamples\n" "\nExamples\n"
+ HelpExampleCli("getrawmempool", "true") + HelpExampleCli("getrawmempool", "true")

Loading…
Cancel
Save