Skip to content

Commit 76aed01

Browse files
committed
listsinceblock now shows txns with 0 confirms, as well as allows the lastblock return property to be targeted to the block with the specified depth
1 parent 5b2f351 commit 76aed01

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/rpc.cpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,10 +1234,11 @@ Value listsinceblock(const Array& params, bool fHelp)
12341234
{
12351235
if (fHelp)
12361236
throw runtime_error(
1237-
"listsinceblock [blockid]\n"
1237+
"listsinceblock [blockid] [target-confirmations]\n"
12381238
"Get all transactions in blocks since block [blockid], or all transactions if omitted");
12391239

12401240
CBlockIndex *pindex = NULL;
1241+
int target_confirms = 1;
12411242

12421243
if (params.size() > 0)
12431244
{
@@ -1247,6 +1248,14 @@ Value listsinceblock(const Array& params, bool fHelp)
12471248
pindex = CBlockLocator(blockId).GetBlockIndex();
12481249
}
12491250

1251+
if (params.size() > 1)
1252+
{
1253+
target_confirms = params[1].get_int();
1254+
1255+
if (target_confirms < 1)
1256+
throw JSONRPCError(-8, "Invalid parameter");
1257+
}
1258+
12501259
int depth = pindex ? (1 + nBestHeight - pindex->nHeight) : -1;
12511260

12521261
Array transactions;
@@ -1257,12 +1266,31 @@ Value listsinceblock(const Array& params, bool fHelp)
12571266
CWalletTx tx = (*it).second;
12581267

12591268
if (depth == -1 || tx.GetDepthInMainChain() < depth)
1260-
ListTransactions(tx, "*", 1, true, transactions);
1269+
ListTransactions(tx, "*", 0, true, transactions);
1270+
}
1271+
1272+
uint256 lastblock;
1273+
1274+
if (target_confirms == 1)
1275+
{
1276+
printf("oops!\n");
1277+
lastblock = hashBestChain;
1278+
}
1279+
else
1280+
{
1281+
int target_height = pindexBest->nHeight + 1 - target_confirms;
1282+
1283+
CBlockIndex *block;
1284+
for (block = pindexBest;
1285+
block && block->nHeight > target_height;
1286+
block = block->pprev);
1287+
1288+
lastblock = block ? block->GetBlockHash() : 0;
12611289
}
12621290

12631291
Object ret;
12641292
ret.push_back(Pair("transactions", transactions));
1265-
ret.push_back(Pair("lastblock", hashBestChain.GetHex()));
1293+
ret.push_back(Pair("lastblock", lastblock.GetHex()));
12661294

12671295
return ret;
12681296
}
@@ -2168,6 +2196,7 @@ int CommandLineRPC(int argc, char *argv[])
21682196
if (strMethod == "listtransactions" && n > 1) ConvertTo<boost::int64_t>(params[1]);
21692197
if (strMethod == "listtransactions" && n > 2) ConvertTo<boost::int64_t>(params[2]);
21702198
if (strMethod == "listaccounts" && n > 0) ConvertTo<boost::int64_t>(params[0]);
2199+
if (strMethod == "listsinceblock" && n > 1) ConvertTo<boost::int64_t>(params[1]);
21712200
if (strMethod == "sendmany" && n > 1)
21722201
{
21732202
string s = params[1].get_str();

0 commit comments

Comments
 (0)