aboutsummaryrefslogtreecommitdiff
path: root/rpc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rpc.cpp')
-rw-r--r--rpc.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/rpc.cpp b/rpc.cpp
index 055e0cf1e7..dd94acc050 100644
--- a/rpc.cpp
+++ b/rpc.cpp
@@ -65,7 +65,7 @@ int64 AmountFromValue(const Value& value)
double dAmount = value.get_real();
if (dAmount <= 0.0 || dAmount > 21000000.0)
throw JSONRPCError(-3, "Invalid amount");
- int64 nAmount = roundint64(dAmount * 100.00) * CENT;
+ int64 nAmount = roundint64(dAmount * COIN);
if (!MoneyRange(nAmount))
throw JSONRPCError(-3, "Invalid amount");
return nAmount;
@@ -277,7 +277,7 @@ Value getinfo(const Array& params, bool fHelp)
Object obj;
obj.push_back(Pair("version", (int)VERSION));
- obj.push_back(Pair("balance", (double)GetBalance() / (double)COIN));
+ obj.push_back(Pair("balance", ValueFromAmount(GetBalance())));
obj.push_back(Pair("blocks", (int)nBestHeight));
obj.push_back(Pair("connections", (int)vNodes.size()));
obj.push_back(Pair("proxy", (fUseProxy ? addrProxy.ToStringIPPort() : string())));
@@ -287,7 +287,7 @@ Value getinfo(const Array& params, bool fHelp)
obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
obj.push_back(Pair("testnet", fTestNet));
obj.push_back(Pair("keypoololdest", (boost::int64_t)GetOldestKeyPoolTime()));
- obj.push_back(Pair("paytxfee", (double)nTransactionFee / (double)COIN));
+ obj.push_back(Pair("paytxfee", ValueFromAmount(nTransactionFee)));
obj.push_back(Pair("errors", GetWarnings("statusbar")));
return obj;
}
@@ -381,6 +381,12 @@ Value setaccount(const Array& params, bool fHelp)
"Sets the account associated with the given address.");
string strAddress = params[0].get_str();
+ uint160 hash160;
+ bool isValid = AddressToHash160(strAddress, hash160);
+ if (!isValid)
+ throw JSONRPCError(-5, "Invalid bitcoin address");
+
+
string strAccount;
if (params.size() > 1)
strAccount = AccountFromValue(params[1]);
@@ -513,7 +519,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
}
}
- return (double)nAmount / (double)COIN;
+ return ValueFromAmount(nAmount);
}
@@ -619,7 +625,7 @@ Value getbalance(const Array& params, bool fHelp)
"If [account] is specified, returns the balance in the account.");
if (params.size() == 0)
- return ((double)GetBalance() / (double)COIN);
+ return ValueFromAmount(GetBalance());
if (params[0].get_str() == "*") {
// Calculate total balance a different way from GetBalance()
@@ -648,7 +654,7 @@ Value getbalance(const Array& params, bool fHelp)
nBalance += allGenerated;
}
printf("Found %d accounts\n", vAccounts.size());
- return (double)nBalance / (double)COIN;
+ return ValueFromAmount(nBalance);
}
string strAccount = AccountFromValue(params[0]);
@@ -658,7 +664,7 @@ Value getbalance(const Array& params, bool fHelp)
int64 nBalance = GetAccountBalance(strAccount, nMinDepth);
- return (double)nBalance / (double)COIN;
+ return ValueFromAmount(nBalance);
}
@@ -851,7 +857,7 @@ Value ListReceived(const Array& params, bool fByAccounts)
obj.push_back(Pair("address", strAddress));
obj.push_back(Pair("account", strAccount));
obj.push_back(Pair("label", strAccount)); // deprecated
- obj.push_back(Pair("amount", (double)nAmount / (double)COIN));
+ obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
obj.push_back(Pair("confirmations", (nConf == INT_MAX ? 0 : nConf)));
ret.push_back(obj);
}
@@ -867,7 +873,7 @@ Value ListReceived(const Array& params, bool fByAccounts)
Object obj;
obj.push_back(Pair("account", (*it).first));
obj.push_back(Pair("label", (*it).first)); // deprecated
- obj.push_back(Pair("amount", (double)nAmount / (double)COIN));
+ obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
obj.push_back(Pair("confirmations", (nConf == INT_MAX ? 0 : nConf)));
ret.push_back(obj);
}
@@ -1015,13 +1021,13 @@ Value listtransactions(const Array& params, bool fHelp)
for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
{
CWalletTx* wtx = &((*it).second);
- txByTime.insert(make_pair(wtx->GetTxTime(), TxPair(wtx, 0)));
+ txByTime.insert(make_pair(wtx->GetTxTime(), TxPair(wtx, (CAccountingEntry*)0)));
}
list<CAccountingEntry> acentries;
walletdb.ListAccountCreditDebit(strAccount, acentries);
foreach(CAccountingEntry& entry, acentries)
{
- txByTime.insert(make_pair(entry.nTime, TxPair(0, &entry)));
+ txByTime.insert(make_pair(entry.nTime, TxPair((CWalletTx*)0, &entry)));
}
// Now: iterate backwards until we have nCount items to return:
@@ -1710,6 +1716,8 @@ void ThreadRPCServer2(void* parg)
ip::tcp::endpoint endpoint(bindAddress, GetArg("-rpcport", 8332));
ip::tcp::acceptor acceptor(io_service, endpoint);
+ acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
+
#ifdef USE_SSL
ssl::context context(io_service, ssl::context::sslv23);
if (fUseSSL)
@@ -1762,7 +1770,7 @@ void ThreadRPCServer2(void* parg)
map<string, string> mapHeaders;
string strRequest;
- boost::thread api_caller(ReadHTTP, ref(stream), ref(mapHeaders), ref(strRequest));
+ boost::thread api_caller(ReadHTTP, boost::ref(stream), boost::ref(mapHeaders), boost::ref(strRequest));
if (!api_caller.timed_join(boost::posix_time::seconds(GetArg("-rpctimeout", 30))))
{ // Timed out:
acceptor.cancel();