aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2011-10-05 11:38:24 -0400
committerGavin Andresen <gavinandresen@gmail.com>2011-10-05 11:38:24 -0400
commit3a6e468d9a0caceea80f274967bb0cf6aecdc8f1 (patch)
treed0dd6dc1bcbfc6d1dd3397fd904a69bde15c0b03
parent4ffbdcc0f5a1b28092f4f45bef6ae0bbcdcefe42 (diff)
parent76aed0141cbc4827ef6f168b6af5b2894046ec0b (diff)
Merge branch 'listsinceblock' of https://github.com/cdhowie/bitcoin
-rw-r--r--src/bitcoinrpc.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index a2a90d69e8..d3d92c8e7e 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -1257,6 +1257,70 @@ Value listaccounts(const Array& params, bool fHelp)
return ret;
}
+Value listsinceblock(const Array& params, bool fHelp)
+{
+ if (fHelp)
+ throw runtime_error(
+ "listsinceblock [blockid] [target-confirmations]\n"
+ "Get all transactions in blocks since block [blockid], or all transactions if omitted");
+
+ CBlockIndex *pindex = NULL;
+ int target_confirms = 1;
+
+ if (params.size() > 0)
+ {
+ uint256 blockId = 0;
+
+ blockId.SetHex(params[0].get_str());
+ pindex = CBlockLocator(blockId).GetBlockIndex();
+ }
+
+ if (params.size() > 1)
+ {
+ target_confirms = params[1].get_int();
+
+ if (target_confirms < 1)
+ throw JSONRPCError(-8, "Invalid parameter");
+ }
+
+ int depth = pindex ? (1 + nBestHeight - pindex->nHeight) : -1;
+
+ Array transactions;
+
+ for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); it++)
+ {
+ CWalletTx tx = (*it).second;
+
+ if (depth == -1 || tx.GetDepthInMainChain() < depth)
+ ListTransactions(tx, "*", 0, true, transactions);
+ }
+
+ uint256 lastblock;
+
+ if (target_confirms == 1)
+ {
+ printf("oops!\n");
+ lastblock = hashBestChain;
+ }
+ else
+ {
+ int target_height = pindexBest->nHeight + 1 - target_confirms;
+
+ CBlockIndex *block;
+ for (block = pindexBest;
+ block && block->nHeight > target_height;
+ block = block->pprev);
+
+ lastblock = block ? block->GetBlockHash() : 0;
+ }
+
+ Object ret;
+ ret.push_back(Pair("transactions", transactions));
+ ret.push_back(Pair("lastblock", lastblock.GetHex()));
+
+ return ret;
+}
+
Value gettransaction(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 1)
@@ -1778,6 +1842,7 @@ pair<string, rpcfn_type> pCallTable[] =
make_pair("listaccounts", &listaccounts),
make_pair("settxfee", &settxfee),
make_pair("getmemorypool", &getmemorypool),
+ make_pair("listsinceblock", &listsinceblock),
};
map<string, rpcfn_type> mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0]));
@@ -2401,6 +2466,7 @@ int CommandLineRPC(int argc, char *argv[])
if (strMethod == "listtransactions" && n > 2) ConvertTo<boost::int64_t>(params[2]);
if (strMethod == "listaccounts" && n > 0) ConvertTo<boost::int64_t>(params[0]);
if (strMethod == "walletpassphrase" && n > 1) ConvertTo<boost::int64_t>(params[1]);
+ if (strMethod == "listsinceblock" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "sendmany" && n > 1)
{
string s = params[1].get_str();