aboutsummaryrefslogtreecommitdiff
path: root/src/rpcwallet.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-10-01 11:28:51 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-10-01 11:28:55 +0200
commit3fd192f8b4d6db386354dfe635a8a6a105b55de8 (patch)
tree39f8a9caf006a6fe38d89b98a57fb94c56f3cd28 /src/rpcwallet.cpp
parentb25551101c7ceff8af862131c30c08527ff60160 (diff)
parentc122f5528c882efc8aebe31fd4d84612175f66aa (diff)
Merge pull request #4234
c122f55 qt: Register CAmount metatype (Wladimir J. van der Laan) a372168 Use a typedef for monetary values (Mark Friedenbach)
Diffstat (limited to 'src/rpcwallet.cpp')
-rw-r--r--src/rpcwallet.cpp62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp
index 35637362a4..632c46acd5 100644
--- a/src/rpcwallet.cpp
+++ b/src/rpcwallet.cpp
@@ -331,7 +331,7 @@ Value sendtoaddress(const Array& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
// Amount
- int64_t nAmount = AmountFromValue(params[1]);
+ CAmount nAmount = AmountFromValue(params[1]);
// Wallet comments
CWalletTx wtx;
@@ -375,7 +375,7 @@ Value listaddressgroupings(const Array& params, bool fHelp)
);
Array jsonGroupings;
- map<CTxDestination, int64_t> balances = pwalletMain->GetAddressBalances();
+ map<CTxDestination, CAmount> balances = pwalletMain->GetAddressBalances();
BOOST_FOREACH(set<CTxDestination> grouping, pwalletMain->GetAddressGroupings())
{
Array jsonGrouping;
@@ -483,7 +483,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
nMinDepth = params[1].get_int();
// Tally
- int64_t nAmount = 0;
+ CAmount nAmount = 0;
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
@@ -532,7 +532,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
set<CTxDestination> setAddress = pwalletMain->GetAccountAddresses(strAccount);
// Tally
- int64_t nAmount = 0;
+ CAmount nAmount = 0;
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
@@ -552,9 +552,9 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
}
-int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter)
+CAmount GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter)
{
- int64_t nBalance = 0;
+ CAmount nBalance = 0;
// Tally wallet transactions
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
@@ -563,7 +563,7 @@ int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi
if (!IsFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
continue;
- int64_t nReceived, nSent, nFee;
+ CAmount nReceived, nSent, nFee;
wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter);
if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
@@ -577,7 +577,7 @@ int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi
return nBalance;
}
-int64_t GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter)
+CAmount GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter)
{
CWalletDB walletdb(pwalletMain->strWalletFile);
return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
@@ -627,14 +627,14 @@ Value getbalance(const Array& params, bool fHelp)
// Calculate total balance a different way from GetBalance()
// (GetBalance() sums up all unspent TxOuts)
// getbalance and getbalance '*' 0 should return the same number
- int64_t nBalance = 0;
+ CAmount nBalance = 0;
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
if (!wtx.IsTrusted() || wtx.GetBlocksToMaturity() > 0)
continue;
- int64_t allFee;
+ CAmount allFee;
string strSentAccount;
list<COutputEntry> listReceived;
list<COutputEntry> listSent;
@@ -653,7 +653,7 @@ Value getbalance(const Array& params, bool fHelp)
string strAccount = AccountFromValue(params[0]);
- int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, filter);
+ CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, filter);
return ValueFromAmount(nBalance);
}
@@ -692,7 +692,7 @@ Value movecmd(const Array& params, bool fHelp)
string strFrom = AccountFromValue(params[0]);
string strTo = AccountFromValue(params[1]);
- int64_t nAmount = AmountFromValue(params[2]);
+ CAmount nAmount = AmountFromValue(params[2]);
if (params.size() > 3)
// unused parameter, used to be nMinDepth, keep type-checking it though
(void)params[3].get_int();
@@ -766,7 +766,7 @@ Value sendfrom(const Array& params, bool fHelp)
CBitcoinAddress address(params[1].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
- int64_t nAmount = AmountFromValue(params[2]);
+ CAmount nAmount = AmountFromValue(params[2]);
int nMinDepth = 1;
if (params.size() > 3)
nMinDepth = params[3].get_int();
@@ -781,7 +781,7 @@ Value sendfrom(const Array& params, bool fHelp)
EnsureWalletIsUnlocked();
// Check funds
- int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
+ CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
if (nAmount > nBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
@@ -834,9 +834,9 @@ Value sendmany(const Array& params, bool fHelp)
wtx.mapValue["comment"] = params[3].get_str();
set<CBitcoinAddress> setAddress;
- vector<pair<CScript, int64_t> > vecSend;
+ vector<pair<CScript, CAmount> > vecSend;
- int64_t totalAmount = 0;
+ CAmount totalAmount = 0;
BOOST_FOREACH(const Pair& s, sendTo)
{
CBitcoinAddress address(s.name_);
@@ -848,7 +848,7 @@ Value sendmany(const Array& params, bool fHelp)
setAddress.insert(address);
CScript scriptPubKey = GetScriptForDestination(address.Get());
- int64_t nAmount = AmountFromValue(s.value_);
+ CAmount nAmount = AmountFromValue(s.value_);
totalAmount += nAmount;
vecSend.push_back(make_pair(scriptPubKey, nAmount));
@@ -857,13 +857,13 @@ Value sendmany(const Array& params, bool fHelp)
EnsureWalletIsUnlocked();
// Check funds
- int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
+ CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
if (totalAmount > nBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
// Send
CReserveKey keyChange(pwalletMain);
- int64_t nFeeRequired = 0;
+ CAmount nFeeRequired = 0;
string strFailReason;
bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason);
if (!fCreated)
@@ -923,7 +923,7 @@ Value addmultisigaddress(const Array& params, bool fHelp)
struct tallyitem
{
- int64_t nAmount;
+ CAmount nAmount;
int nConf;
vector<uint256> txids;
bool fIsWatchonly;
@@ -995,7 +995,7 @@ Value ListReceived(const Array& params, bool fByAccounts)
if (it == mapTally.end() && !fIncludeEmpty)
continue;
- int64_t nAmount = 0;
+ CAmount nAmount = 0;
int nConf = std::numeric_limits<int>::max();
bool fIsWatchonly = false;
if (it != mapTally.end())
@@ -1038,7 +1038,7 @@ Value ListReceived(const Array& params, bool fByAccounts)
{
for (map<string, tallyitem>::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it)
{
- int64_t nAmount = (*it).second.nAmount;
+ CAmount nAmount = (*it).second.nAmount;
int nConf = (*it).second.nConf;
Object obj;
if((*it).second.fIsWatchonly)
@@ -1125,7 +1125,7 @@ static void MaybePushAddress(Object & entry, const CTxDestination &dest)
void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret, const isminefilter& filter)
{
- int64_t nFee;
+ CAmount nFee;
string strSentAccount;
list<COutputEntry> listReceived;
list<COutputEntry> listSent;
@@ -1355,7 +1355,7 @@ Value listaccounts(const Array& params, bool fHelp)
if(params[1].get_bool())
includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY;
- map<string, int64_t> mapAccountBalances;
+ map<string, CAmount> mapAccountBalances;
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) {
if (IsMine(*pwalletMain, entry.first) & includeWatchonly) // This address belongs to me
mapAccountBalances[entry.second.name] = 0;
@@ -1364,7 +1364,7 @@ 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_t nFee;
+ CAmount nFee;
string strSentAccount;
list<COutputEntry> listReceived;
list<COutputEntry> listSent;
@@ -1391,7 +1391,7 @@ Value listaccounts(const Array& params, bool fHelp)
mapAccountBalances[entry.strAccount] += entry.nCreditDebit;
Object ret;
- BOOST_FOREACH(const PAIRTYPE(string, int64_t)& accountBalance, mapAccountBalances) {
+ BOOST_FOREACH(const PAIRTYPE(string, CAmount)& accountBalance, mapAccountBalances) {
ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second)));
}
return ret;
@@ -1534,10 +1534,10 @@ Value gettransaction(const Array& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
const CWalletTx& wtx = pwalletMain->mapWallet[hash];
- int64_t nCredit = wtx.GetCredit(filter != 0);
- int64_t nDebit = wtx.GetDebit(filter);
- int64_t nNet = nCredit - nDebit;
- int64_t nFee = (wtx.IsFromMe(filter) ? wtx.GetValueOut() - nDebit : 0);
+ CAmount nCredit = wtx.GetCredit(filter != 0);
+ CAmount nDebit = wtx.GetDebit(filter);
+ CAmount nNet = nCredit - nDebit;
+ CAmount nFee = (wtx.IsFromMe(filter) ? wtx.GetValueOut() - nDebit : 0);
entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
if (wtx.IsFromMe(filter))
@@ -1937,7 +1937,7 @@ Value settxfee(const Array& params, bool fHelp)
);
// Amount
- int64_t nAmount = 0;
+ CAmount nAmount = 0;
if (params[0].get_real() != 0.0)
nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts