aboutsummaryrefslogtreecommitdiff
path: root/src/rpcwallet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpcwallet.cpp')
-rw-r--r--src/rpcwallet.cpp92
1 files changed, 55 insertions, 37 deletions
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp
index 20df4c0a68..b8e6a4467a 100644
--- a/src/rpcwallet.cpp
+++ b/src/rpcwallet.cpp
@@ -15,16 +15,14 @@ using namespace std;
int64 nWalletUnlockTime;
static CCriticalSection cs_nWalletUnlockTime;
-std::string
-HelpRequiringPassphrase()
+std::string HelpRequiringPassphrase()
{
return pwalletMain->IsCrypted()
? "\nrequires wallet passphrase to be set with walletpassphrase first"
: "";
}
-void
-EnsureWalletIsUnlocked()
+void EnsureWalletIsUnlocked()
{
if (pwalletMain->IsLocked())
throw JSONRPCError(-13, "Error: Please enter the wallet passphrase with walletpassphrase first.");
@@ -34,6 +32,8 @@ void WalletTxToJSON(const CWalletTx& wtx, Object& entry)
{
int confirms = wtx.GetDepthInMainChain();
entry.push_back(Pair("confirmations", confirms));
+ if (wtx.IsCoinBase())
+ entry.push_back(Pair("generated", true));
if (confirms)
{
entry.push_back(Pair("blockhash", wtx.hashBlock.GetHex()));
@@ -274,6 +274,37 @@ Value sendtoaddress(const Array& params, bool fHelp)
return wtx.GetHash().GetHex();
}
+Value listaddressgroupings(const Array& params, bool fHelp)
+{
+ if (fHelp)
+ throw runtime_error(
+ "listaddressgroupings\n"
+ "Lists groups of addresses which have had their common ownership\n"
+ "made public by common use as inputs or as the resulting change\n"
+ "in past transactions");
+
+ Array jsonGroupings;
+ map<CTxDestination, int64> balances = pwalletMain->GetAddressBalances();
+ BOOST_FOREACH(set<CTxDestination> grouping, pwalletMain->GetAddressGroupings())
+ {
+ Array jsonGrouping;
+ BOOST_FOREACH(CTxDestination address, grouping)
+ {
+ Array addressInfo;
+ addressInfo.push_back(CBitcoinAddress(address).ToString());
+ addressInfo.push_back(ValueFromAmount(balances[address]));
+ {
+ LOCK(pwalletMain->cs_wallet);
+ if (pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get()) != pwalletMain->mapAddressBook.end())
+ addressInfo.push_back(pwalletMain->mapAddressBook.find(CBitcoinAddress(address).Get())->second);
+ }
+ jsonGrouping.push_back(addressInfo);
+ }
+ jsonGroupings.push_back(jsonGrouping);
+ }
+ return jsonGroupings;
+}
+
Value signmessage(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 2)
@@ -445,12 +476,12 @@ int64 GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinD
if (!wtx.IsFinal())
continue;
- int64 nGenerated, nReceived, nSent, nFee;
- wtx.GetAccountAmounts(strAccount, nGenerated, nReceived, nSent, nFee);
+ int64 nReceived, nSent, nFee;
+ wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee);
if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
nBalance += nReceived;
- nBalance += nGenerated - nSent - nFee;
+ nBalance -= nSent + nFee;
}
// Tally internal accounting entries
@@ -492,12 +523,11 @@ Value getbalance(const Array& params, bool fHelp)
if (!wtx.IsFinal())
continue;
- int64 allGeneratedImmature, allGeneratedMature, allFee;
- allGeneratedImmature = allGeneratedMature = allFee = 0;
+ int64 allFee;
string strSentAccount;
list<pair<CTxDestination, int64> > listReceived;
list<pair<CTxDestination, int64> > listSent;
- wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount);
+ wtx.GetAmounts(listReceived, listSent, allFee, strSentAccount);
if (wtx.GetDepthInMainChain() >= nMinDepth)
{
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& r, listReceived)
@@ -506,7 +536,6 @@ Value getbalance(const Array& params, bool fHelp)
BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& r, listSent)
nBalance -= r.second;
nBalance -= allFee;
- nBalance += allGeneratedMature;
}
return ValueFromAmount(nBalance);
}
@@ -877,35 +906,15 @@ Value listreceivedbyaccount(const Array& params, bool fHelp)
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret)
{
- int64 nGeneratedImmature, nGeneratedMature, nFee;
+ int64 nFee;
string strSentAccount;
list<pair<CTxDestination, int64> > listReceived;
list<pair<CTxDestination, int64> > listSent;
- wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount);
+ wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount);
bool fAllAccounts = (strAccount == string("*"));
- // Generated blocks assigned to account ""
- if ((nGeneratedMature+nGeneratedImmature) != 0 && (fAllAccounts || strAccount == ""))
- {
- Object entry;
- entry.push_back(Pair("account", string("")));
- if (nGeneratedImmature)
- {
- entry.push_back(Pair("category", wtx.GetDepthInMainChain() ? "immature" : "orphan"));
- entry.push_back(Pair("amount", ValueFromAmount(nGeneratedImmature)));
- }
- else
- {
- entry.push_back(Pair("category", "generate"));
- entry.push_back(Pair("amount", ValueFromAmount(nGeneratedMature)));
- }
- if (fLong)
- WalletTxToJSON(wtx, entry);
- ret.push_back(entry);
- }
-
// Sent
if ((!listSent.empty() || nFee != 0) && (fAllAccounts || strAccount == strSentAccount))
{
@@ -936,7 +945,17 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe
Object entry;
entry.push_back(Pair("account", account));
entry.push_back(Pair("address", CBitcoinAddress(r.first).ToString()));
- entry.push_back(Pair("category", "receive"));
+ if (wtx.IsCoinBase())
+ {
+ if (wtx.GetDepthInMainChain() < 1)
+ entry.push_back(Pair("category", "orphan"));
+ else if (wtx.GetBlocksToMaturity() > 0)
+ entry.push_back(Pair("category", "immature"));
+ else
+ entry.push_back(Pair("category", "generate"));
+ }
+ else
+ entry.push_back(Pair("category", "receive"));
entry.push_back(Pair("amount", ValueFromAmount(r.second)));
if (fLong)
WalletTxToJSON(wtx, entry);
@@ -1041,17 +1060,16 @@ Value listaccounts(const Array& params, bool fHelp)
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
- int64 nGeneratedImmature, nGeneratedMature, nFee;
+ int64 nFee;
string strSentAccount;
list<pair<CTxDestination, int64> > listReceived;
list<pair<CTxDestination, int64> > listSent;
- wtx.GetAmounts(nGeneratedImmature, nGeneratedMature, listReceived, listSent, nFee, strSentAccount);
+ wtx.GetAmounts(listReceived, listSent, nFee, strSentAccount);
mapAccountBalances[strSentAccount] -= nFee;
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& s, listSent)
mapAccountBalances[strSentAccount] -= s.second;
if (wtx.GetDepthInMainChain() >= nMinDepth)
{
- mapAccountBalances[""] += nGeneratedMature;
BOOST_FOREACH(const PAIRTYPE(CTxDestination, int64)& r, listReceived)
if (pwalletMain->mapAddressBook.count(r.first))
mapAccountBalances[pwalletMain->mapAddressBook[r.first]] += r.second;