Index: rpc.cpp =================================================================== --- rpc.cpp (revision 117) +++ rpc.cpp (working copy) @@ -342,7 +342,80 @@ return "sent"; } +struct txnitem +{ + uint160 hash160; + int64 nAmount; + int nConf; + txnitem() + { + hash160 = 0; + nAmount = 0; + nConf = INT_MAX; + } +}; + +Value ListTransactions(int64 nCount, bool fGenerated) +{ + vector tv; + CRITICAL_BLOCK(cs_mapWallet) + { + for (map::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) + { + const CWalletTx& wtx = (*it).second; + if (wtx.IsCoinBase() || !wtx.IsFinal()) + continue; + + int nDepth = wtx.GetDepthInMainChain(); + + foreach(const CTxOut& txout, wtx.vout) + { + // Only counting our own bitcoin addresses and not ip addresses + uint160 hash160 = txout.scriptPubKey.GetBitcoinAddressHash160(); + +#if 0 + if (hash160 == 0 || !mapPubKeys.count(hash160)) // IsMine + continue; +#endif + + txnitem item; + item.nAmount = txout.nValue; + item.nConf = min(item.nConf, nDepth); + item.hash160 = hash160; + + tv.push_back(item); + } + } + } + + // Reply + Array ret; + CRITICAL_BLOCK(cs_mapAddressBook) + { + foreach(const txnitem& txn, tv) + { + string strAddress = Hash160ToAddress(txn.hash160); + string strLabel; + int64 nAmount = txn.nAmount; + int nConf = txn.nConf; + + map::iterator mi = mapAddressBook.find(strAddress); + if (mi != mapAddressBook.end()) + strLabel = (*mi).second; + + Object obj; + obj.push_back(Pair("address", strAddress)); + obj.push_back(Pair("label", strLabel)); + obj.push_back(Pair("amount", (double)nAmount / (double)COIN)); + obj.push_back(Pair("confirmations", (nConf == INT_MAX ? 0 : nConf))); + ret.push_back(obj); + } + } + + return ret; +} + Value listtransactions(const Array& params, bool fHelp) { if (fHelp || params.size() > 2) @@ -357,10 +430,7 @@ if (params.size() > 1) fGenerated = params[1].get_bool(); - Array ret; - //// not finished - ret.push_back("not implemented yet"); - return ret; + return ListTransactions(nCount, fGenerated); } @@ -638,6 +708,7 @@ make_pair("getreceivedbylabel", &getreceivedbylabel), make_pair("listreceivedbyaddress", &listreceivedbyaddress), make_pair("listreceivedbylabel", &listreceivedbylabel), + make_pair("listtransactions", &listtransactions), }; map mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0]));