@@ -1257,6 +1257,70 @@ Value listaccounts(const Array& params, bool fHelp)
12571257 return ret;
12581258}
12591259
1260+ Value listsinceblock (const Array& params, bool fHelp )
1261+ {
1262+ if (fHelp )
1263+ throw runtime_error (
1264+ " listsinceblock [blockid] [target-confirmations]\n "
1265+ " Get all transactions in blocks since block [blockid], or all transactions if omitted" );
1266+
1267+ CBlockIndex *pindex = NULL ;
1268+ int target_confirms = 1 ;
1269+
1270+ if (params.size () > 0 )
1271+ {
1272+ uint256 blockId = 0 ;
1273+
1274+ blockId.SetHex (params[0 ].get_str ());
1275+ pindex = CBlockLocator (blockId).GetBlockIndex ();
1276+ }
1277+
1278+ if (params.size () > 1 )
1279+ {
1280+ target_confirms = params[1 ].get_int ();
1281+
1282+ if (target_confirms < 1 )
1283+ throw JSONRPCError (-8 , " Invalid parameter" );
1284+ }
1285+
1286+ int depth = pindex ? (1 + nBestHeight - pindex->nHeight ) : -1 ;
1287+
1288+ Array transactions;
1289+
1290+ for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet .begin (); it != pwalletMain->mapWallet .end (); it++)
1291+ {
1292+ CWalletTx tx = (*it).second ;
1293+
1294+ if (depth == -1 || tx.GetDepthInMainChain () < depth)
1295+ ListTransactions (tx, " *" , 0 , true , transactions);
1296+ }
1297+
1298+ uint256 lastblock;
1299+
1300+ if (target_confirms == 1 )
1301+ {
1302+ printf (" oops!\n " );
1303+ lastblock = hashBestChain;
1304+ }
1305+ else
1306+ {
1307+ int target_height = pindexBest->nHeight + 1 - target_confirms;
1308+
1309+ CBlockIndex *block;
1310+ for (block = pindexBest;
1311+ block && block->nHeight > target_height;
1312+ block = block->pprev );
1313+
1314+ lastblock = block ? block->GetBlockHash () : 0 ;
1315+ }
1316+
1317+ Object ret;
1318+ ret.push_back (Pair (" transactions" , transactions));
1319+ ret.push_back (Pair (" lastblock" , lastblock.GetHex ()));
1320+
1321+ return ret;
1322+ }
1323+
12601324Value gettransaction (const Array& params, bool fHelp )
12611325{
12621326 if (fHelp || params.size () != 1 )
@@ -1778,6 +1842,7 @@ pair<string, rpcfn_type> pCallTable[] =
17781842 make_pair (" listaccounts" , &listaccounts),
17791843 make_pair (" settxfee" , &settxfee),
17801844 make_pair (" getmemorypool" , &getmemorypool),
1845+ make_pair (" listsinceblock" , &listsinceblock),
17811846};
17821847map<string, rpcfn_type> mapCallTable (pCallTable, pCallTable + sizeof (pCallTable)/sizeof(pCallTable[0 ]));
17831848
@@ -2401,6 +2466,7 @@ int CommandLineRPC(int argc, char *argv[])
24012466 if (strMethod == " listtransactions" && n > 2 ) ConvertTo<boost::int64_t >(params[2 ]);
24022467 if (strMethod == " listaccounts" && n > 0 ) ConvertTo<boost::int64_t >(params[0 ]);
24032468 if (strMethod == " walletpassphrase" && n > 1 ) ConvertTo<boost::int64_t >(params[1 ]);
2469+ if (strMethod == " listsinceblock" && n > 1 ) ConvertTo<boost::int64_t >(params[1 ]);
24042470 if (strMethod == " sendmany" && n > 1 )
24052471 {
24062472 string s = params[1 ].get_str ();
0 commit comments