aboutsummaryrefslogtreecommitdiff
path: root/rpc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rpc.cpp')
-rw-r--r--rpc.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/rpc.cpp b/rpc.cpp
index e8335cd51f..85f8b02216 100644
--- a/rpc.cpp
+++ b/rpc.cpp
@@ -640,40 +640,39 @@ Value getbalance(const Array& params, bool fHelp)
if (params.size() == 0)
return ValueFromAmount(GetBalance());
+ int nMinDepth = 1;
+ if (params.size() > 1)
+ nMinDepth = params[1].get_int();
+
if (params[0].get_str() == "*") {
// Calculate total balance a different way from GetBalance()
// (GetBalance() sums up all unspent TxOuts)
// getbalance and getbalance '*' should always return the same number.
int64 nBalance = 0;
- vector<string> vAccounts;
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
+ if (!wtx.IsFinal())
+ continue;
+
int64 allGeneratedImmature, allGeneratedMature, allFee;
allGeneratedImmature = allGeneratedMature = allFee = 0;
string strSentAccount;
list<pair<string, int64> > listReceived;
list<pair<string, int64> > listSent;
wtx.GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount);
- foreach(const PAIRTYPE(string,int64)& r, listReceived)
- {
- nBalance += r.second;
- if (!count(vAccounts.begin(), vAccounts.end(), r.first))
- vAccounts.push_back(r.first);
- }
+ if (wtx.GetDepthInMainChain() >= nMinDepth)
+ foreach(const PAIRTYPE(string,int64)& r, listReceived)
+ nBalance += r.second;
foreach(const PAIRTYPE(string,int64)& r, listSent)
nBalance -= r.second;
nBalance -= allFee;
nBalance += allGeneratedMature;
}
- printf("Found %d accounts\n", vAccounts.size());
return ValueFromAmount(nBalance);
}
string strAccount = AccountFromValue(params[0]);
- int nMinDepth = 1;
- if (params.size() > 1)
- nMinDepth = params[1].get_int();
int64 nBalance = GetAccountBalance(strAccount, nMinDepth);
@@ -1483,7 +1482,7 @@ string HTTPPost(const string& strMsg, const map<string,string>& mapRequestHeader
{
ostringstream s;
s << "POST / HTTP/1.1\r\n"
- << "User-Agent: json-rpc/1.0\r\n"
+ << "User-Agent: bitcoin-json-rpc/" << FormatFullVersion() << "\r\n"
<< "Host: 127.0.0.1\r\n"
<< "Content-Type: application/json\r\n"
<< "Content-Length: " << strMsg.size() << "\r\n"
@@ -1501,7 +1500,10 @@ string rfc1123Time()
time_t now;
time(&now);
struct tm* now_gmt = gmtime(&now);
- strftime(buffer, sizeof(buffer), "%a, %d %b %Y %H:%M:%S %Z", now_gmt);
+ string locale(setlocale(LC_TIME, NULL));
+ setlocale(LC_TIME, "C"); // we want posix (aka "C") weekday/month strings
+ strftime(buffer, sizeof(buffer), "%a, %d %b %Y %H:%M:%S +0000", now_gmt);
+ setlocale(LC_TIME, locale.c_str());
return string(buffer);
}
@@ -1510,7 +1512,7 @@ string HTTPReply(int nStatus, const string& strMsg)
if (nStatus == 401)
return strprintf("HTTP/1.0 401 Authorization Required\r\n"
"Date: %s\r\n"
- "Server: bitcoin-json-rpc\r\n"
+ "Server: bitcoin-json-rpc/%s\r\n"
"WWW-Authenticate: Basic realm=\"jsonrpc\"\r\n"
"Content-Type: text/html\r\n"
"Content-Length: 296\r\n"
@@ -1523,7 +1525,7 @@ string HTTPReply(int nStatus, const string& strMsg)
"<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>\r\n"
"</HEAD>\r\n"
"<BODY><H1>401 Unauthorized.</H1></BODY>\r\n"
- "</HTML>\r\n", rfc1123Time().c_str());
+ "</HTML>\r\n", rfc1123Time().c_str(), FormatFullVersion().c_str());
string strStatus;
if (nStatus == 200) strStatus = "OK";
else if (nStatus == 400) strStatus = "Bad Request";
@@ -1535,13 +1537,14 @@ string HTTPReply(int nStatus, const string& strMsg)
"Connection: close\r\n"
"Content-Length: %d\r\n"
"Content-Type: application/json\r\n"
- "Server: bitcoin-json-rpc/1.0\r\n"
+ "Server: bitcoin-json-rpc/%s\r\n"
"\r\n"
"%s",
nStatus,
strStatus.c_str(),
rfc1123Time().c_str(),
strMsg.size(),
+ FormatFullVersion().c_str(),
strMsg.c_str());
}
@@ -1570,10 +1573,11 @@ int ReadHTTPHeader(std::basic_istream<char>& stream, map<string, string>& mapHea
{
string strHeader = str.substr(0, nColon);
boost::trim(strHeader);
+ boost::to_lower(strHeader);
string strValue = str.substr(nColon+1);
boost::trim(strValue);
mapHeadersRet[strHeader] = strValue;
- if (strHeader == "Content-Length")
+ if (strHeader == "content-length")
nLen = atoi(strValue.c_str());
}
}
@@ -1643,7 +1647,7 @@ string DecodeBase64(string s)
bool HTTPAuthorized(map<string, string>& mapHeaders)
{
- string strAuth = mapHeaders["Authorization"];
+ string strAuth = mapHeaders["authorization"];
if (strAuth.substr(0,6) != "Basic ")
return false;
string strUserPass64 = strAuth.substr(6); boost::trim(strUserPass64);
@@ -1872,7 +1876,7 @@ void ThreadRPCServer2(void* parg)
}
// Check authorization
- if (mapHeaders.count("Authorization") == 0)
+ if (mapHeaders.count("authorization") == 0)
{
stream << HTTPReply(401, "") << std::flush;
continue;