@@ -302,7 +302,7 @@ UniValue getmempoolancestors(const UniValue& params, bool fHelp)
302302 " 1. \" txid\" (string, required) The transaction id (must be in mempool)\n "
303303 " 2. verbose (boolean, optional, default=false) true for a json object, false for array of transaction ids\n "
304304 " \n Result (for verbose=false):\n "
305- " [ (json array of string )\n "
305+ " [ (json array of strings )\n "
306306 " \" transactionid\" (string) The transaction id of an in-mempool ancestor transaction\n "
307307 " ,...\n "
308308 " ]\n "
@@ -356,6 +356,70 @@ UniValue getmempoolancestors(const UniValue& params, bool fHelp)
356356 }
357357}
358358
359+ UniValue getmempooldescendants (const UniValue& params, bool fHelp )
360+ {
361+ if (fHelp || params.size () < 1 || params.size () > 2 ) {
362+ throw runtime_error (
363+ " getmempooldescendants txid (verbose)\n "
364+ " \n If txid is in the mempool, returns all in-mempool descendants.\n "
365+ " \n Arguments:\n "
366+ " 1. \" txid\" (string, required) The transaction id (must be in mempool)\n "
367+ " 2. verbose (boolean, optional, default=false) true for a json object, false for array of transaction ids\n "
368+ " \n Result (for verbose=false):\n "
369+ " [ (json array of strings)\n "
370+ " \" transactionid\" (string) The transaction id of an in-mempool descendant transaction\n "
371+ " ,...\n "
372+ " ]\n "
373+ " \n Result (for verbose=true):\n "
374+ " { (json object)\n "
375+ " \" transactionid\" : { (json object)\n "
376+ + EntryDescriptionString ()
377+ + " }, ...\n "
378+ " }\n "
379+ " \n Examples\n "
380+ + HelpExampleCli (" getmempooldescendants" , " \" mytxid\" " )
381+ + HelpExampleRpc (" getmempooldescendants" , " \" mytxid\" " )
382+ );
383+ }
384+
385+ bool fVerbose = false ;
386+ if (params.size () > 1 )
387+ fVerbose = params[1 ].get_bool ();
388+
389+ uint256 hash = ParseHashV (params[0 ], " parameter 1" );
390+
391+ LOCK (mempool.cs );
392+
393+ CTxMemPool::txiter it = mempool.mapTx .find (hash);
394+ if (it == mempool.mapTx .end ()) {
395+ throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Transaction not in mempool" );
396+ }
397+
398+ CTxMemPool::setEntries setDescendants;
399+ mempool.CalculateDescendants (it, setDescendants);
400+ // CTxMemPool::CalculateDescendants will include the given tx
401+ setDescendants.erase (it);
402+
403+ if (!fVerbose ) {
404+ UniValue o (UniValue::VARR);
405+ BOOST_FOREACH (CTxMemPool::txiter descendantIt, setDescendants) {
406+ o.push_back (descendantIt->GetTx ().GetHash ().ToString ());
407+ }
408+
409+ return o;
410+ } else {
411+ UniValue o (UniValue::VOBJ);
412+ BOOST_FOREACH (CTxMemPool::txiter descendantIt, setDescendants) {
413+ const CTxMemPoolEntry &e = *descendantIt;
414+ const uint256& hash = e.GetTx ().GetHash ();
415+ UniValue info (UniValue::VOBJ);
416+ entryToJSON (info, e);
417+ o.push_back (Pair (hash.ToString (), info));
418+ }
419+ return o;
420+ }
421+ }
422+
359423UniValue getblockhash (const UniValue& params, bool fHelp )
360424{
361425 if (fHelp || params.size () != 1 )
@@ -1081,6 +1145,7 @@ static const CRPCCommand commands[] =
10811145 { " blockchain" , " getchaintips" , &getchaintips, true },
10821146 { " blockchain" , " getdifficulty" , &getdifficulty, true },
10831147 { " blockchain" , " getmempoolancestors" , &getmempoolancestors, true },
1148+ { " blockchain" , " getmempooldescendants" , &getmempooldescendants, true },
10841149 { " blockchain" , " getmempoolinfo" , &getmempoolinfo, true },
10851150 { " blockchain" , " getrawmempool" , &getrawmempool, true },
10861151 { " blockchain" , " gettxout" , &gettxout, true },
0 commit comments