@@ -183,6 +183,60 @@ UniValue getdifficulty(const UniValue& params, bool fHelp)
183
183
return GetDifficulty ();
184
184
}
185
185
186
+ std::string EntryDescriptionString ()
187
+ {
188
+ return " \" size\" : n, (numeric) transaction size in bytes\n "
189
+ " \" fee\" : n, (numeric) transaction fee in " + CURRENCY_UNIT + " \n "
190
+ " \" modifiedfee\" : n, (numeric) transaction fee with fee deltas used for mining priority\n "
191
+ " \" time\" : n, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT\n "
192
+ " \" height\" : n, (numeric) block height when transaction entered pool\n "
193
+ " \" startingpriority\" : n, (numeric) priority when transaction entered pool\n "
194
+ " \" currentpriority\" : n, (numeric) transaction priority now\n "
195
+ " \" descendantcount\" : n, (numeric) number of in-mempool descendant transactions (including this one)\n "
196
+ " \" descendantsize\" : n, (numeric) size of in-mempool descendants (including this one)\n "
197
+ " \" descendantfees\" : n, (numeric) modified fees (see above) of in-mempool descendants (including this one)\n "
198
+ " \" ancestorcount\" : n, (numeric) number of in-mempool ancestor transactions (including this one)\n "
199
+ " \" ancestorsize\" : n, (numeric) size of in-mempool ancestors (including this one)\n "
200
+ " \" ancestorfees\" : n, (numeric) modified fees (see above) of in-mempool ancestors (including this one)\n "
201
+ " \" depends\" : [ (array) unconfirmed transactions used as inputs for this transaction\n "
202
+ " \" transactionid\" , (string) parent transaction id\n "
203
+ " ... ]\n " ;
204
+ }
205
+
206
+ void entryToJSON (UniValue &info, const CTxMemPoolEntry &e)
207
+ {
208
+ AssertLockHeld (mempool.cs );
209
+
210
+ info.push_back (Pair (" size" , (int )e.GetTxSize ()));
211
+ info.push_back (Pair (" fee" , ValueFromAmount (e.GetFee ())));
212
+ info.push_back (Pair (" modifiedfee" , ValueFromAmount (e.GetModifiedFee ())));
213
+ info.push_back (Pair (" time" , e.GetTime ()));
214
+ info.push_back (Pair (" height" , (int )e.GetHeight ()));
215
+ info.push_back (Pair (" startingpriority" , e.GetPriority (e.GetHeight ())));
216
+ info.push_back (Pair (" currentpriority" , e.GetPriority (chainActive.Height ())));
217
+ info.push_back (Pair (" descendantcount" , e.GetCountWithDescendants ()));
218
+ info.push_back (Pair (" descendantsize" , e.GetSizeWithDescendants ()));
219
+ info.push_back (Pair (" descendantfees" , e.GetModFeesWithDescendants ()));
220
+ info.push_back (Pair (" ancestorcount" , e.GetCountWithAncestors ()));
221
+ info.push_back (Pair (" ancestorsize" , e.GetSizeWithAncestors ()));
222
+ info.push_back (Pair (" ancestorfees" , e.GetModFeesWithAncestors ()));
223
+ const CTransaction& tx = e.GetTx ();
224
+ set<string> setDepends;
225
+ BOOST_FOREACH (const CTxIn& txin, tx.vin )
226
+ {
227
+ if (mempool.exists (txin.prevout .hash ))
228
+ setDepends.insert (txin.prevout .hash .ToString ());
229
+ }
230
+
231
+ UniValue depends (UniValue::VARR);
232
+ BOOST_FOREACH (const string& dep, setDepends)
233
+ {
234
+ depends.push_back (dep);
235
+ }
236
+
237
+ info.push_back (Pair (" depends" , depends));
238
+ }
239
+
186
240
UniValue mempoolToJSON (bool fVerbose = false )
187
241
{
188
242
if (fVerbose )
@@ -193,31 +247,7 @@ UniValue mempoolToJSON(bool fVerbose = false)
193
247
{
194
248
const uint256& hash = e.GetTx ().GetHash ();
195
249
UniValue info (UniValue::VOBJ);
196
- info.push_back (Pair (" size" , (int )e.GetTxSize ()));
197
- info.push_back (Pair (" fee" , ValueFromAmount (e.GetFee ())));
198
- info.push_back (Pair (" modifiedfee" , ValueFromAmount (e.GetModifiedFee ())));
199
- info.push_back (Pair (" time" , e.GetTime ()));
200
- info.push_back (Pair (" height" , (int )e.GetHeight ()));
201
- info.push_back (Pair (" startingpriority" , e.GetPriority (e.GetHeight ())));
202
- info.push_back (Pair (" currentpriority" , e.GetPriority (chainActive.Height ())));
203
- info.push_back (Pair (" descendantcount" , e.GetCountWithDescendants ()));
204
- info.push_back (Pair (" descendantsize" , e.GetSizeWithDescendants ()));
205
- info.push_back (Pair (" descendantfees" , e.GetModFeesWithDescendants ()));
206
- const CTransaction& tx = e.GetTx ();
207
- set<string> setDepends;
208
- BOOST_FOREACH (const CTxIn& txin, tx.vin )
209
- {
210
- if (mempool.exists (txin.prevout .hash ))
211
- setDepends.insert (txin.prevout .hash .ToString ());
212
- }
213
-
214
- UniValue depends (UniValue::VARR);
215
- BOOST_FOREACH (const string& dep, setDepends)
216
- {
217
- depends.push_back (dep);
218
- }
219
-
220
- info.push_back (Pair (" depends" , depends));
250
+ entryToJSON (info, e);
221
251
o.push_back (Pair (hash.ToString (), info));
222
252
}
223
253
return o;
@@ -251,20 +281,8 @@ UniValue getrawmempool(const UniValue& params, bool fHelp)
251
281
" \n Result: (for verbose = true):\n "
252
282
" { (json object)\n "
253
283
" \" transactionid\" : { (json object)\n "
254
- " \" size\" : n, (numeric) transaction size in bytes\n "
255
- " \" fee\" : n, (numeric) transaction fee in " + CURRENCY_UNIT + " \n "
256
- " \" modifiedfee\" : n, (numeric) transaction fee with fee deltas used for mining priority\n "
257
- " \" time\" : n, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT\n "
258
- " \" height\" : n, (numeric) block height when transaction entered pool\n "
259
- " \" startingpriority\" : n, (numeric) priority when transaction entered pool\n "
260
- " \" currentpriority\" : n, (numeric) transaction priority now\n "
261
- " \" descendantcount\" : n, (numeric) number of in-mempool descendant transactions (including this one)\n "
262
- " \" descendantsize\" : n, (numeric) size of in-mempool descendants (including this one)\n "
263
- " \" descendantfees\" : n, (numeric) modified fees (see above) of in-mempool descendants (including this one)\n "
264
- " \" depends\" : [ (array) unconfirmed transactions used as inputs for this transaction\n "
265
- " \" transactionid\" , (string) parent transaction id\n "
266
- " ... ]\n "
267
- " }, ...\n "
284
+ + EntryDescriptionString ()
285
+ + " }, ...\n "
268
286
" }\n "
269
287
" \n Examples\n "
270
288
+ HelpExampleCli (" getrawmempool" , " true" )
@@ -280,6 +298,167 @@ UniValue getrawmempool(const UniValue& params, bool fHelp)
280
298
return mempoolToJSON (fVerbose );
281
299
}
282
300
301
+ UniValue getmempoolancestors (const UniValue& params, bool fHelp )
302
+ {
303
+ if (fHelp || params.size () < 1 || params.size () > 2 ) {
304
+ throw runtime_error (
305
+ " getmempoolancestors txid (verbose)\n "
306
+ " \n If txid is in the mempool, returns all in-mempool ancestors.\n "
307
+ " \n Arguments:\n "
308
+ " 1. \" txid\" (string, required) The transaction id (must be in mempool)\n "
309
+ " 2. verbose (boolean, optional, default=false) true for a json object, false for array of transaction ids\n "
310
+ " \n Result (for verbose=false):\n "
311
+ " [ (json array of strings)\n "
312
+ " \" transactionid\" (string) The transaction id of an in-mempool ancestor transaction\n "
313
+ " ,...\n "
314
+ " ]\n "
315
+ " \n Result (for verbose=true):\n "
316
+ " { (json object)\n "
317
+ " \" transactionid\" : { (json object)\n "
318
+ + EntryDescriptionString ()
319
+ + " }, ...\n "
320
+ " }\n "
321
+ " \n Examples\n "
322
+ + HelpExampleCli (" getmempoolancestors" , " \" mytxid\" " )
323
+ + HelpExampleRpc (" getmempoolancestors" , " \" mytxid\" " )
324
+ );
325
+ }
326
+
327
+ bool fVerbose = false ;
328
+ if (params.size () > 1 )
329
+ fVerbose = params[1 ].get_bool ();
330
+
331
+ uint256 hash = ParseHashV (params[0 ], " parameter 1" );
332
+
333
+ LOCK (mempool.cs );
334
+
335
+ CTxMemPool::txiter it = mempool.mapTx .find (hash);
336
+ if (it == mempool.mapTx .end ()) {
337
+ throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Transaction not in mempool" );
338
+ }
339
+
340
+ CTxMemPool::setEntries setAncestors;
341
+ uint64_t noLimit = std::numeric_limits<uint64_t >::max ();
342
+ std::string dummy;
343
+ mempool.CalculateMemPoolAncestors (*it, setAncestors, noLimit, noLimit, noLimit, noLimit, dummy, false );
344
+
345
+ if (!fVerbose ) {
346
+ UniValue o (UniValue::VARR);
347
+ BOOST_FOREACH (CTxMemPool::txiter ancestorIt, setAncestors) {
348
+ o.push_back (ancestorIt->GetTx ().GetHash ().ToString ());
349
+ }
350
+
351
+ return o;
352
+ } else {
353
+ UniValue o (UniValue::VOBJ);
354
+ BOOST_FOREACH (CTxMemPool::txiter ancestorIt, setAncestors) {
355
+ const CTxMemPoolEntry &e = *ancestorIt;
356
+ const uint256& hash = e.GetTx ().GetHash ();
357
+ UniValue info (UniValue::VOBJ);
358
+ entryToJSON (info, e);
359
+ o.push_back (Pair (hash.ToString (), info));
360
+ }
361
+ return o;
362
+ }
363
+ }
364
+
365
+ UniValue getmempooldescendants (const UniValue& params, bool fHelp )
366
+ {
367
+ if (fHelp || params.size () < 1 || params.size () > 2 ) {
368
+ throw runtime_error (
369
+ " getmempooldescendants txid (verbose)\n "
370
+ " \n If txid is in the mempool, returns all in-mempool descendants.\n "
371
+ " \n Arguments:\n "
372
+ " 1. \" txid\" (string, required) The transaction id (must be in mempool)\n "
373
+ " 2. verbose (boolean, optional, default=false) true for a json object, false for array of transaction ids\n "
374
+ " \n Result (for verbose=false):\n "
375
+ " [ (json array of strings)\n "
376
+ " \" transactionid\" (string) The transaction id of an in-mempool descendant transaction\n "
377
+ " ,...\n "
378
+ " ]\n "
379
+ " \n Result (for verbose=true):\n "
380
+ " { (json object)\n "
381
+ " \" transactionid\" : { (json object)\n "
382
+ + EntryDescriptionString ()
383
+ + " }, ...\n "
384
+ " }\n "
385
+ " \n Examples\n "
386
+ + HelpExampleCli (" getmempooldescendants" , " \" mytxid\" " )
387
+ + HelpExampleRpc (" getmempooldescendants" , " \" mytxid\" " )
388
+ );
389
+ }
390
+
391
+ bool fVerbose = false ;
392
+ if (params.size () > 1 )
393
+ fVerbose = params[1 ].get_bool ();
394
+
395
+ uint256 hash = ParseHashV (params[0 ], " parameter 1" );
396
+
397
+ LOCK (mempool.cs );
398
+
399
+ CTxMemPool::txiter it = mempool.mapTx .find (hash);
400
+ if (it == mempool.mapTx .end ()) {
401
+ throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Transaction not in mempool" );
402
+ }
403
+
404
+ CTxMemPool::setEntries setDescendants;
405
+ mempool.CalculateDescendants (it, setDescendants);
406
+ // CTxMemPool::CalculateDescendants will include the given tx
407
+ setDescendants.erase (it);
408
+
409
+ if (!fVerbose ) {
410
+ UniValue o (UniValue::VARR);
411
+ BOOST_FOREACH (CTxMemPool::txiter descendantIt, setDescendants) {
412
+ o.push_back (descendantIt->GetTx ().GetHash ().ToString ());
413
+ }
414
+
415
+ return o;
416
+ } else {
417
+ UniValue o (UniValue::VOBJ);
418
+ BOOST_FOREACH (CTxMemPool::txiter descendantIt, setDescendants) {
419
+ const CTxMemPoolEntry &e = *descendantIt;
420
+ const uint256& hash = e.GetTx ().GetHash ();
421
+ UniValue info (UniValue::VOBJ);
422
+ entryToJSON (info, e);
423
+ o.push_back (Pair (hash.ToString (), info));
424
+ }
425
+ return o;
426
+ }
427
+ }
428
+
429
+ UniValue getmempoolentry (const UniValue& params, bool fHelp )
430
+ {
431
+ if (fHelp || params.size () != 1 ) {
432
+ throw runtime_error (
433
+ " getmempoolentry txid\n "
434
+ " \n Returns mempool data for given transaction\n "
435
+ " \n Arguments:\n "
436
+ " 1. \" txid\" (string, required) The transaction id (must be in mempool)\n "
437
+ " \n Result:\n "
438
+ " { (json object)\n "
439
+ + EntryDescriptionString ()
440
+ + " }\n "
441
+ " \n Examples\n "
442
+ + HelpExampleCli (" getmempoolentry" , " \" mytxid\" " )
443
+ + HelpExampleRpc (" getmempoolentry" , " \" mytxid\" " )
444
+ );
445
+ }
446
+
447
+ uint256 hash = ParseHashV (params[0 ], " parameter 1" );
448
+
449
+ LOCK (mempool.cs );
450
+
451
+ CTxMemPool::txiter it = mempool.mapTx .find (hash);
452
+ if (it == mempool.mapTx .end ()) {
453
+ throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, " Transaction not in mempool" );
454
+ }
455
+
456
+ const CTxMemPoolEntry &e = *it;
457
+ UniValue info (UniValue::VOBJ);
458
+ entryToJSON (info, e);
459
+ return info;
460
+ }
461
+
283
462
UniValue getblockhash (const UniValue& params, bool fHelp )
284
463
{
285
464
if (fHelp || params.size () != 1 )
@@ -1004,6 +1183,9 @@ static const CRPCCommand commands[] =
1004
1183
{ " blockchain" , " getblockheader" , &getblockheader, true },
1005
1184
{ " blockchain" , " getchaintips" , &getchaintips, true },
1006
1185
{ " blockchain" , " getdifficulty" , &getdifficulty, true },
1186
+ { " blockchain" , " getmempoolancestors" , &getmempoolancestors, true },
1187
+ { " blockchain" , " getmempooldescendants" , &getmempooldescendants, true },
1188
+ { " blockchain" , " getmempoolentry" , &getmempoolentry, true },
1007
1189
{ " blockchain" , " getmempoolinfo" , &getmempoolinfo, true },
1008
1190
{ " blockchain" , " getrawmempool" , &getrawmempool, true },
1009
1191
{ " blockchain" , " gettxout" , &gettxout, true },
0 commit comments