Browse Source

Use a typedef for monetary values

0.10
Mark Friedenbach 11 years ago committed by Mark Friedenbach
parent
commit
a372168e77
  1. 1
      src/Makefile.am
  2. 13
      src/amount.h
  3. 4
      src/bitcoin-tx.cpp
  4. 4
      src/coins.cpp
  5. 4
      src/coins.h
  6. 12
      src/core.cpp
  7. 21
      src/core.h
  8. 6
      src/init.cpp
  9. 26
      src/main.cpp
  10. 6
      src/main.h
  11. 10
      src/miner.cpp
  12. 28
      src/qt/bitcoinamountfield.cpp
  13. 10
      src/qt/bitcoinamountfield.h
  14. 2
      src/qt/bitcoingui.cpp
  15. 4
      src/qt/bitcoingui.h
  16. 13
      src/qt/bitcoinunits.cpp
  17. 12
      src/qt/bitcoinunits.h
  18. 16
      src/qt/coincontroldialog.cpp
  19. 4
      src/qt/coincontroldialog.h
  20. 2
      src/qt/guiutil.cpp
  21. 4
      src/qt/guiutil.h
  22. 4
      src/qt/optionsmodel.cpp
  23. 4
      src/qt/optionsmodel.h
  24. 4
      src/qt/overviewpage.cpp
  25. 18
      src/qt/overviewpage.h
  26. 4
      src/qt/paymentrequestplus.cpp
  27. 2
      src/qt/paymentrequestplus.h
  28. 4
      src/qt/paymentserver.cpp
  29. 10
      src/qt/sendcoinsdialog.cpp
  30. 4
      src/qt/sendcoinsdialog.h
  31. 14
      src/qt/transactiondesc.cpp
  32. 2
      src/qt/transactionfilterproxy.cpp
  33. 6
      src/qt/transactionfilterproxy.h
  34. 12
      src/qt/transactionrecord.cpp
  35. 7
      src/qt/transactionrecord.h
  36. 4
      src/qt/transactiontablemodel.cpp
  37. 2
      src/qt/transactionview.cpp
  38. 40
      src/qt/walletmodel.cpp
  39. 32
      src/qt/walletmodel.h
  40. 8
      src/qt/walletmodeltransaction.cpp
  41. 8
      src/qt/walletmodeltransaction.h
  42. 2
      src/qt/walletview.cpp
  43. 4
      src/qt/walletview.h
  44. 2
      src/rpcmining.cpp
  45. 4
      src/rpcrawtransaction.cpp
  46. 6
      src/rpcserver.cpp
  47. 5
      src/rpcserver.h
  48. 62
      src/rpcwallet.cpp
  49. 4
      src/test/accounting_tests.cpp
  50. 4
      src/test/main_tests.cpp
  51. 2
      src/test/util_tests.cpp
  52. 4
      src/test/wallet_tests.cpp
  53. 2
      src/txdb.cpp
  54. 17
      src/txmempool.cpp
  55. 12
      src/txmempool.h
  56. 1
      src/util.h
  57. 8
      src/utilmoneystr.cpp
  58. 8
      src/utilmoneystr.h
  59. 108
      src/wallet.cpp
  60. 100
      src/wallet.h
  61. 4
      src/walletdb.cpp
  62. 3
      src/walletdb.h

1
src/Makefile.am

@ -65,6 +65,7 @@ BITCOIN_CORE_H = \
addrman.h \ addrman.h \
alert.h \ alert.h \
allocators.h \ allocators.h \
amount.h \
base58.h \ base58.h \
bloom.h \ bloom.h \
chainparams.h \ chainparams.h \

13
src/amount.h

@ -0,0 +1,13 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2014 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_AMOUNT_H
#define BITCOIN_AMOUNT_H
#include <stdint.h>
typedef int64_t CAmount;
#endif

4
src/bitcoin-tx.cpp

@ -214,7 +214,7 @@ static void MutateTxAddOutAddr(CMutableTransaction& tx, const string& strInput)
// extract and validate VALUE // extract and validate VALUE
string strValue = strInput.substr(0, pos); string strValue = strInput.substr(0, pos);
int64_t value; CAmount value;
if (!ParseMoney(strValue, value)) if (!ParseMoney(strValue, value))
throw runtime_error("invalid TX output value"); throw runtime_error("invalid TX output value");
@ -242,7 +242,7 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const string& strInput
// extract and validate VALUE // extract and validate VALUE
string strValue = strInput.substr(0, pos); string strValue = strInput.substr(0, pos);
int64_t value; CAmount value;
if (!ParseMoney(strValue, value)) if (!ParseMoney(strValue, value))
throw runtime_error("invalid TX output value"); throw runtime_error("invalid TX output value");

4
src/coins.cpp

@ -171,12 +171,12 @@ const CTxOut &CCoinsViewCache::GetOutputFor(const CTxIn& input) const
return coins->vout[input.prevout.n]; return coins->vout[input.prevout.n];
} }
int64_t CCoinsViewCache::GetValueIn(const CTransaction& tx) const CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const
{ {
if (tx.IsCoinBase()) if (tx.IsCoinBase())
return 0; return 0;
int64_t nResult = 0; CAmount nResult = 0;
for (unsigned int i = 0; i < tx.vin.size(); i++) for (unsigned int i = 0; i < tx.vin.size(); i++)
nResult += GetOutputFor(tx.vin[i]).nValue; nResult += GetOutputFor(tx.vin[i]).nValue;

4
src/coins.h

@ -266,7 +266,7 @@ struct CCoinsStats
uint64_t nTransactionOutputs; uint64_t nTransactionOutputs;
uint64_t nSerializedSize; uint64_t nSerializedSize;
uint256 hashSerialized; uint256 hashSerialized;
int64_t nTotalAmount; CAmount nTotalAmount;
CCoinsStats() : nHeight(0), hashBlock(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), hashSerialized(0), nTotalAmount(0) {} CCoinsStats() : nHeight(0), hashBlock(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), hashSerialized(0), nTotalAmount(0) {}
}; };
@ -367,7 +367,7 @@ public:
@param[in] tx transaction for which we are checking input total @param[in] tx transaction for which we are checking input total
@return Sum of value of all inputs (scriptSigs) @return Sum of value of all inputs (scriptSigs)
*/ */
int64_t GetValueIn(const CTransaction& tx) const; CAmount GetValueIn(const CTransaction& tx) const;
// Check whether all prevouts of the transaction are present in the UTXO set represented by this view // Check whether all prevouts of the transaction are present in the UTXO set represented by this view
bool HaveInputs(const CTransaction& tx) const; bool HaveInputs(const CTransaction& tx) const;

12
src/core.cpp

@ -43,7 +43,7 @@ std::string CTxIn::ToString() const
return str; return str;
} }
CTxOut::CTxOut(int64_t nValueIn, CScript scriptPubKeyIn) CTxOut::CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn)
{ {
nValue = nValueIn; nValue = nValueIn;
scriptPubKey = scriptPubKeyIn; scriptPubKey = scriptPubKeyIn;
@ -59,7 +59,7 @@ std::string CTxOut::ToString() const
return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30)); return strprintf("CTxOut(nValue=%d.%08d, scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30));
} }
CFeeRate::CFeeRate(int64_t nFeePaid, size_t nSize) CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize)
{ {
if (nSize > 0) if (nSize > 0)
nSatoshisPerK = nFeePaid*1000/nSize; nSatoshisPerK = nFeePaid*1000/nSize;
@ -67,9 +67,9 @@ CFeeRate::CFeeRate(int64_t nFeePaid, size_t nSize)
nSatoshisPerK = 0; nSatoshisPerK = 0;
} }
int64_t CFeeRate::GetFee(size_t nSize) const CAmount CFeeRate::GetFee(size_t nSize) const
{ {
int64_t nFee = nSatoshisPerK*nSize / 1000; CAmount nFee = nSatoshisPerK*nSize / 1000;
if (nFee == 0 && nSatoshisPerK > 0) if (nFee == 0 && nSatoshisPerK > 0)
nFee = nSatoshisPerK; nFee = nSatoshisPerK;
@ -110,9 +110,9 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) {
return *this; return *this;
} }
int64_t CTransaction::GetValueOut() const CAmount CTransaction::GetValueOut() const
{ {
int64_t nValueOut = 0; CAmount nValueOut = 0;
BOOST_FOREACH(const CTxOut& txout, vout) BOOST_FOREACH(const CTxOut& txout, vout)
{ {
nValueOut += txout.nValue; nValueOut += txout.nValue;

21
src/core.h

@ -6,6 +6,7 @@
#ifndef BITCOIN_CORE_H #ifndef BITCOIN_CORE_H
#define BITCOIN_CORE_H #define BITCOIN_CORE_H
#include "amount.h"
#include "script/compressor.h" #include "script/compressor.h"
#include "script/script.h" #include "script/script.h"
#include "serialize.h" #include "serialize.h"
@ -19,8 +20,8 @@ static const int64_t COIN = 100000000;
static const int64_t CENT = 1000000; static const int64_t CENT = 1000000;
/** No amount larger than this (in satoshi) is valid */ /** No amount larger than this (in satoshi) is valid */
static const int64_t MAX_MONEY = 21000000 * COIN; static const CAmount MAX_MONEY = 21000000 * COIN;
inline bool MoneyRange(int64_t nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
/** An outpoint - a combination of a transaction hash and an index n into its vout */ /** An outpoint - a combination of a transaction hash and an index n into its vout */
class COutPoint class COutPoint
@ -129,15 +130,15 @@ public:
class CFeeRate class CFeeRate
{ {
private: private:
int64_t nSatoshisPerK; // unit is satoshis-per-1,000-bytes CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
public: public:
CFeeRate() : nSatoshisPerK(0) { } CFeeRate() : nSatoshisPerK(0) { }
explicit CFeeRate(int64_t _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { } explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
CFeeRate(int64_t nFeePaid, size_t nSize); CFeeRate(const CAmount& nFeePaid, size_t nSize);
CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; } CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }
int64_t GetFee(size_t size) const; // unit returned is satoshis CAmount GetFee(size_t size) const; // unit returned is satoshis
int64_t GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes CAmount GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes
friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; } friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; }
friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; } friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; }
@ -161,7 +162,7 @@ public:
class CTxOut class CTxOut
{ {
public: public:
int64_t nValue; CAmount nValue;
CScript scriptPubKey; CScript scriptPubKey;
CTxOut() CTxOut()
@ -169,7 +170,7 @@ public:
SetNull(); SetNull();
} }
CTxOut(int64_t nValueIn, CScript scriptPubKeyIn); CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn);
ADD_SERIALIZE_METHODS; ADD_SERIALIZE_METHODS;
@ -276,7 +277,7 @@ public:
} }
// Return sum of txouts. // Return sum of txouts.
int64_t GetValueOut() const; CAmount GetValueOut() const;
// GetValueIn() is a method on CCoinsViewCache, because // GetValueIn() is a method on CCoinsViewCache, because
// inputs must be known to compute value in. // inputs must be known to compute value in.

6
src/init.cpp

@ -662,7 +662,7 @@ bool AppInit2(boost::thread_group& threadGroup)
// cost to you of processing a transaction. // cost to you of processing a transaction.
if (mapArgs.count("-minrelaytxfee")) if (mapArgs.count("-minrelaytxfee"))
{ {
int64_t n = 0; CAmount n = 0;
if (ParseMoney(mapArgs["-minrelaytxfee"], n) && n > 0) if (ParseMoney(mapArgs["-minrelaytxfee"], n) && n > 0)
::minRelayTxFee = CFeeRate(n); ::minRelayTxFee = CFeeRate(n);
else else
@ -672,7 +672,7 @@ bool AppInit2(boost::thread_group& threadGroup)
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
if (mapArgs.count("-mintxfee")) if (mapArgs.count("-mintxfee"))
{ {
int64_t n = 0; CAmount n = 0;
if (ParseMoney(mapArgs["-mintxfee"], n) && n > 0) if (ParseMoney(mapArgs["-mintxfee"], n) && n > 0)
CWallet::minTxFee = CFeeRate(n); CWallet::minTxFee = CFeeRate(n);
else else
@ -680,7 +680,7 @@ bool AppInit2(boost::thread_group& threadGroup)
} }
if (mapArgs.count("-paytxfee")) if (mapArgs.count("-paytxfee"))
{ {
int64_t nFeePerK = 0; CAmount nFeePerK = 0;
if (!ParseMoney(mapArgs["-paytxfee"], nFeePerK)) if (!ParseMoney(mapArgs["-paytxfee"], nFeePerK))
return InitError(strprintf(_("Invalid amount for -paytxfee=<amount>: '%s'"), mapArgs["-paytxfee"])); return InitError(strprintf(_("Invalid amount for -paytxfee=<amount>: '%s'"), mapArgs["-paytxfee"]));
if (nFeePerK > nHighTransactionFeeWarning) if (nFeePerK > nHighTransactionFeeWarning)

26
src/main.cpp

@ -781,7 +781,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
REJECT_INVALID, "bad-txns-oversize"); REJECT_INVALID, "bad-txns-oversize");
// Check for negative or overflow output values // Check for negative or overflow output values
int64_t nValueOut = 0; CAmount nValueOut = 0;
BOOST_FOREACH(const CTxOut& txout, tx.vout) BOOST_FOREACH(const CTxOut& txout, tx.vout)
{ {
if (txout.nValue < 0) if (txout.nValue < 0)
@ -823,19 +823,19 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
return true; return true;
} }
int64_t GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree) CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree)
{ {
{ {
LOCK(mempool.cs); LOCK(mempool.cs);
uint256 hash = tx.GetHash(); uint256 hash = tx.GetHash();
double dPriorityDelta = 0; double dPriorityDelta = 0;
int64_t nFeeDelta = 0; CAmount nFeeDelta = 0;
mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
if (dPriorityDelta > 0 || nFeeDelta > 0) if (dPriorityDelta > 0 || nFeeDelta > 0)
return 0; return 0;
} }
int64_t nMinFee = ::minRelayTxFee.GetFee(nBytes); CAmount nMinFee = ::minRelayTxFee.GetFee(nBytes);
if (fAllowFree) if (fAllowFree)
{ {
@ -898,7 +898,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
CCoinsView dummy; CCoinsView dummy;
CCoinsViewCache view(dummy); CCoinsViewCache view(dummy);
int64_t nValueIn = 0; CAmount nValueIn = 0;
{ {
LOCK(pool.cs); LOCK(pool.cs);
CCoinsViewMemPool viewMemPool(*pcoinsTip, pool); CCoinsViewMemPool viewMemPool(*pcoinsTip, pool);
@ -950,15 +950,15 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
hash.ToString(), nSigOps, MAX_TX_SIGOPS), hash.ToString(), nSigOps, MAX_TX_SIGOPS),
REJECT_NONSTANDARD, "bad-txns-too-many-sigops"); REJECT_NONSTANDARD, "bad-txns-too-many-sigops");
int64_t nValueOut = tx.GetValueOut(); CAmount nValueOut = tx.GetValueOut();
int64_t nFees = nValueIn-nValueOut; CAmount nFees = nValueIn-nValueOut;
double dPriority = view.GetPriority(tx, chainActive.Height()); double dPriority = view.GetPriority(tx, chainActive.Height());
CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height()); CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height());
unsigned int nSize = entry.GetTxSize(); unsigned int nSize = entry.GetTxSize();
// Don't accept it if it can't get into a block // Don't accept it if it can't get into a block
int64_t txMinFee = GetMinRelayFee(tx, nSize, true); CAmount txMinFee = GetMinRelayFee(tx, nSize, true);
if (fLimitFree && nFees < txMinFee) if (fLimitFree && nFees < txMinFee)
return state.DoS(0, error("AcceptToMemoryPool : not enough fees %s, %d < %d", return state.DoS(0, error("AcceptToMemoryPool : not enough fees %s, %d < %d",
hash.ToString(), nFees, txMinFee), hash.ToString(), nFees, txMinFee),
@ -1178,7 +1178,7 @@ void static PruneOrphanBlocks()
mapOrphanBlocks.erase(hash); mapOrphanBlocks.erase(hash);
} }
int64_t GetBlockValue(int nHeight, int64_t nFees) CAmount GetBlockValue(int nHeight, const CAmount& nFees)
{ {
int64_t nSubsidy = 50 * COIN; int64_t nSubsidy = 50 * COIN;
int halvings = nHeight / Params().SubsidyHalvingInterval(); int halvings = nHeight / Params().SubsidyHalvingInterval();
@ -1389,8 +1389,8 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
// This is also true for mempool checks. // This is also true for mempool checks.
CBlockIndex *pindexPrev = mapBlockIndex.find(inputs.GetBestBlock())->second; CBlockIndex *pindexPrev = mapBlockIndex.find(inputs.GetBestBlock())->second;
int nSpendHeight = pindexPrev->nHeight + 1; int nSpendHeight = pindexPrev->nHeight + 1;
int64_t nValueIn = 0; CAmount nValueIn = 0;
int64_t nFees = 0; CAmount nFees = 0;
for (unsigned int i = 0; i < tx.vin.size(); i++) for (unsigned int i = 0; i < tx.vin.size(); i++)
{ {
const COutPoint &prevout = tx.vin[i].prevout; const COutPoint &prevout = tx.vin[i].prevout;
@ -1418,7 +1418,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
REJECT_INVALID, "bad-txns-in-belowout"); REJECT_INVALID, "bad-txns-in-belowout");
// Tally transaction fees // Tally transaction fees
int64_t nTxFee = nValueIn - tx.GetValueOut(); CAmount nTxFee = nValueIn - tx.GetValueOut();
if (nTxFee < 0) if (nTxFee < 0)
return state.DoS(100, error("CheckInputs() : %s nTxFee < 0", tx.GetHash().ToString()), return state.DoS(100, error("CheckInputs() : %s nTxFee < 0", tx.GetHash().ToString()),
REJECT_INVALID, "bad-txns-fee-negative"); REJECT_INVALID, "bad-txns-fee-negative");
@ -1658,7 +1658,7 @@ bool ConnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, C
CCheckQueueControl<CScriptCheck> control(fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL); CCheckQueueControl<CScriptCheck> control(fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL);
int64_t nTimeStart = GetTimeMicros(); int64_t nTimeStart = GetTimeMicros();
int64_t nFees = 0; CAmount nFees = 0;
int nInputs = 0; int nInputs = 0;
unsigned int nSigOps = 0; unsigned int nSigOps = 0;
CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size())); CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));

6
src/main.h

@ -172,7 +172,7 @@ std::string GetWarnings(std::string strFor);
bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, bool fAllowSlow = false); bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, bool fAllowSlow = false);
/** Find the best known block, and make it the tip of the block chain */ /** Find the best known block, and make it the tip of the block chain */
bool ActivateBestChain(CValidationState &state, CBlock *pblock = NULL); bool ActivateBestChain(CValidationState &state, CBlock *pblock = NULL);
int64_t GetBlockValue(int nHeight, int64_t nFees); CAmount GetBlockValue(int nHeight, const CAmount& nFees);
/** Create a new block index entry for a given block hash */ /** Create a new block index entry for a given block hash */
CBlockIndex * InsertBlockIndex(uint256 hash); CBlockIndex * InsertBlockIndex(uint256 hash);
@ -260,7 +260,7 @@ struct CDiskTxPos : public CDiskBlockPos
}; };
int64_t GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree); CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree);
// //
// Check transaction inputs, and make sure any // Check transaction inputs, and make sure any
@ -970,7 +970,7 @@ extern CBlockTreeDB *pblocktree;
struct CBlockTemplate struct CBlockTemplate
{ {
CBlock block; CBlock block;
std::vector<int64_t> vTxFees; std::vector<CAmount> vTxFees;
std::vector<int64_t> vTxSigOps; std::vector<int64_t> vTxSigOps;
}; };

10
src/miner.cpp

@ -111,7 +111,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize); nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);
// Collect memory pool transactions into the block // Collect memory pool transactions into the block
int64_t nFees = 0; CAmount nFees = 0;
{ {
LOCK2(cs_main, mempool.cs); LOCK2(cs_main, mempool.cs);
@ -135,7 +135,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
COrphan* porphan = NULL; COrphan* porphan = NULL;
double dPriority = 0; double dPriority = 0;
int64_t nTotalIn = 0; CAmount nTotalIn = 0;
bool fMissingInputs = false; bool fMissingInputs = false;
BOOST_FOREACH(const CTxIn& txin, tx.vin) BOOST_FOREACH(const CTxIn& txin, tx.vin)
{ {
@ -170,7 +170,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
const CCoins* coins = view.AccessCoins(txin.prevout.hash); const CCoins* coins = view.AccessCoins(txin.prevout.hash);
assert(coins); assert(coins);
int64_t nValueIn = coins->vout[txin.prevout.n].nValue; CAmount nValueIn = coins->vout[txin.prevout.n].nValue;
nTotalIn += nValueIn; nTotalIn += nValueIn;
int nConf = pindexPrev->nHeight - coins->nHeight + 1; int nConf = pindexPrev->nHeight - coins->nHeight + 1;
@ -229,7 +229,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
// Skip free transactions if we're past the minimum block size: // Skip free transactions if we're past the minimum block size:
const uint256& hash = tx.GetHash(); const uint256& hash = tx.GetHash();
double dPriorityDelta = 0; double dPriorityDelta = 0;
int64_t nFeeDelta = 0; CAmount nFeeDelta = 0;
mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize)) if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
continue; continue;
@ -247,7 +247,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
if (!view.HaveInputs(tx)) if (!view.HaveInputs(tx))
continue; continue;
int64_t nTxFees = view.GetValueIn(tx)-tx.GetValueOut(); CAmount nTxFees = view.GetValueIn(tx)-tx.GetValueOut();
nTxSigOps += GetP2SHSigOpCount(tx, view); nTxSigOps += GetP2SHSigOpCount(tx, view);
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)

28
src/qt/bitcoinamountfield.cpp

@ -44,7 +44,7 @@ public:
void fixup(QString &input) const void fixup(QString &input) const
{ {
bool valid = false; bool valid = false;
qint64 val = parse(input, &valid); CAmount val = parse(input, &valid);
if(valid) if(valid)
{ {
input = BitcoinUnits::format(currentUnit, val, false, BitcoinUnits::separatorAlways); input = BitcoinUnits::format(currentUnit, val, false, BitcoinUnits::separatorAlways);
@ -52,12 +52,12 @@ public:
} }
} }
qint64 value(bool *valid_out=0) const CAmount value(bool *valid_out=0) const
{ {
return parse(text(), valid_out); return parse(text(), valid_out);
} }
void setValue(qint64 value) void setValue(const CAmount& value)
{ {
lineEdit()->setText(BitcoinUnits::format(currentUnit, value, false, BitcoinUnits::separatorAlways)); lineEdit()->setText(BitcoinUnits::format(currentUnit, value, false, BitcoinUnits::separatorAlways));
emit valueChanged(); emit valueChanged();
@ -66,9 +66,9 @@ public:
void stepBy(int steps) void stepBy(int steps)
{ {
bool valid = false; bool valid = false;
qint64 val = value(&valid); CAmount val = value(&valid);
val = val + steps * singleStep; val = val + steps * singleStep;
val = qMin(qMax(val, Q_INT64_C(0)), BitcoinUnits::maxMoney()); val = qMin(qMax(val, CAmount(0)), BitcoinUnits::maxMoney());
setValue(val); setValue(val);
} }
@ -78,7 +78,7 @@ public:
if(text().isEmpty()) // Allow step-up with empty field if(text().isEmpty()) // Allow step-up with empty field
return StepUpEnabled; return StepUpEnabled;
bool valid = false; bool valid = false;
qint64 val = value(&valid); CAmount val = value(&valid);
if(valid) if(valid)
{ {
if(val > 0) if(val > 0)
@ -92,7 +92,7 @@ public:
void setDisplayUnit(int unit) void setDisplayUnit(int unit)
{ {
bool valid = false; bool valid = false;
qint64 val = value(&valid); CAmount val = value(&valid);
currentUnit = unit; currentUnit = unit;
@ -102,7 +102,7 @@ public:
clear(); clear();
} }
void setSingleStep(qint64 step) void setSingleStep(const CAmount& step)
{ {
singleStep = step; singleStep = step;
} }
@ -140,7 +140,7 @@ public:
} }
private: private:
int currentUnit; int currentUnit;
qint64 singleStep; CAmount singleStep;
mutable QSize cachedMinimumSizeHint; mutable QSize cachedMinimumSizeHint;
/** /**
@ -148,9 +148,9 @@ private:
* return validity. * return validity.
* @note Must return 0 if !valid. * @note Must return 0 if !valid.
*/ */
qint64 parse(const QString &text, bool *valid_out=0) const CAmount parse(const QString &text, bool *valid_out=0) const
{ {
qint64 val = 0; CAmount val = 0;
bool valid = BitcoinUnits::parse(currentUnit, text, &val); bool valid = BitcoinUnits::parse(currentUnit, text, &val);
if(valid) if(valid)
{ {
@ -253,12 +253,12 @@ QWidget *BitcoinAmountField::setupTabChain(QWidget *prev)
return unit; return unit;
} }
qint64 BitcoinAmountField::value(bool *valid_out) const CAmount BitcoinAmountField::value(bool *valid_out) const
{ {
return amount->value(valid_out); return amount->value(valid_out);
} }
void BitcoinAmountField::setValue(qint64 value) void BitcoinAmountField::setValue(const CAmount& value)
{ {
amount->setValue(value); amount->setValue(value);
} }
@ -285,7 +285,7 @@ void BitcoinAmountField::setDisplayUnit(int newUnit)
unit->setValue(newUnit); unit->setValue(newUnit);
} }
void BitcoinAmountField::setSingleStep(qint64 step) void BitcoinAmountField::setSingleStep(const CAmount& step)
{ {
amount->setSingleStep(step); amount->setSingleStep(step);
} }

10
src/qt/bitcoinamountfield.h

@ -5,6 +5,8 @@
#ifndef BITCOINAMOUNTFIELD_H #ifndef BITCOINAMOUNTFIELD_H
#define BITCOINAMOUNTFIELD_H #define BITCOINAMOUNTFIELD_H
#include "amount.h"
#include <QWidget> #include <QWidget>
class AmountSpinBox; class AmountSpinBox;
@ -19,16 +21,16 @@ class BitcoinAmountField: public QWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(qint64 value READ value WRITE setValue NOTIFY valueChanged USER true) Q_PROPERTY(CAmount value READ value WRITE setValue NOTIFY valueChanged USER true)
public: public:
explicit BitcoinAmountField(QWidget *parent = 0); explicit BitcoinAmountField(QWidget *parent = 0);
qint64 value(bool *valid=0) const; CAmount value(bool *value=0) const;
void setValue(qint64 value); void setValue(const CAmount& value);
/** Set single step in satoshis **/ /** Set single step in satoshis **/
void setSingleStep(qint64 step); void setSingleStep(const CAmount& step);
/** Make read-only **/ /** Make read-only **/
void setReadOnly(bool fReadOnly); void setReadOnly(bool fReadOnly);

2
src/qt/bitcoingui.cpp

@ -864,7 +864,7 @@ void BitcoinGUI::closeEvent(QCloseEvent *event)
} }
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
void BitcoinGUI::incomingTransaction(const QString& date, int unit, qint64 amount, const QString& type, const QString& address) void BitcoinGUI::incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address)
{ {
// On new transaction, make an info balloon // On new transaction, make an info balloon
message((amount)<0 ? tr("Sent transaction") : tr("Incoming transaction"), message((amount)<0 ? tr("Sent transaction") : tr("Incoming transaction"),

4
src/qt/bitcoingui.h

@ -9,6 +9,8 @@
#include "config/bitcoin-config.h" #include "config/bitcoin-config.h"
#endif #endif
#include "amount.h"
#include <QLabel> #include <QLabel>
#include <QMainWindow> #include <QMainWindow>
#include <QMap> #include <QMap>
@ -159,7 +161,7 @@ public slots:
bool handlePaymentRequest(const SendCoinsRecipient& recipient); bool handlePaymentRequest(const SendCoinsRecipient& recipient);
/** Show incoming transaction notification for new transactions. */ /** Show incoming transaction notification for new transactions. */
void incomingTransaction(const QString& date, int unit, qint64 amount, const QString& type, const QString& address); void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address);
#endif #endif
private slots: private slots:

13
src/qt/bitcoinunits.cpp

@ -91,12 +91,13 @@ int BitcoinUnits::decimals(int unit)
} }
} }
QString BitcoinUnits::format(int unit, qint64 n, bool fPlus, SeparatorStyle separators) QString BitcoinUnits::format(int unit, const CAmount& nIn, bool fPlus, SeparatorStyle separators)
{ {
// Note: not using straight sprintf here because we do NOT want // Note: not using straight sprintf here because we do NOT want
// localized number formatting. // localized number formatting.
if(!valid(unit)) if(!valid(unit))
return QString(); // Refuse to format invalid unit return QString(); // Refuse to format invalid unit
qint64 n = (qint64)nIn;
qint64 coin = factor(unit); qint64 coin = factor(unit);
int num_decimals = decimals(unit); int num_decimals = decimals(unit);
qint64 n_abs = (n > 0 ? n : -n); qint64 n_abs = (n > 0 ? n : -n);
@ -138,12 +139,12 @@ QString BitcoinUnits::format(int unit, qint64 n, bool fPlus, SeparatorStyle sepa
// Please take care to use formatHtmlWithUnit instead, when // Please take care to use formatHtmlWithUnit instead, when
// appropriate. // appropriate.
QString BitcoinUnits::formatWithUnit(int unit, qint64 amount, bool plussign, SeparatorStyle separators) QString BitcoinUnits::formatWithUnit(int unit, const CAmount& amount, bool plussign, SeparatorStyle separators)
{ {
return format(unit, amount, plussign, separators) + QString(" ") + name(unit); return format(unit, amount, plussign, separators) + QString(" ") + name(unit);
} }
QString BitcoinUnits::formatHtmlWithUnit(int unit, qint64 amount, bool plussign, SeparatorStyle separators) QString BitcoinUnits::formatHtmlWithUnit(int unit, const CAmount& amount, bool plussign, SeparatorStyle separators)
{ {
QString str(formatWithUnit(unit, amount, plussign, separators)); QString str(formatWithUnit(unit, amount, plussign, separators));
str.replace(QChar(THIN_SP_CP), QString(THIN_SP_HTML)); str.replace(QChar(THIN_SP_CP), QString(THIN_SP_HTML));
@ -151,7 +152,7 @@ QString BitcoinUnits::formatHtmlWithUnit(int unit, qint64 amount, bool plussign,
} }
bool BitcoinUnits::parse(int unit, const QString &value, qint64 *val_out) bool BitcoinUnits::parse(int unit, const QString &value, CAmount *val_out)
{ {
if(!valid(unit) || value.isEmpty()) if(!valid(unit) || value.isEmpty())
return false; // Refuse to parse invalid unit or empty string return false; // Refuse to parse invalid unit or empty string
@ -182,7 +183,7 @@ bool BitcoinUnits::parse(int unit, const QString &value, qint64 *val_out)
{ {
return false; // Longer numbers will exceed 63 bits return false; // Longer numbers will exceed 63 bits
} }
qint64 retvalue = str.toLongLong(&ok); CAmount retvalue(str.toLongLong(&ok));
if(val_out) if(val_out)
{ {
*val_out = retvalue; *val_out = retvalue;
@ -226,7 +227,7 @@ QVariant BitcoinUnits::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
} }
qint64 BitcoinUnits::maxMoney() CAmount BitcoinUnits::maxMoney()
{ {
return MAX_MONEY; return MAX_MONEY;
} }

12
src/qt/bitcoinunits.h

@ -5,6 +5,8 @@
#ifndef BITCOINUNITS_H #ifndef BITCOINUNITS_H
#define BITCOINUNITS_H #define BITCOINUNITS_H
#include "amount.h"
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QString> #include <QString>
@ -85,12 +87,12 @@ public:
//! Number of decimals left //! Number of decimals left
static int decimals(int unit); static int decimals(int unit);
//! Format as string //! Format as string
static QString format(int unit, qint64 amount, bool plussign=false, SeparatorStyle separators=separatorStandard); static QString format(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
//! Format as string (with unit) //! Format as string (with unit)
static QString formatWithUnit(int unit, qint64 amount, bool plussign=false, SeparatorStyle separators=separatorStandard); static QString formatWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
static QString formatHtmlWithUnit(int unit, qint64 amount, bool plussign=false, SeparatorStyle separators=separatorStandard); static QString formatHtmlWithUnit(int unit, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
//! Parse string to coin amount //! Parse string to coin amount
static bool parse(int unit, const QString &value, qint64 *val_out); static bool parse(int unit, const QString &value, CAmount *val_out);
//! Gets title for amount column including current display unit if optionsModel reference available */ //! Gets title for amount column including current display unit if optionsModel reference available */
static QString getAmountColumnTitle(int unit); static QString getAmountColumnTitle(int unit);
///@} ///@}
@ -117,7 +119,7 @@ public:
} }
//! Return maximum number of base units (Satoshis) //! Return maximum number of base units (Satoshis)
static qint64 maxMoney(); static CAmount maxMoney();
private: private:
QList<BitcoinUnits::Unit> unitlist; QList<BitcoinUnits::Unit> unitlist;

16
src/qt/coincontroldialog.cpp

@ -29,7 +29,7 @@
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
using namespace std; using namespace std;
QList<qint64> CoinControlDialog::payAmounts; QList<CAmount> CoinControlDialog::payAmounts;
CCoinControl* CoinControlDialog::coinControl = new CCoinControl(); CCoinControl* CoinControlDialog::coinControl = new CCoinControl();
CoinControlDialog::CoinControlDialog(QWidget *parent) : CoinControlDialog::CoinControlDialog(QWidget *parent) :
@ -443,10 +443,10 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
return; return;
// nPayAmount // nPayAmount
qint64 nPayAmount = 0; CAmount nPayAmount = 0;
bool fDust = false; bool fDust = false;
CMutableTransaction txDummy; CMutableTransaction txDummy;
foreach(const qint64 &amount, CoinControlDialog::payAmounts) foreach(const CAmount &amount, CoinControlDialog::payAmounts)
{ {
nPayAmount += amount; nPayAmount += amount;
@ -460,10 +460,10 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
} }
QString sPriorityLabel = tr("none"); QString sPriorityLabel = tr("none");
int64_t nAmount = 0; CAmount nAmount = 0;
int64_t nPayFee = 0; CAmount nPayFee = 0;
int64_t nAfterFee = 0; CAmount nAfterFee = 0;
int64_t nChange = 0; CAmount nChange = 0;
unsigned int nBytes = 0; unsigned int nBytes = 0;
unsigned int nBytesInputs = 0; unsigned int nBytesInputs = 0;
double dPriority = 0; double dPriority = 0;
@ -684,7 +684,7 @@ void CoinControlDialog::updateView()
itemWalletAddress->setText(COLUMN_ADDRESS, sWalletAddress); itemWalletAddress->setText(COLUMN_ADDRESS, sWalletAddress);
} }
int64_t nSum = 0; CAmount nSum = 0;
double dPrioritySum = 0; double dPrioritySum = 0;
int nChildren = 0; int nChildren = 0;
int nInputSum = 0; int nInputSum = 0;

4
src/qt/coincontroldialog.h

@ -5,6 +5,8 @@
#ifndef COINCONTROLDIALOG_H #ifndef COINCONTROLDIALOG_H
#define COINCONTROLDIALOG_H #define COINCONTROLDIALOG_H
#include "amount.h"
#include <QAbstractButton> #include <QAbstractButton>
#include <QAction> #include <QAction>
#include <QDialog> #include <QDialog>
@ -37,7 +39,7 @@ public:
static void updateLabels(WalletModel*, QDialog*); static void updateLabels(WalletModel*, QDialog*);
static QString getPriorityLabel(const CTxMemPool& pool, double); static QString getPriorityLabel(const CTxMemPool& pool, double);
static QList<qint64> payAmounts; static QList<CAmount> payAmounts;
static CCoinControl *coinControl; static CCoinControl *coinControl;
private: private:

2
src/qt/guiutil.cpp

@ -221,7 +221,7 @@ QString formatBitcoinURI(const SendCoinsRecipient &info)
return ret; return ret;
} }
bool isDust(const QString& address, qint64 amount) bool isDust(const QString& address, const CAmount& amount)
{ {
CTxDestination dest = CBitcoinAddress(address.toStdString()).Get(); CTxDestination dest = CBitcoinAddress(address.toStdString()).Get();
CScript script = GetScriptForDestination(dest); CScript script = GetScriptForDestination(dest);

4
src/qt/guiutil.h

@ -5,6 +5,8 @@
#ifndef GUIUTIL_H #ifndef GUIUTIL_H
#define GUIUTIL_H #define GUIUTIL_H
#include "amount.h"
#include <QHeaderView> #include <QHeaderView>
#include <QMessageBox> #include <QMessageBox>
#include <QObject> #include <QObject>
@ -46,7 +48,7 @@ namespace GUIUtil
QString formatBitcoinURI(const SendCoinsRecipient &info); QString formatBitcoinURI(const SendCoinsRecipient &info);
// Returns true if given address+amount meets "dust" definition // Returns true if given address+amount meets "dust" definition
bool isDust(const QString& address, qint64 amount); bool isDust(const QString& address, const CAmount& amount);
// HTML escaping for rich text controls // HTML escaping for rich text controls
QString HtmlEscape(const QString& str, bool fMultiLine=false); QString HtmlEscape(const QString& str, bool fMultiLine=false);

4
src/qt/optionsmodel.cpp

@ -275,9 +275,9 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
#ifdef ENABLE_WALLET #ifdef ENABLE_WALLET
case Fee: { // core option - can be changed on-the-fly case Fee: { // core option - can be changed on-the-fly
// Todo: Add is valid check and warn via message, if not // Todo: Add is valid check and warn via message, if not
qint64 nTransactionFee = value.toLongLong(); CAmount nTransactionFee(value.toLongLong());
payTxFee = CFeeRate(nTransactionFee, 1000); payTxFee = CFeeRate(nTransactionFee, 1000);
settings.setValue("nTransactionFee", nTransactionFee); settings.setValue("nTransactionFee", qint64(nTransactionFee));
emit transactionFeeChanged(nTransactionFee); emit transactionFeeChanged(nTransactionFee);
break; break;
} }

4
src/qt/optionsmodel.h

@ -5,6 +5,8 @@
#ifndef OPTIONSMODEL_H #ifndef OPTIONSMODEL_H
#define OPTIONSMODEL_H #define OPTIONSMODEL_H
#include "amount.h"
#include <QAbstractListModel> #include <QAbstractListModel>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -82,7 +84,7 @@ private:
signals: signals:
void displayUnitChanged(int unit); void displayUnitChanged(int unit);
void transactionFeeChanged(qint64); void transactionFeeChanged(const CAmount&);
void coinControlFeaturesChanged(bool); void coinControlFeaturesChanged(bool);
}; };

4
src/qt/overviewpage.cpp

@ -146,7 +146,7 @@ OverviewPage::~OverviewPage()
delete ui; delete ui;
} }
void OverviewPage::setBalance(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance, qint64 watchOnlyBalance, qint64 watchUnconfBalance, qint64 watchImmatureBalance) void OverviewPage::setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance, const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance)
{ {
int unit = walletModel->getOptionsModel()->getDisplayUnit(); int unit = walletModel->getOptionsModel()->getDisplayUnit();
currentBalance = balance; currentBalance = balance;
@ -220,7 +220,7 @@ void OverviewPage::setWalletModel(WalletModel *model)
// Keep up to date with wallet // Keep up to date with wallet
setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(),
model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance()); model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance());
connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64, qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64, qint64, qint64, qint64))); connect(model, SIGNAL(balanceChanged(const CAmount&, const CAmount&, const CAmount&, const CAmount&, const CAmount&, const CAmount&)), this, SLOT(setBalance(const CAmount&, const CAmount&, const CAmount&, const CAmount&, const CAmount&, const CAmount&)));
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));

18
src/qt/overviewpage.h

@ -5,6 +5,8 @@
#ifndef OVERVIEWPAGE_H #ifndef OVERVIEWPAGE_H
#define OVERVIEWPAGE_H #define OVERVIEWPAGE_H
#include "amount.h"
#include <QWidget> #include <QWidget>
class ClientModel; class ClientModel;
@ -34,8 +36,8 @@ public:
void showOutOfSyncWarning(bool fShow); void showOutOfSyncWarning(bool fShow);
public slots: public slots:
void setBalance(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance, void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
qint64 watchOnlyBalance, qint64 watchUnconfBalance, qint64 watchImmatureBalance); const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance);
signals: signals:
void transactionClicked(const QModelIndex &index); void transactionClicked(const QModelIndex &index);
@ -44,12 +46,12 @@ private:
Ui::OverviewPage *ui; Ui::OverviewPage *ui;
ClientModel *clientModel; ClientModel *clientModel;
WalletModel *walletModel; WalletModel *walletModel;
qint64 currentBalance; CAmount currentBalance;
qint64 currentUnconfirmedBalance; CAmount currentUnconfirmedBalance;
qint64 currentImmatureBalance; CAmount currentImmatureBalance;
qint64 currentWatchOnlyBalance; CAmount currentWatchOnlyBalance;
qint64 currentWatchUnconfBalance; CAmount currentWatchUnconfBalance;
qint64 currentWatchImmatureBalance; CAmount currentWatchImmatureBalance;
TxViewDelegate *txdelegate; TxViewDelegate *txdelegate;
TransactionFilterProxy *filter; TransactionFilterProxy *filter;

4
src/qt/paymentrequestplus.cpp

@ -196,9 +196,9 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
return fResult; return fResult;
} }
QList<std::pair<CScript,qint64> > PaymentRequestPlus::getPayTo() const QList<std::pair<CScript,CAmount> > PaymentRequestPlus::getPayTo() const
{ {
QList<std::pair<CScript,qint64> > result; QList<std::pair<CScript,CAmount> > result;
for (int i = 0; i < details.outputs_size(); i++) for (int i = 0; i < details.outputs_size(); i++)
{ {
const unsigned char* scriptStr = (const unsigned char*)details.outputs(i).script().data(); const unsigned char* scriptStr = (const unsigned char*)details.outputs(i).script().data();

2
src/qt/paymentrequestplus.h

@ -33,7 +33,7 @@ public:
bool getMerchant(X509_STORE* certStore, QString& merchant) const; bool getMerchant(X509_STORE* certStore, QString& merchant) const;
// Returns list of outputs, amount // Returns list of outputs, amount
QList<std::pair<CScript,qint64> > getPayTo() const; QList<std::pair<CScript,CAmount> > getPayTo() const;
const payments::PaymentDetails& getDetails() const { return details; } const payments::PaymentDetails& getDetails() const { return details; }

4
src/qt/paymentserver.cpp

@ -532,10 +532,10 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins
request.getMerchant(PaymentServer::certStore, recipient.authenticatedMerchant); request.getMerchant(PaymentServer::certStore, recipient.authenticatedMerchant);
QList<std::pair<CScript, qint64> > sendingTos = request.getPayTo(); QList<std::pair<CScript, CAmount> > sendingTos = request.getPayTo();
QStringList addresses; QStringList addresses;
foreach(const PAIRTYPE(CScript, qint64)& sendingTo, sendingTos) { foreach(const PAIRTYPE(CScript, CAmount)& sendingTo, sendingTos) {
// Extract and check destination addresses // Extract and check destination addresses
CTxDestination dest; CTxDestination dest;
if (ExtractDestination(sendingTo.first, dest)) { if (ExtractDestination(sendingTo.first, dest)) {

10
src/qt/sendcoinsdialog.cpp

@ -92,7 +92,7 @@ void SendCoinsDialog::setModel(WalletModel *model)
setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(), setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(),
model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance()); model->getWatchBalance(), model->getWatchUnconfirmedBalance(), model->getWatchImmatureBalance());
connect(model, SIGNAL(balanceChanged(qint64, qint64, qint64, qint64, qint64, qint64)), this, SLOT(setBalance(qint64, qint64, qint64, qint64, qint64, qint64))); connect(model, SIGNAL(balanceChanged(const CAmount&, const CAmount&, const CAmount&, const CAmount&, const CAmount&, const CAmount&)), this, SLOT(setBalance(const CAmount&, const CAmount&, const CAmount&, const CAmount&, const CAmount&, const CAmount&)));
connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit())); connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
// Coin Control // Coin Control
@ -203,7 +203,7 @@ void SendCoinsDialog::on_sendButton_clicked()
return; return;
} }
qint64 txFee = currentTransaction.getTransactionFee(); CAmount txFee = currentTransaction.getTransactionFee();
QString questionString = tr("Are you sure you want to send?"); QString questionString = tr("Are you sure you want to send?");
questionString.append("<br /><br />%1"); questionString.append("<br /><br />%1");
@ -218,7 +218,7 @@ void SendCoinsDialog::on_sendButton_clicked()
// add total amount in all subdivision units // add total amount in all subdivision units
questionString.append("<hr />"); questionString.append("<hr />");
qint64 totalAmount = currentTransaction.getTotalTransactionAmount() + txFee; CAmount totalAmount = currentTransaction.getTotalTransactionAmount() + txFee;
QStringList alternativeUnits; QStringList alternativeUnits;
foreach(BitcoinUnits::Unit u, BitcoinUnits::availableUnits()) foreach(BitcoinUnits::Unit u, BitcoinUnits::availableUnits())
{ {
@ -384,8 +384,8 @@ bool SendCoinsDialog::handlePaymentRequest(const SendCoinsRecipient &rv)
return true; return true;
} }
void SendCoinsDialog::setBalance(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance, void SendCoinsDialog::setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
qint64 watchBalance, qint64 watchUnconfirmedBalance, qint64 watchImmatureBalance) const CAmount& watchBalance, const CAmount& watchUnconfirmedBalance, const CAmount& watchImmatureBalance)
{ {
Q_UNUSED(unconfirmedBalance); Q_UNUSED(unconfirmedBalance);
Q_UNUSED(immatureBalance); Q_UNUSED(immatureBalance);

4
src/qt/sendcoinsdialog.h

@ -47,8 +47,8 @@ public slots:
void accept(); void accept();
SendCoinsEntry *addEntry(); SendCoinsEntry *addEntry();
void updateTabsAndLabels(); void updateTabsAndLabels();
void setBalance(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance, void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
qint64 watchOnlyBalance, qint64 watchUnconfBalance, qint64 watchImmatureBalance); const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance);
private: private:
Ui::SendCoinsDialog *ui; Ui::SendCoinsDialog *ui;

14
src/qt/transactiondesc.cpp

@ -56,9 +56,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
strHTML += "<html><font face='verdana, arial, helvetica, sans-serif'>"; strHTML += "<html><font face='verdana, arial, helvetica, sans-serif'>";
int64_t nTime = wtx.GetTxTime(); int64_t nTime = wtx.GetTxTime();
int64_t nCredit = wtx.GetCredit(ISMINE_ALL); CAmount nCredit = wtx.GetCredit(ISMINE_ALL);
int64_t nDebit = wtx.GetDebit(ISMINE_ALL); CAmount nDebit = wtx.GetDebit(ISMINE_ALL);
int64_t nNet = nCredit - nDebit; CAmount nNet = nCredit - nDebit;
strHTML += "<b>" + tr("Status") + ":</b> " + FormatTxStatus(wtx); strHTML += "<b>" + tr("Status") + ":</b> " + FormatTxStatus(wtx);
int nRequests = wtx.GetRequestCount(); int nRequests = wtx.GetRequestCount();
@ -132,7 +132,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
// //
// Coinbase // Coinbase
// //
int64_t nUnmatured = 0; CAmount nUnmatured = 0;
BOOST_FOREACH(const CTxOut& txout, wtx.vout) BOOST_FOREACH(const CTxOut& txout, wtx.vout)
nUnmatured += wallet->GetCredit(txout, ISMINE_ALL); nUnmatured += wallet->GetCredit(txout, ISMINE_ALL);
strHTML += "<b>" + tr("Credit") + ":</b> "; strHTML += "<b>" + tr("Credit") + ":</b> ";
@ -206,13 +206,13 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
if (fAllToMe) if (fAllToMe)
{ {
// Payment to self // Payment to self
int64_t nChange = wtx.GetChange(); CAmount nChange = wtx.GetChange();
int64_t nValue = nCredit - nChange; CAmount nValue = nCredit - nChange;
strHTML += "<b>" + tr("Total debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -nValue) + "<br>"; strHTML += "<b>" + tr("Total debit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -nValue) + "<br>";
strHTML += "<b>" + tr("Total credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, nValue) + "<br>"; strHTML += "<b>" + tr("Total credit") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, nValue) + "<br>";
} }
int64_t nTxFee = nDebit - wtx.GetValueOut(); CAmount nTxFee = nDebit - wtx.GetValueOut();
if (nTxFee > 0) if (nTxFee > 0)
strHTML += "<b>" + tr("Transaction fee") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -nTxFee) + "<br>"; strHTML += "<b>" + tr("Transaction fee") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -nTxFee) + "<br>";
} }

2
src/qt/transactionfilterproxy.cpp

@ -78,7 +78,7 @@ void TransactionFilterProxy::setTypeFilter(quint32 modes)
invalidateFilter(); invalidateFilter();
} }
void TransactionFilterProxy::setMinAmount(qint64 minimum) void TransactionFilterProxy::setMinAmount(const CAmount& minimum)
{ {
this->minAmount = minimum; this->minAmount = minimum;
invalidateFilter(); invalidateFilter();

6
src/qt/transactionfilterproxy.h

@ -5,6 +5,8 @@
#ifndef TRANSACTIONFILTERPROXY_H #ifndef TRANSACTIONFILTERPROXY_H
#define TRANSACTIONFILTERPROXY_H #define TRANSACTIONFILTERPROXY_H
#include "amount.h"
#include <QDateTime> #include <QDateTime>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
@ -38,7 +40,7 @@ public:
@note Type filter takes a bit field created with TYPE() or ALL_TYPES @note Type filter takes a bit field created with TYPE() or ALL_TYPES
*/ */
void setTypeFilter(quint32 modes); void setTypeFilter(quint32 modes);
void setMinAmount(qint64 minimum); void setMinAmount(const CAmount& minimum);
void setWatchOnlyFilter(WatchOnlyFilter filter); void setWatchOnlyFilter(WatchOnlyFilter filter);
/** Set maximum number of rows returned, -1 if unlimited. */ /** Set maximum number of rows returned, -1 if unlimited. */
@ -58,7 +60,7 @@ private:
QString addrPrefix; QString addrPrefix;
quint32 typeFilter; quint32 typeFilter;
WatchOnlyFilter watchOnlyFilter; WatchOnlyFilter watchOnlyFilter;
qint64 minAmount; CAmount minAmount;
int limitRows; int limitRows;
bool showInactive; bool showInactive;
}; };

12
src/qt/transactionrecord.cpp

@ -32,9 +32,9 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
{ {
QList<TransactionRecord> parts; QList<TransactionRecord> parts;
int64_t nTime = wtx.GetTxTime(); int64_t nTime = wtx.GetTxTime();
int64_t nCredit = wtx.GetCredit(true); CAmount nCredit = wtx.GetCredit(true);
int64_t nDebit = wtx.GetDebit(ISMINE_ALL); CAmount nDebit = wtx.GetDebit(ISMINE_ALL);
int64_t nNet = nCredit - nDebit; CAmount nNet = nCredit - nDebit;
uint256 hash = wtx.GetHash(); uint256 hash = wtx.GetHash();
std::map<std::string, std::string> mapValue = wtx.mapValue; std::map<std::string, std::string> mapValue = wtx.mapValue;
@ -97,7 +97,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
if (fAllFromMe && fAllToMe) if (fAllFromMe && fAllToMe)
{ {
// Payment to self // Payment to self
int64_t nChange = wtx.GetChange(); CAmount nChange = wtx.GetChange();
parts.append(TransactionRecord(hash, nTime, TransactionRecord::SendToSelf, "", parts.append(TransactionRecord(hash, nTime, TransactionRecord::SendToSelf, "",
-(nDebit - nChange), nCredit - nChange)); -(nDebit - nChange), nCredit - nChange));
@ -108,7 +108,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
// //
// Debit // Debit
// //
int64_t nTxFee = nDebit - wtx.GetValueOut(); CAmount nTxFee = nDebit - wtx.GetValueOut();
for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++) for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++)
{ {
@ -138,7 +138,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
sub.address = mapValue["to"]; sub.address = mapValue["to"];
} }
int64_t nValue = txout.nValue; CAmount nValue = txout.nValue;
/* Add fee to first output */ /* Add fee to first output */
if (nTxFee > 0) if (nTxFee > 0)
{ {

7
src/qt/transactionrecord.h

@ -5,6 +5,7 @@
#ifndef TRANSACTIONRECORD_H #ifndef TRANSACTIONRECORD_H
#define TRANSACTIONRECORD_H #define TRANSACTIONRECORD_H
#include "amount.h"
#include "uint256.h" #include "uint256.h"
#include <QList> #include <QList>
@ -94,7 +95,7 @@ public:
TransactionRecord(uint256 hash, qint64 time, TransactionRecord(uint256 hash, qint64 time,
Type type, const std::string &address, Type type, const std::string &address,
qint64 debit, qint64 credit): const CAmount& debit, const CAmount& credit):
hash(hash), time(time), type(type), address(address), debit(debit), credit(credit), hash(hash), time(time), type(type), address(address), debit(debit), credit(credit),
idx(0) idx(0)
{ {
@ -111,8 +112,8 @@ public:
qint64 time; qint64 time;
Type type; Type type;
std::string address; std::string address;
qint64 debit; CAmount debit;
qint64 credit; CAmount credit;
/**@}*/ /**@}*/
/** Subtransaction index, for sort key */ /** Subtransaction index, for sort key */

4
src/qt/transactiontablemodel.cpp

@ -546,7 +546,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
case ToAddress: case ToAddress:
return formatTxToAddress(rec, true); return formatTxToAddress(rec, true);
case Amount: case Amount:
return rec->credit + rec->debit; return qint64(rec->credit + rec->debit);
} }
break; break;
case Qt::ToolTipRole: case Qt::ToolTipRole:
@ -583,7 +583,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
case LabelRole: case LabelRole:
return walletModel->getAddressTableModel()->labelForAddress(QString::fromStdString(rec->address)); return walletModel->getAddressTableModel()->labelForAddress(QString::fromStdString(rec->address));
case AmountRole: case AmountRole:
return rec->credit + rec->debit; return qint64(rec->credit + rec->debit);
case TxIDRole: case TxIDRole:
return rec->getTxID(); return rec->getTxID();
case TxHashRole: case TxHashRole:

2
src/qt/transactionview.cpp

@ -304,7 +304,7 @@ void TransactionView::changedAmount(const QString &amount)
{ {
if(!transactionProxyModel) if(!transactionProxyModel)
return; return;
qint64 amount_parsed = 0; CAmount amount_parsed = 0;
if(BitcoinUnits::parse(model->getOptionsModel()->getDisplayUnit(), amount, &amount_parsed)) if(BitcoinUnits::parse(model->getOptionsModel()->getDisplayUnit(), amount, &amount_parsed))
{ {
transactionProxyModel->setMinAmount(amount_parsed); transactionProxyModel->setMinAmount(amount_parsed);

40
src/qt/walletmodel.cpp

@ -55,11 +55,11 @@ WalletModel::~WalletModel()
unsubscribeFromCoreSignals(); unsubscribeFromCoreSignals();
} }
qint64 WalletModel::getBalance(const CCoinControl *coinControl) const CAmount WalletModel::getBalance(const CCoinControl *coinControl) const
{ {
if (coinControl) if (coinControl)
{ {
qint64 nBalance = 0; CAmount nBalance = 0;
std::vector<COutput> vCoins; std::vector<COutput> vCoins;
wallet->AvailableCoins(vCoins, true, coinControl); wallet->AvailableCoins(vCoins, true, coinControl);
BOOST_FOREACH(const COutput& out, vCoins) BOOST_FOREACH(const COutput& out, vCoins)
@ -72,12 +72,12 @@ qint64 WalletModel::getBalance(const CCoinControl *coinControl) const
return wallet->GetBalance(); return wallet->GetBalance();
} }
qint64 WalletModel::getUnconfirmedBalance() const CAmount WalletModel::getUnconfirmedBalance() const
{ {
return wallet->GetUnconfirmedBalance(); return wallet->GetUnconfirmedBalance();
} }
qint64 WalletModel::getImmatureBalance() const CAmount WalletModel::getImmatureBalance() const
{ {
return wallet->GetImmatureBalance(); return wallet->GetImmatureBalance();
} }
@ -87,17 +87,17 @@ bool WalletModel::haveWatchOnly() const
return fHaveWatchOnly; return fHaveWatchOnly;
} }
qint64 WalletModel::getWatchBalance() const CAmount WalletModel::getWatchBalance() const
{ {
return wallet->GetWatchOnlyBalance(); return wallet->GetWatchOnlyBalance();
} }
qint64 WalletModel::getWatchUnconfirmedBalance() const CAmount WalletModel::getWatchUnconfirmedBalance() const
{ {
return wallet->GetUnconfirmedWatchOnlyBalance(); return wallet->GetUnconfirmedWatchOnlyBalance();
} }
qint64 WalletModel::getWatchImmatureBalance() const CAmount WalletModel::getWatchImmatureBalance() const
{ {
return wallet->GetImmatureWatchOnlyBalance(); return wallet->GetImmatureWatchOnlyBalance();
} }
@ -137,12 +137,12 @@ void WalletModel::pollBalanceChanged()
void WalletModel::checkBalanceChanged() void WalletModel::checkBalanceChanged()
{ {
qint64 newBalance = getBalance(); CAmount newBalance = getBalance();
qint64 newUnconfirmedBalance = getUnconfirmedBalance(); CAmount newUnconfirmedBalance = getUnconfirmedBalance();
qint64 newImmatureBalance = getImmatureBalance(); CAmount newImmatureBalance = getImmatureBalance();
qint64 newWatchOnlyBalance = 0; CAmount newWatchOnlyBalance = 0;
qint64 newWatchUnconfBalance = 0; CAmount newWatchUnconfBalance = 0;
qint64 newWatchImmatureBalance = 0; CAmount newWatchImmatureBalance = 0;
if (haveWatchOnly()) if (haveWatchOnly())
{ {
newWatchOnlyBalance = getWatchBalance(); newWatchOnlyBalance = getWatchBalance();
@ -194,9 +194,9 @@ bool WalletModel::validateAddress(const QString &address)
WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransaction &transaction, const CCoinControl *coinControl) WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransaction &transaction, const CCoinControl *coinControl)
{ {
qint64 total = 0; CAmount total = 0;
QList<SendCoinsRecipient> recipients = transaction.getRecipients(); QList<SendCoinsRecipient> recipients = transaction.getRecipients();
std::vector<std::pair<CScript, int64_t> > vecSend; std::vector<std::pair<CScript, CAmount> > vecSend;
if(recipients.empty()) if(recipients.empty())
{ {
@ -211,7 +211,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
{ {
if (rcp.paymentRequest.IsInitialized()) if (rcp.paymentRequest.IsInitialized())
{ // PaymentRequest... { // PaymentRequest...
int64_t subtotal = 0; CAmount subtotal = 0;
const payments::PaymentDetails& details = rcp.paymentRequest.getDetails(); const payments::PaymentDetails& details = rcp.paymentRequest.getDetails();
for (int i = 0; i < details.outputs_size(); i++) for (int i = 0; i < details.outputs_size(); i++)
{ {
@ -220,7 +220,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
subtotal += out.amount(); subtotal += out.amount();
const unsigned char* scriptStr = (const unsigned char*)out.script().data(); const unsigned char* scriptStr = (const unsigned char*)out.script().data();
CScript scriptPubKey(scriptStr, scriptStr+out.script().size()); CScript scriptPubKey(scriptStr, scriptStr+out.script().size());
vecSend.push_back(std::pair<CScript, int64_t>(scriptPubKey, out.amount())); vecSend.push_back(std::pair<CScript, CAmount>(scriptPubKey, out.amount()));
} }
if (subtotal <= 0) if (subtotal <= 0)
{ {
@ -242,7 +242,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
++nAddresses; ++nAddresses;
CScript scriptPubKey = GetScriptForDestination(CBitcoinAddress(rcp.address.toStdString()).Get()); CScript scriptPubKey = GetScriptForDestination(CBitcoinAddress(rcp.address.toStdString()).Get());
vecSend.push_back(std::pair<CScript, int64_t>(scriptPubKey, rcp.amount)); vecSend.push_back(std::pair<CScript, CAmount>(scriptPubKey, rcp.amount));
total += rcp.amount; total += rcp.amount;
} }
@ -252,7 +252,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
return DuplicateAddress; return DuplicateAddress;
} }
qint64 nBalance = getBalance(coinControl); CAmount nBalance = getBalance(coinControl);
if(total > nBalance) if(total > nBalance)
{ {
@ -263,7 +263,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
LOCK2(cs_main, wallet->cs_wallet); LOCK2(cs_main, wallet->cs_wallet);
transaction.newPossibleKeyChange(wallet); transaction.newPossibleKeyChange(wallet);
int64_t nFeeRequired = 0; CAmount nFeeRequired = 0;
std::string strFailReason; std::string strFailReason;
CWalletTx *newTx = transaction.getTransaction(); CWalletTx *newTx = transaction.getTransaction();

32
src/qt/walletmodel.h

@ -37,7 +37,7 @@ class SendCoinsRecipient
{ {
public: public:
explicit SendCoinsRecipient() : amount(0), nVersion(SendCoinsRecipient::CURRENT_VERSION) { } explicit SendCoinsRecipient() : amount(0), nVersion(SendCoinsRecipient::CURRENT_VERSION) { }
explicit SendCoinsRecipient(const QString &addr, const QString &label, quint64 amount, const QString &message): explicit SendCoinsRecipient(const QString &addr, const QString &label, const CAmount& amount, const QString &message):
address(addr), label(label), amount(amount), message(message), nVersion(SendCoinsRecipient::CURRENT_VERSION) {} address(addr), label(label), amount(amount), message(message), nVersion(SendCoinsRecipient::CURRENT_VERSION) {}
// If from an insecure payment request, this is used for storing // If from an insecure payment request, this is used for storing
@ -47,7 +47,7 @@ public:
// Todo: This is a hack, should be replaced with a cleaner solution! // Todo: This is a hack, should be replaced with a cleaner solution!
QString address; QString address;
QString label; QString label;
qint64 amount; CAmount amount;
// If from a payment request, this is used for storing the memo // If from a payment request, this is used for storing the memo
QString message; QString message;
@ -125,13 +125,13 @@ public:
TransactionTableModel *getTransactionTableModel(); TransactionTableModel *getTransactionTableModel();
RecentRequestsTableModel *getRecentRequestsTableModel(); RecentRequestsTableModel *getRecentRequestsTableModel();
qint64 getBalance(const CCoinControl *coinControl = NULL) const; CAmount getBalance(const CCoinControl *coinControl = NULL) const;
qint64 getUnconfirmedBalance() const; CAmount getUnconfirmedBalance() const;
qint64 getImmatureBalance() const; CAmount getImmatureBalance() const;
bool haveWatchOnly() const; bool haveWatchOnly() const;
qint64 getWatchBalance() const; CAmount getWatchBalance() const;
qint64 getWatchUnconfirmedBalance() const; CAmount getWatchUnconfirmedBalance() const;
qint64 getWatchImmatureBalance() const; CAmount getWatchImmatureBalance() const;
EncryptionStatus getEncryptionStatus() const; EncryptionStatus getEncryptionStatus() const;
bool processingQueuedTransactions() { return fProcessingQueuedTransactions; } bool processingQueuedTransactions() { return fProcessingQueuedTransactions; }
@ -210,12 +210,12 @@ private:
RecentRequestsTableModel *recentRequestsTableModel; RecentRequestsTableModel *recentRequestsTableModel;
// Cache some values to be able to detect changes // Cache some values to be able to detect changes
qint64 cachedBalance; CAmount cachedBalance;
qint64 cachedUnconfirmedBalance; CAmount cachedUnconfirmedBalance;
qint64 cachedImmatureBalance; CAmount cachedImmatureBalance;
qint64 cachedWatchOnlyBalance; CAmount cachedWatchOnlyBalance;
qint64 cachedWatchUnconfBalance; CAmount cachedWatchUnconfBalance;
qint64 cachedWatchImmatureBalance; CAmount cachedWatchImmatureBalance;
EncryptionStatus cachedEncryptionStatus; EncryptionStatus cachedEncryptionStatus;
int cachedNumBlocks; int cachedNumBlocks;
@ -227,8 +227,8 @@ private:
signals: signals:
// Signal that balance in wallet changed // Signal that balance in wallet changed
void balanceChanged(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance, void balanceChanged(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
qint64 watchOnlyBalance, qint64 watchUnconfBalance, qint64 watchImmatureBalance); const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance);
// Encryption status of wallet changed // Encryption status of wallet changed
void encryptionStatusChanged(int status); void encryptionStatusChanged(int status);

8
src/qt/walletmodeltransaction.cpp

@ -31,19 +31,19 @@ CWalletTx *WalletModelTransaction::getTransaction()
return walletTransaction; return walletTransaction;
} }
qint64 WalletModelTransaction::getTransactionFee() CAmount WalletModelTransaction::getTransactionFee()
{ {
return fee; return fee;
} }
void WalletModelTransaction::setTransactionFee(qint64 newFee) void WalletModelTransaction::setTransactionFee(const CAmount& newFee)
{ {
fee = newFee; fee = newFee;
} }
qint64 WalletModelTransaction::getTotalTransactionAmount() CAmount WalletModelTransaction::getTotalTransactionAmount()
{ {
qint64 totalTransactionAmount = 0; CAmount totalTransactionAmount = 0;
foreach(const SendCoinsRecipient &rcp, recipients) foreach(const SendCoinsRecipient &rcp, recipients)
{ {
totalTransactionAmount += rcp.amount; totalTransactionAmount += rcp.amount;

8
src/qt/walletmodeltransaction.h

@ -26,10 +26,10 @@ public:
CWalletTx *getTransaction(); CWalletTx *getTransaction();
void setTransactionFee(qint64 newFee); void setTransactionFee(const CAmount& newFee);
qint64 getTransactionFee(); CAmount getTransactionFee();
qint64 getTotalTransactionAmount(); CAmount getTotalTransactionAmount();
void newPossibleKeyChange(CWallet *wallet); void newPossibleKeyChange(CWallet *wallet);
CReserveKey *getPossibleKeyChange(); CReserveKey *getPossibleKeyChange();
@ -38,7 +38,7 @@ private:
const QList<SendCoinsRecipient> recipients; const QList<SendCoinsRecipient> recipients;
CWalletTx *walletTransaction; CWalletTx *walletTransaction;
CReserveKey *keyChange; CReserveKey *keyChange;
qint64 fee; CAmount fee;
}; };
#endif // WALLETMODELTRANSACTION_H #endif // WALLETMODELTRANSACTION_H

2
src/qt/walletview.cpp

@ -92,7 +92,7 @@ void WalletView::setBitcoinGUI(BitcoinGUI *gui)
connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int))); connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));
// Pass through transaction notifications // Pass through transaction notifications
connect(this, SIGNAL(incomingTransaction(QString,int,qint64,QString,QString)), gui, SLOT(incomingTransaction(QString,int,qint64,QString,QString))); connect(this, SIGNAL(incomingTransaction(QString,int,const CAmount&,QString,QString)), gui, SLOT(incomingTransaction(QString,int,const CAmount&,QString,QString)));
} }
} }

4
src/qt/walletview.h

@ -5,6 +5,8 @@
#ifndef WALLETVIEW_H #ifndef WALLETVIEW_H
#define WALLETVIEW_H #define WALLETVIEW_H
#include "amount.h"
#include <QStackedWidget> #include <QStackedWidget>
class BitcoinGUI; class BitcoinGUI;
@ -111,7 +113,7 @@ signals:
/** Encryption status of wallet changed */ /** Encryption status of wallet changed */
void encryptionStatusChanged(int status); void encryptionStatusChanged(int status);
/** Notify that a new transaction appeared */ /** Notify that a new transaction appeared */
void incomingTransaction(const QString& date, int unit, qint64 amount, const QString& type, const QString& address); void incomingTransaction(const QString& date, int unit, const CAmount& amount, const QString& type, const QString& address);
}; };
#endif // WALLETVIEW_H #endif // WALLETVIEW_H

2
src/rpcmining.cpp

@ -273,7 +273,7 @@ Value prioritisetransaction(const Array& params, bool fHelp)
uint256 hash; uint256 hash;
hash.SetHex(params[0].get_str()); hash.SetHex(params[0].get_str());
int64_t nAmount = 0; CAmount nAmount = 0;
if (params[2].get_real() != 0.0) if (params[2].get_real() != 0.0)
nAmount = AmountFromValue(params[2]); nAmount = AmountFromValue(params[2]);

4
src/rpcrawtransaction.cpp

@ -269,7 +269,7 @@ Value listunspent(const Array& params, bool fHelp)
continue; continue;
} }
int64_t nValue = out.tx->vout[out.i].nValue; CAmount nValue = out.tx->vout[out.i].nValue;
const CScript& pk = out.tx->vout[out.i].scriptPubKey; const CScript& pk = out.tx->vout[out.i].scriptPubKey;
Object entry; Object entry;
entry.push_back(Pair("txid", out.tx->GetHash().GetHex())); entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
@ -367,7 +367,7 @@ Value createrawtransaction(const Array& params, bool fHelp)
setAddress.insert(address); setAddress.insert(address);
CScript scriptPubKey = GetScriptForDestination(address.Get()); CScript scriptPubKey = GetScriptForDestination(address.Get());
int64_t nAmount = AmountFromValue(s.value_); CAmount nAmount = AmountFromValue(s.value_);
CTxOut out(nAmount, scriptPubKey); CTxOut out(nAmount, scriptPubKey);
rawTx.vout.push_back(out); rawTx.vout.push_back(out);

6
src/rpcserver.cpp

@ -88,18 +88,18 @@ static inline int64_t roundint64(double d)
return (int64_t)(d > 0 ? d + 0.5 : d - 0.5); return (int64_t)(d > 0 ? d + 0.5 : d - 0.5);
} }
int64_t AmountFromValue(const Value& value) CAmount AmountFromValue(const Value& value)
{ {
double dAmount = value.get_real(); double dAmount = value.get_real();
if (dAmount <= 0.0 || dAmount > 21000000.0) if (dAmount <= 0.0 || dAmount > 21000000.0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount"); throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
int64_t nAmount = roundint64(dAmount * COIN); CAmount nAmount = roundint64(dAmount * COIN);
if (!MoneyRange(nAmount)) if (!MoneyRange(nAmount))
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount"); throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
return nAmount; return nAmount;
} }
Value ValueFromAmount(int64_t amount) Value ValueFromAmount(const CAmount& amount)
{ {
return (double)amount / (double)COIN; return (double)amount / (double)COIN;
} }

5
src/rpcserver.h

@ -6,6 +6,7 @@
#ifndef _BITCOINRPC_SERVER_H_ #ifndef _BITCOINRPC_SERVER_H_
#define _BITCOINRPC_SERVER_H_ #define _BITCOINRPC_SERVER_H_
#include "amount.h"
#include "uint256.h" #include "uint256.h"
#include "rpcprotocol.h" #include "rpcprotocol.h"
@ -116,8 +117,8 @@ extern void InitRPCMining();
extern void ShutdownRPCMining(); extern void ShutdownRPCMining();
extern int64_t nWalletUnlockTime; extern int64_t nWalletUnlockTime;
extern int64_t AmountFromValue(const json_spirit::Value& value); extern CAmount AmountFromValue(const json_spirit::Value& value);
extern json_spirit::Value ValueFromAmount(int64_t amount); extern json_spirit::Value ValueFromAmount(const CAmount& amount);
extern double GetDifficulty(const CBlockIndex* blockindex = NULL); extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
extern std::string HelpRequiringPassphrase(); extern std::string HelpRequiringPassphrase();
extern std::string HelpExampleCli(std::string methodname, std::string args); extern std::string HelpExampleCli(std::string methodname, std::string args);

62
src/rpcwallet.cpp

@ -331,7 +331,7 @@ Value sendtoaddress(const Array& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
// Amount // Amount
int64_t nAmount = AmountFromValue(params[1]); CAmount nAmount = AmountFromValue(params[1]);
// Wallet comments // Wallet comments
CWalletTx wtx; CWalletTx wtx;
@ -375,7 +375,7 @@ Value listaddressgroupings(const Array& params, bool fHelp)
); );
Array jsonGroupings; Array jsonGroupings;
map<CTxDestination, int64_t> balances = pwalletMain->GetAddressBalances(); map<CTxDestination, CAmount> balances = pwalletMain->GetAddressBalances();
BOOST_FOREACH(set<CTxDestination> grouping, pwalletMain->GetAddressGroupings()) BOOST_FOREACH(set<CTxDestination> grouping, pwalletMain->GetAddressGroupings())
{ {
Array jsonGrouping; Array jsonGrouping;
@ -483,7 +483,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
nMinDepth = params[1].get_int(); nMinDepth = params[1].get_int();
// Tally // Tally
int64_t nAmount = 0; CAmount nAmount = 0;
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{ {
const CWalletTx& wtx = (*it).second; const CWalletTx& wtx = (*it).second;
@ -532,7 +532,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
set<CTxDestination> setAddress = pwalletMain->GetAccountAddresses(strAccount); set<CTxDestination> setAddress = pwalletMain->GetAccountAddresses(strAccount);
// Tally // Tally
int64_t nAmount = 0; CAmount nAmount = 0;
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{ {
const CWalletTx& wtx = (*it).second; 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 // Tally wallet transactions
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) 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) if (!IsFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
continue; continue;
int64_t nReceived, nSent, nFee; CAmount nReceived, nSent, nFee;
wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter); wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter);
if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth) if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
@ -577,7 +577,7 @@ int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi
return nBalance; 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); CWalletDB walletdb(pwalletMain->strWalletFile);
return GetAccountBalance(walletdb, strAccount, nMinDepth, filter); 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() // Calculate total balance a different way from GetBalance()
// (GetBalance() sums up all unspent TxOuts) // (GetBalance() sums up all unspent TxOuts)
// getbalance and getbalance '*' 0 should return the same number // 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) for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{ {
const CWalletTx& wtx = (*it).second; const CWalletTx& wtx = (*it).second;
if (!wtx.IsTrusted() || wtx.GetBlocksToMaturity() > 0) if (!wtx.IsTrusted() || wtx.GetBlocksToMaturity() > 0)
continue; continue;
int64_t allFee; CAmount allFee;
string strSentAccount; string strSentAccount;
list<COutputEntry> listReceived; list<COutputEntry> listReceived;
list<COutputEntry> listSent; list<COutputEntry> listSent;
@ -653,7 +653,7 @@ Value getbalance(const Array& params, bool fHelp)
string strAccount = AccountFromValue(params[0]); string strAccount = AccountFromValue(params[0]);
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, filter); CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, filter);
return ValueFromAmount(nBalance); return ValueFromAmount(nBalance);
} }
@ -692,7 +692,7 @@ Value movecmd(const Array& params, bool fHelp)
string strFrom = AccountFromValue(params[0]); string strFrom = AccountFromValue(params[0]);
string strTo = AccountFromValue(params[1]); string strTo = AccountFromValue(params[1]);
int64_t nAmount = AmountFromValue(params[2]); CAmount nAmount = AmountFromValue(params[2]);
if (params.size() > 3) if (params.size() > 3)
// unused parameter, used to be nMinDepth, keep type-checking it though // unused parameter, used to be nMinDepth, keep type-checking it though
(void)params[3].get_int(); (void)params[3].get_int();
@ -766,7 +766,7 @@ Value sendfrom(const Array& params, bool fHelp)
CBitcoinAddress address(params[1].get_str()); CBitcoinAddress address(params[1].get_str());
if (!address.IsValid()) if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
int64_t nAmount = AmountFromValue(params[2]); CAmount nAmount = AmountFromValue(params[2]);
int nMinDepth = 1; int nMinDepth = 1;
if (params.size() > 3) if (params.size() > 3)
nMinDepth = params[3].get_int(); nMinDepth = params[3].get_int();
@ -781,7 +781,7 @@ Value sendfrom(const Array& params, bool fHelp)
EnsureWalletIsUnlocked(); EnsureWalletIsUnlocked();
// Check funds // Check funds
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
if (nAmount > nBalance) if (nAmount > nBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); 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(); wtx.mapValue["comment"] = params[3].get_str();
set<CBitcoinAddress> setAddress; 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) BOOST_FOREACH(const Pair& s, sendTo)
{ {
CBitcoinAddress address(s.name_); CBitcoinAddress address(s.name_);
@ -848,7 +848,7 @@ Value sendmany(const Array& params, bool fHelp)
setAddress.insert(address); setAddress.insert(address);
CScript scriptPubKey = GetScriptForDestination(address.Get()); CScript scriptPubKey = GetScriptForDestination(address.Get());
int64_t nAmount = AmountFromValue(s.value_); CAmount nAmount = AmountFromValue(s.value_);
totalAmount += nAmount; totalAmount += nAmount;
vecSend.push_back(make_pair(scriptPubKey, nAmount)); vecSend.push_back(make_pair(scriptPubKey, nAmount));
@ -857,13 +857,13 @@ Value sendmany(const Array& params, bool fHelp)
EnsureWalletIsUnlocked(); EnsureWalletIsUnlocked();
// Check funds // Check funds
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE); CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
if (totalAmount > nBalance) if (totalAmount > nBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds"); throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");
// Send // Send
CReserveKey keyChange(pwalletMain); CReserveKey keyChange(pwalletMain);
int64_t nFeeRequired = 0; CAmount nFeeRequired = 0;
string strFailReason; string strFailReason;
bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason); bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason);
if (!fCreated) if (!fCreated)
@ -923,7 +923,7 @@ Value addmultisigaddress(const Array& params, bool fHelp)
struct tallyitem struct tallyitem
{ {
int64_t nAmount; CAmount nAmount;
int nConf; int nConf;
vector<uint256> txids; vector<uint256> txids;
bool fIsWatchonly; bool fIsWatchonly;
@ -995,7 +995,7 @@ Value ListReceived(const Array& params, bool fByAccounts)
if (it == mapTally.end() && !fIncludeEmpty) if (it == mapTally.end() && !fIncludeEmpty)
continue; continue;
int64_t nAmount = 0; CAmount nAmount = 0;
int nConf = std::numeric_limits<int>::max(); int nConf = std::numeric_limits<int>::max();
bool fIsWatchonly = false; bool fIsWatchonly = false;
if (it != mapTally.end()) 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) 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; int nConf = (*it).second.nConf;
Object obj; Object obj;
if((*it).second.fIsWatchonly) 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) void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret, const isminefilter& filter)
{ {
int64_t nFee; CAmount nFee;
string strSentAccount; string strSentAccount;
list<COutputEntry> listReceived; list<COutputEntry> listReceived;
list<COutputEntry> listSent; list<COutputEntry> listSent;
@ -1355,7 +1355,7 @@ Value listaccounts(const Array& params, bool fHelp)
if(params[1].get_bool()) if(params[1].get_bool())
includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY; includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY;
map<string, int64_t> mapAccountBalances; map<string, CAmount> mapAccountBalances;
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) { BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) {
if (IsMine(*pwalletMain, entry.first) & includeWatchonly) // This address belongs to me if (IsMine(*pwalletMain, entry.first) & includeWatchonly) // This address belongs to me
mapAccountBalances[entry.second.name] = 0; 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) for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{ {
const CWalletTx& wtx = (*it).second; const CWalletTx& wtx = (*it).second;
int64_t nFee; CAmount nFee;
string strSentAccount; string strSentAccount;
list<COutputEntry> listReceived; list<COutputEntry> listReceived;
list<COutputEntry> listSent; list<COutputEntry> listSent;
@ -1391,7 +1391,7 @@ Value listaccounts(const Array& params, bool fHelp)
mapAccountBalances[entry.strAccount] += entry.nCreditDebit; mapAccountBalances[entry.strAccount] += entry.nCreditDebit;
Object ret; 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))); ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second)));
} }
return ret; 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"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
const CWalletTx& wtx = pwalletMain->mapWallet[hash]; const CWalletTx& wtx = pwalletMain->mapWallet[hash];
int64_t nCredit = wtx.GetCredit(filter != 0); CAmount nCredit = wtx.GetCredit(filter != 0);
int64_t nDebit = wtx.GetDebit(filter); CAmount nDebit = wtx.GetDebit(filter);
int64_t nNet = nCredit - nDebit; CAmount nNet = nCredit - nDebit;
int64_t nFee = (wtx.IsFromMe(filter) ? wtx.GetValueOut() - nDebit : 0); CAmount nFee = (wtx.IsFromMe(filter) ? wtx.GetValueOut() - nDebit : 0);
entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee))); entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
if (wtx.IsFromMe(filter)) if (wtx.IsFromMe(filter))
@ -1937,7 +1937,7 @@ Value settxfee(const Array& params, bool fHelp)
); );
// Amount // Amount
int64_t nAmount = 0; CAmount nAmount = 0;
if (params[0].get_real() != 0.0) if (params[0].get_real() != 0.0)
nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts

4
src/test/accounting_tests.cpp

@ -15,7 +15,7 @@ extern CWallet* pwalletMain;
BOOST_AUTO_TEST_SUITE(accounting_tests) BOOST_AUTO_TEST_SUITE(accounting_tests)
static void static void
GetResults(CWalletDB& walletdb, std::map<int64_t, CAccountingEntry>& results) GetResults(CWalletDB& walletdb, std::map<CAmount, CAccountingEntry>& results)
{ {
std::list<CAccountingEntry> aes; std::list<CAccountingEntry> aes;
@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
std::vector<CWalletTx*> vpwtx; std::vector<CWalletTx*> vpwtx;
CWalletTx wtx; CWalletTx wtx;
CAccountingEntry ae; CAccountingEntry ae;
std::map<int64_t, CAccountingEntry> results; std::map<CAmount, CAccountingEntry> results;
LOCK(pwalletMain->cs_wallet); LOCK(pwalletMain->cs_wallet);

4
src/test/main_tests.cpp

@ -11,9 +11,9 @@ BOOST_AUTO_TEST_SUITE(main_tests)
BOOST_AUTO_TEST_CASE(subsidy_limit_test) BOOST_AUTO_TEST_CASE(subsidy_limit_test)
{ {
uint64_t nSum = 0; CAmount nSum = 0;
for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) { for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) {
uint64_t nSubsidy = GetBlockValue(nHeight, 0); CAmount nSubsidy = GetBlockValue(nHeight, 0);
BOOST_CHECK(nSubsidy <= 50 * COIN); BOOST_CHECK(nSubsidy <= 50 * COIN);
nSum += nSubsidy * 1000; nSum += nSubsidy * 1000;
BOOST_CHECK(MoneyRange(nSum)); BOOST_CHECK(MoneyRange(nSum));

2
src/test/util_tests.cpp

@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE(util_FormatMoney)
BOOST_AUTO_TEST_CASE(util_ParseMoney) BOOST_AUTO_TEST_CASE(util_ParseMoney)
{ {
int64_t ret = 0; CAmount ret = 0;
BOOST_CHECK(ParseMoney("0.0", ret)); BOOST_CHECK(ParseMoney("0.0", ret));
BOOST_CHECK_EQUAL(ret, 0); BOOST_CHECK_EQUAL(ret, 0);

4
src/test/wallet_tests.cpp

@ -28,7 +28,7 @@ BOOST_AUTO_TEST_SUITE(wallet_tests)
static CWallet wallet; static CWallet wallet;
static vector<COutput> vCoins; static vector<COutput> vCoins;
static void add_coin(int64_t nValue, int nAge = 6*24, bool fIsFromMe = false, int nInput=0) static void add_coin(const CAmount& nValue, int nAge = 6*24, bool fIsFromMe = false, int nInput=0)
{ {
static int nextLockTime = 0; static int nextLockTime = 0;
CMutableTransaction tx; CMutableTransaction tx;
@ -66,7 +66,7 @@ static bool equal_sets(CoinSet a, CoinSet b)
BOOST_AUTO_TEST_CASE(coin_selection_tests) BOOST_AUTO_TEST_CASE(coin_selection_tests)
{ {
CoinSet setCoinsRet, setCoinsRet2; CoinSet setCoinsRet, setCoinsRet2;
int64_t nValueRet; CAmount nValueRet;
LOCK(wallet.cs_wallet); LOCK(wallet.cs_wallet);

2
src/txdb.cpp

@ -117,7 +117,7 @@ bool CCoinsViewDB::GetStats(CCoinsStats &stats) const {
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
stats.hashBlock = GetBestBlock(); stats.hashBlock = GetBestBlock();
ss << stats.hashBlock; ss << stats.hashBlock;
int64_t nTotalAmount = 0; CAmount nTotalAmount = 0;
while (pcursor->Valid()) { while (pcursor->Valid()) {
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
try { try {

17
src/txmempool.cpp

@ -7,6 +7,7 @@
#include "core.h" #include "core.h"
#include "util.h" #include "util.h"
#include "utilmoneystr.h"
#include <boost/circular_buffer.hpp> #include <boost/circular_buffer.hpp>
@ -18,7 +19,7 @@ CTxMemPoolEntry::CTxMemPoolEntry():
nHeight = MEMPOOL_HEIGHT; nHeight = MEMPOOL_HEIGHT;
} }
CTxMemPoolEntry::CTxMemPoolEntry(const CTransaction& _tx, int64_t _nFee, CTxMemPoolEntry::CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
int64_t _nTime, double _dPriority, int64_t _nTime, double _dPriority,
unsigned int _nHeight): unsigned int _nHeight):
tx(_tx), nFee(_nFee), nTime(_nTime), dPriority(_dPriority), nHeight(_nHeight) tx(_tx), nFee(_nFee), nTime(_nTime), dPriority(_dPriority), nHeight(_nHeight)
@ -36,7 +37,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTxMemPoolEntry& other)
double double
CTxMemPoolEntry::GetPriority(unsigned int currentHeight) const CTxMemPoolEntry::GetPriority(unsigned int currentHeight) const
{ {
int64_t nValueIn = tx.GetValueOut()+nFee; CAmount nValueIn = tx.GetValueOut()+nFee;
double deltaPriority = ((double)(currentHeight-nHeight)*nValueIn)/nModSize; double deltaPriority = ((double)(currentHeight-nHeight)*nValueIn)/nModSize;
double dResult = dPriority + deltaPriority; double dResult = dPriority + deltaPriority;
return dResult; return dResult;
@ -601,24 +602,24 @@ CTxMemPool::ReadFeeEstimates(CAutoFile& filein)
return true; return true;
} }
void CTxMemPool::PrioritiseTransaction(const uint256 hash, const string strHash, double dPriorityDelta, int64_t nFeeDelta) void CTxMemPool::PrioritiseTransaction(const uint256 hash, const string strHash, double dPriorityDelta, const CAmount& nFeeDelta)
{ {
{ {
LOCK(cs); LOCK(cs);
std::pair<double, int64_t> &deltas = mapDeltas[hash]; std::pair<double, CAmount> &deltas = mapDeltas[hash];
deltas.first += dPriorityDelta; deltas.first += dPriorityDelta;
deltas.second += nFeeDelta; deltas.second += nFeeDelta;
} }
LogPrintf("PrioritiseTransaction: %s priority += %f, fee += %d\n", strHash, dPriorityDelta, nFeeDelta); LogPrintf("PrioritiseTransaction: %s priority += %f, fee += %d\n", strHash, dPriorityDelta, FormatMoney(nFeeDelta));
} }
void CTxMemPool::ApplyDeltas(const uint256 hash, double &dPriorityDelta, int64_t &nFeeDelta) void CTxMemPool::ApplyDeltas(const uint256 hash, double &dPriorityDelta, CAmount &nFeeDelta)
{ {
LOCK(cs); LOCK(cs);
std::map<uint256, std::pair<double, int64_t> >::iterator pos = mapDeltas.find(hash); std::map<uint256, std::pair<double, CAmount> >::iterator pos = mapDeltas.find(hash);
if (pos == mapDeltas.end()) if (pos == mapDeltas.end())
return; return;
const std::pair<double, int64_t> &deltas = pos->second; const std::pair<double, CAmount> &deltas = pos->second;
dPriorityDelta += deltas.first; dPriorityDelta += deltas.first;
nFeeDelta += deltas.second; nFeeDelta += deltas.second;
} }

12
src/txmempool.h

@ -29,7 +29,7 @@ class CTxMemPoolEntry
{ {
private: private:
CTransaction tx; CTransaction tx;
int64_t nFee; // Cached to avoid expensive parent-transaction lookups CAmount nFee; // Cached to avoid expensive parent-transaction lookups
size_t nTxSize; // ... and avoid recomputing tx size size_t nTxSize; // ... and avoid recomputing tx size
size_t nModSize; // ... and modified size for priority size_t nModSize; // ... and modified size for priority
int64_t nTime; // Local time when entering the mempool int64_t nTime; // Local time when entering the mempool
@ -37,14 +37,14 @@ private:
unsigned int nHeight; // Chain height when entering the mempool unsigned int nHeight; // Chain height when entering the mempool
public: public:
CTxMemPoolEntry(const CTransaction& _tx, int64_t _nFee, CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
int64_t _nTime, double _dPriority, unsigned int _nHeight); int64_t _nTime, double _dPriority, unsigned int _nHeight);
CTxMemPoolEntry(); CTxMemPoolEntry();
CTxMemPoolEntry(const CTxMemPoolEntry& other); CTxMemPoolEntry(const CTxMemPoolEntry& other);
const CTransaction& GetTx() const { return this->tx; } const CTransaction& GetTx() const { return this->tx; }
double GetPriority(unsigned int currentHeight) const; double GetPriority(unsigned int currentHeight) const;
int64_t GetFee() const { return nFee; } CAmount GetFee() const { return nFee; }
size_t GetTxSize() const { return nTxSize; } size_t GetTxSize() const { return nTxSize; }
int64_t GetTime() const { return nTime; } int64_t GetTime() const { return nTime; }
unsigned int GetHeight() const { return nHeight; } unsigned int GetHeight() const { return nHeight; }
@ -76,7 +76,7 @@ public:
mutable CCriticalSection cs; mutable CCriticalSection cs;
std::map<uint256, CTxMemPoolEntry> mapTx; std::map<uint256, CTxMemPoolEntry> mapTx;
std::map<COutPoint, CInPoint> mapNextTx; std::map<COutPoint, CInPoint> mapNextTx;
std::map<uint256, std::pair<double, int64_t> > mapDeltas; std::map<uint256, std::pair<double, CAmount> > mapDeltas;
CTxMemPool(const CFeeRate& _minRelayFee); CTxMemPool(const CFeeRate& _minRelayFee);
~CTxMemPool(); ~CTxMemPool();
@ -102,8 +102,8 @@ public:
void AddTransactionsUpdated(unsigned int n); void AddTransactionsUpdated(unsigned int n);
/** Affect CreateNewBlock prioritisation of transactions */ /** Affect CreateNewBlock prioritisation of transactions */
void PrioritiseTransaction(const uint256 hash, const std::string strHash, double dPriorityDelta, int64_t nFeeDelta); void PrioritiseTransaction(const uint256 hash, const std::string strHash, double dPriorityDelta, const CAmount& nFeeDelta);
void ApplyDeltas(const uint256 hash, double &dPriorityDelta, int64_t &nFeeDelta); void ApplyDeltas(const uint256 hash, double &dPriorityDelta, CAmount &nFeeDelta);
void ClearPrioritisation(const uint256 hash); void ClearPrioritisation(const uint256 hash);
unsigned long size() unsigned long size()

1
src/util.h

@ -14,6 +14,7 @@
#include "config/bitcoin-config.h" #include "config/bitcoin-config.h"
#endif #endif
#include "amount.h"
#include "compat.h" #include "compat.h"
#include "tinyformat.h" #include "tinyformat.h"
#include "utiltime.h" #include "utiltime.h"

8
src/utilmoneystr.cpp

@ -10,7 +10,7 @@
using namespace std; using namespace std;
string FormatMoney(int64_t n, bool fPlus) string FormatMoney(const CAmount& n, bool fPlus)
{ {
// Note: not using straight sprintf here because we do NOT want // Note: not using straight sprintf here because we do NOT want
// localized number formatting. // localized number formatting.
@ -34,12 +34,12 @@ string FormatMoney(int64_t n, bool fPlus)
} }
bool ParseMoney(const string& str, int64_t& nRet) bool ParseMoney(const string& str, CAmount& nRet)
{ {
return ParseMoney(str.c_str(), nRet); return ParseMoney(str.c_str(), nRet);
} }
bool ParseMoney(const char* pszIn, int64_t& nRet) bool ParseMoney(const char* pszIn, CAmount& nRet)
{ {
string strWhole; string strWhole;
int64_t nUnits = 0; int64_t nUnits = 0;
@ -73,7 +73,7 @@ bool ParseMoney(const char* pszIn, int64_t& nRet)
if (nUnits < 0 || nUnits > COIN) if (nUnits < 0 || nUnits > COIN)
return false; return false;
int64_t nWhole = atoi64(strWhole); int64_t nWhole = atoi64(strWhole);
int64_t nValue = nWhole*COIN + nUnits; CAmount nValue = nWhole*COIN + nUnits;
nRet = nValue; nRet = nValue;
return true; return true;

8
src/utilmoneystr.h

@ -12,8 +12,10 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
std::string FormatMoney(int64_t n, bool fPlus=false); #include "amount.h"
bool ParseMoney(const std::string& str, int64_t& nRet);
bool ParseMoney(const char* pszIn, int64_t& nRet); std::string FormatMoney(const CAmount& n, bool fPlus=false);
bool ParseMoney(const std::string& str, CAmount& nRet);
bool ParseMoney(const char* pszIn, CAmount& nRet);
#endif // BITCOIN_UTILMONEYSTR_H #endif // BITCOIN_UTILMONEYSTR_H

108
src/wallet.cpp

@ -35,8 +35,8 @@ CFeeRate CWallet::minTxFee = CFeeRate(10000); // Override with -mintxfee
struct CompareValueOnly struct CompareValueOnly
{ {
bool operator()(const pair<int64_t, pair<const CWalletTx*, unsigned int> >& t1, bool operator()(const pair<CAmount, pair<const CWalletTx*, unsigned int> >& t1,
const pair<int64_t, pair<const CWalletTx*, unsigned int> >& t2) const const pair<CAmount, pair<const CWalletTx*, unsigned int> >& t2) const
{ {
return t1.first < t2.first; return t1.first < t2.first;
} }
@ -697,7 +697,7 @@ isminetype CWallet::IsMine(const CTxIn &txin) const
return ISMINE_NO; return ISMINE_NO;
} }
int64_t CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const CAmount CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const
{ {
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
@ -781,7 +781,7 @@ int CWalletTx::GetRequestCount() const
} }
void CWalletTx::GetAmounts(list<COutputEntry>& listReceived, void CWalletTx::GetAmounts(list<COutputEntry>& listReceived,
list<COutputEntry>& listSent, int64_t& nFee, string& strSentAccount, const isminefilter& filter) const list<COutputEntry>& listSent, CAmount& nFee, string& strSentAccount, const isminefilter& filter) const
{ {
nFee = 0; nFee = 0;
listReceived.clear(); listReceived.clear();
@ -789,10 +789,10 @@ void CWalletTx::GetAmounts(list<COutputEntry>& listReceived,
strSentAccount = strFromAccount; strSentAccount = strFromAccount;
// Compute fee: // Compute fee:
int64_t nDebit = GetDebit(filter); CAmount nDebit = GetDebit(filter);
if (nDebit > 0) // debit>0 means we signed/sent this transaction if (nDebit > 0) // debit>0 means we signed/sent this transaction
{ {
int64_t nValueOut = GetValueOut(); CAmount nValueOut = GetValueOut();
nFee = nDebit - nValueOut; nFee = nDebit - nValueOut;
} }
@ -835,12 +835,12 @@ void CWalletTx::GetAmounts(list<COutputEntry>& listReceived,
} }
void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nReceived, void CWalletTx::GetAccountAmounts(const string& strAccount, CAmount& nReceived,
int64_t& nSent, int64_t& nFee, const isminefilter& filter) const CAmount& nSent, CAmount& nFee, const isminefilter& filter) const
{ {
nReceived = nSent = nFee = 0; nReceived = nSent = nFee = 0;
int64_t allFee; CAmount allFee;
string strSentAccount; string strSentAccount;
list<COutputEntry> listReceived; list<COutputEntry> listReceived;
list<COutputEntry> listSent; list<COutputEntry> listSent;
@ -1011,9 +1011,9 @@ void CWallet::ResendWalletTransactions()
// //
int64_t CWallet::GetBalance() const CAmount CWallet::GetBalance() const
{ {
int64_t nTotal = 0; CAmount nTotal = 0;
{ {
LOCK2(cs_main, cs_wallet); LOCK2(cs_main, cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
@ -1027,9 +1027,9 @@ int64_t CWallet::GetBalance() const
return nTotal; return nTotal;
} }
int64_t CWallet::GetUnconfirmedBalance() const CAmount CWallet::GetUnconfirmedBalance() const
{ {
int64_t nTotal = 0; CAmount nTotal = 0;
{ {
LOCK2(cs_main, cs_wallet); LOCK2(cs_main, cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
@ -1042,9 +1042,9 @@ int64_t CWallet::GetUnconfirmedBalance() const
return nTotal; return nTotal;
} }
int64_t CWallet::GetImmatureBalance() const CAmount CWallet::GetImmatureBalance() const
{ {
int64_t nTotal = 0; CAmount nTotal = 0;
{ {
LOCK2(cs_main, cs_wallet); LOCK2(cs_main, cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
@ -1056,9 +1056,9 @@ int64_t CWallet::GetImmatureBalance() const
return nTotal; return nTotal;
} }
int64_t CWallet::GetWatchOnlyBalance() const CAmount CWallet::GetWatchOnlyBalance() const
{ {
int64_t nTotal = 0; CAmount nTotal = 0;
{ {
LOCK2(cs_main, cs_wallet); LOCK2(cs_main, cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
@ -1072,9 +1072,9 @@ int64_t CWallet::GetWatchOnlyBalance() const
return nTotal; return nTotal;
} }
int64_t CWallet::GetUnconfirmedWatchOnlyBalance() const CAmount CWallet::GetUnconfirmedWatchOnlyBalance() const
{ {
int64_t nTotal = 0; CAmount nTotal = 0;
{ {
LOCK2(cs_main, cs_wallet); LOCK2(cs_main, cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
@ -1087,9 +1087,9 @@ int64_t CWallet::GetUnconfirmedWatchOnlyBalance() const
return nTotal; return nTotal;
} }
int64_t CWallet::GetImmatureWatchOnlyBalance() const CAmount CWallet::GetImmatureWatchOnlyBalance() const
{ {
int64_t nTotal = 0; CAmount nTotal = 0;
{ {
LOCK2(cs_main, cs_wallet); LOCK2(cs_main, cs_wallet);
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it) for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
@ -1137,8 +1137,8 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed, const
} }
} }
static void ApproximateBestSubset(vector<pair<int64_t, pair<const CWalletTx*,unsigned int> > >vValue, int64_t nTotalLower, int64_t nTargetValue, static void ApproximateBestSubset(vector<pair<CAmount, pair<const CWalletTx*,unsigned int> > >vValue, const CAmount& nTotalLower, const CAmount& nTargetValue,
vector<char>& vfBest, int64_t& nBest, int iterations = 1000) vector<char>& vfBest, CAmount& nBest, int iterations = 1000)
{ {
vector<char> vfIncluded; vector<char> vfIncluded;
@ -1150,7 +1150,7 @@ static void ApproximateBestSubset(vector<pair<int64_t, pair<const CWalletTx*,uns
for (int nRep = 0; nRep < iterations && nBest != nTargetValue; nRep++) for (int nRep = 0; nRep < iterations && nBest != nTargetValue; nRep++)
{ {
vfIncluded.assign(vValue.size(), false); vfIncluded.assign(vValue.size(), false);
int64_t nTotal = 0; CAmount nTotal = 0;
bool fReachedTarget = false; bool fReachedTarget = false;
for (int nPass = 0; nPass < 2 && !fReachedTarget; nPass++) for (int nPass = 0; nPass < 2 && !fReachedTarget; nPass++)
{ {
@ -1183,18 +1183,18 @@ static void ApproximateBestSubset(vector<pair<int64_t, pair<const CWalletTx*,uns
} }
} }
bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfTheirs, vector<COutput> vCoins, bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, vector<COutput> vCoins,
set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet) const
{ {
setCoinsRet.clear(); setCoinsRet.clear();
nValueRet = 0; nValueRet = 0;
// List of values less than target // List of values less than target
pair<int64_t, pair<const CWalletTx*,unsigned int> > coinLowestLarger; pair<CAmount, pair<const CWalletTx*,unsigned int> > coinLowestLarger;
coinLowestLarger.first = std::numeric_limits<int64_t>::max(); coinLowestLarger.first = std::numeric_limits<CAmount>::max();
coinLowestLarger.second.first = NULL; coinLowestLarger.second.first = NULL;
vector<pair<int64_t, pair<const CWalletTx*,unsigned int> > > vValue; vector<pair<CAmount, pair<const CWalletTx*,unsigned int> > > vValue;
int64_t nTotalLower = 0; CAmount nTotalLower = 0;
random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt); random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt);
@ -1209,9 +1209,9 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfT
continue; continue;
int i = output.i; int i = output.i;
int64_t n = pcoin->vout[i].nValue; CAmount n = pcoin->vout[i].nValue;
pair<int64_t,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin, i)); pair<CAmount,pair<const CWalletTx*,unsigned int> > coin = make_pair(n,make_pair(pcoin, i));
if (n == nTargetValue) if (n == nTargetValue)
{ {
@ -1252,7 +1252,7 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfT
// Solve subset sum by stochastic approximation // Solve subset sum by stochastic approximation
sort(vValue.rbegin(), vValue.rend(), CompareValueOnly()); sort(vValue.rbegin(), vValue.rend(), CompareValueOnly());
vector<char> vfBest; vector<char> vfBest;
int64_t nBest; CAmount nBest;
ApproximateBestSubset(vValue, nTotalLower, nTargetValue, vfBest, nBest, 1000); ApproximateBestSubset(vValue, nTotalLower, nTargetValue, vfBest, nBest, 1000);
if (nBest != nTargetValue && nTotalLower >= nTargetValue + CENT) if (nBest != nTargetValue && nTotalLower >= nTargetValue + CENT)
@ -1284,7 +1284,7 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfT
return true; return true;
} }
bool CWallet::SelectCoins(int64_t nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet, const CCoinControl* coinControl) const bool CWallet::SelectCoins(const CAmount& nTargetValue, set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl* coinControl) const
{ {
vector<COutput> vCoins; vector<COutput> vCoins;
AvailableCoins(vCoins, true, coinControl); AvailableCoins(vCoins, true, coinControl);
@ -1310,11 +1310,11 @@ bool CWallet::SelectCoins(int64_t nTargetValue, set<pair<const CWalletTx*,unsign
bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend, bool CWallet::CreateTransaction(const vector<pair<CScript, CAmount> >& vecSend,
CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl) CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl)
{ {
int64_t nValue = 0; CAmount nValue = 0;
BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend) BOOST_FOREACH (const PAIRTYPE(CScript, CAmount)& s, vecSend)
{ {
if (nValue < 0) if (nValue < 0)
{ {
@ -1343,10 +1343,10 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
txNew.vout.clear(); txNew.vout.clear();
wtxNew.fFromMe = true; wtxNew.fFromMe = true;
int64_t nTotalValue = nValue + nFeeRet; CAmount nTotalValue = nValue + nFeeRet;
double dPriority = 0; double dPriority = 0;
// vouts to the payees // vouts to the payees
BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend) BOOST_FOREACH (const PAIRTYPE(CScript, CAmount)& s, vecSend)
{ {
CTxOut txout(s.second, s.first); CTxOut txout(s.second, s.first);
if (txout.IsDust(::minRelayTxFee)) if (txout.IsDust(::minRelayTxFee))
@ -1359,7 +1359,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
// Choose coins to use // Choose coins to use
set<pair<const CWalletTx*,unsigned int> > setCoins; set<pair<const CWalletTx*,unsigned int> > setCoins;
int64_t nValueIn = 0; CAmount nValueIn = 0;
if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl)) if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl))
{ {
strFailReason = _("Insufficient funds"); strFailReason = _("Insufficient funds");
@ -1367,14 +1367,14 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
} }
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins) BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
{ {
int64_t nCredit = pcoin.first->vout[pcoin.second].nValue; CAmount nCredit = pcoin.first->vout[pcoin.second].nValue;
//The priority after the next block (depth+1) is used instead of the current, //The priority after the next block (depth+1) is used instead of the current,
//reflecting an assumption the user would accept a bit more delay for //reflecting an assumption the user would accept a bit more delay for
//a chance at a free transaction. //a chance at a free transaction.
dPriority += (double)nCredit * (pcoin.first->GetDepthInMainChain()+1); dPriority += (double)nCredit * (pcoin.first->GetDepthInMainChain()+1);
} }
int64_t nChange = nValueIn - nValue - nFeeRet; CAmount nChange = nValueIn - nValue - nFeeRet;
if (nChange > 0) if (nChange > 0)
{ {
@ -1450,7 +1450,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
} }
dPriority = wtxNew.ComputePriority(dPriority, nBytes); dPriority = wtxNew.ComputePriority(dPriority, nBytes);
int64_t nFeeNeeded = GetMinimumFee(nBytes, nTxConfirmTarget, mempool); CAmount nFeeNeeded = GetMinimumFee(nBytes, nTxConfirmTarget, mempool);
if (nFeeRet >= nFeeNeeded) if (nFeeRet >= nFeeNeeded)
break; // Done, enough fee included. break; // Done, enough fee included.
@ -1481,10 +1481,10 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
return true; return true;
} }
bool CWallet::CreateTransaction(CScript scriptPubKey, int64_t nValue, bool CWallet::CreateTransaction(CScript scriptPubKey, const CAmount& nValue,
CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl) CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl)
{ {
vector< pair<CScript, int64_t> > vecSend; vector< pair<CScript, CAmount> > vecSend;
vecSend.push_back(make_pair(scriptPubKey, nValue)); vecSend.push_back(make_pair(scriptPubKey, nValue));
return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet, strFailReason, coinControl); return CreateTransaction(vecSend, wtxNew, reservekey, nFeeRet, strFailReason, coinControl);
} }
@ -1539,7 +1539,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
string CWallet::SendMoney(const CTxDestination &address, int64_t nValue, CWalletTx& wtxNew) string CWallet::SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew)
{ {
// Check amount // Check amount
if (nValue <= 0) if (nValue <= 0)
@ -1560,7 +1560,7 @@ string CWallet::SendMoney(const CTxDestination &address, int64_t nValue, CWallet
// Create and send the transaction // Create and send the transaction
CReserveKey reservekey(this); CReserveKey reservekey(this);
int64_t nFeeRequired; CAmount nFeeRequired;
if (!CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired, strError)) if (!CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired, strError))
{ {
if (nValue + nFeeRequired > GetBalance()) if (nValue + nFeeRequired > GetBalance())
@ -1576,10 +1576,10 @@ string CWallet::SendMoney(const CTxDestination &address, int64_t nValue, CWallet
int64_t CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool) CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool)
{ {
// payTxFee is user-set "I want to pay this much" // payTxFee is user-set "I want to pay this much"
int64_t nFeeNeeded = payTxFee.GetFee(nTxBytes); CAmount nFeeNeeded = payTxFee.GetFee(nTxBytes);
// User didn't set: use -txconfirmtarget to estimate... // User didn't set: use -txconfirmtarget to estimate...
if (nFeeNeeded == 0) if (nFeeNeeded == 0)
nFeeNeeded = pool.estimateFee(nConfirmTarget).GetFee(nTxBytes); nFeeNeeded = pool.estimateFee(nConfirmTarget).GetFee(nTxBytes);
@ -1838,9 +1838,9 @@ int64_t CWallet::GetOldestKeyPoolTime()
return keypool.nTime; return keypool.nTime;
} }
std::map<CTxDestination, int64_t> CWallet::GetAddressBalances() std::map<CTxDestination, CAmount> CWallet::GetAddressBalances()
{ {
map<CTxDestination, int64_t> balances; map<CTxDestination, CAmount> balances;
{ {
LOCK(cs_wallet); LOCK(cs_wallet);
@ -1866,7 +1866,7 @@ std::map<CTxDestination, int64_t> CWallet::GetAddressBalances()
if(!ExtractDestination(pcoin->vout[i].scriptPubKey, addr)) if(!ExtractDestination(pcoin->vout[i].scriptPubKey, addr))
continue; continue;
int64_t n = IsSpent(walletEntry.first, i) ? 0 : pcoin->vout[i].nValue; CAmount n = IsSpent(walletEntry.first, i) ? 0 : pcoin->vout[i].nValue;
if (!balances.count(addr)) if (!balances.count(addr))
balances[addr] = 0; balances[addr] = 0;

100
src/wallet.h

@ -30,9 +30,9 @@ extern unsigned int nTxConfirmTarget;
extern bool bSpendZeroConfChange; extern bool bSpendZeroConfChange;
// -paytxfee default // -paytxfee default
static const int64_t DEFAULT_TRANSACTION_FEE = 0; static const CAmount DEFAULT_TRANSACTION_FEE = 0;
// -paytxfee will warn if called with a higher fee than this amount (in satoshis) per KB // -paytxfee will warn if called with a higher fee than this amount (in satoshis) per KB
static const int nHighTransactionFeeWarning = 0.01 * COIN; static const CAmount nHighTransactionFeeWarning = 0.01 * COIN;
// Largest (in bytes) free transaction we're willing to create // Largest (in bytes) free transaction we're willing to create
static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000; static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000;
@ -98,7 +98,7 @@ public:
class CWallet : public CCryptoKeyStore, public CWalletInterface class CWallet : public CCryptoKeyStore, public CWalletInterface
{ {
private: private:
bool SelectCoins(int64_t nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet, const CCoinControl *coinControl = NULL) const; bool SelectCoins(const CAmount& nTargetValue, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet, const CCoinControl *coinControl = NULL) const;
CWalletDB *pwalletdbEncryption; CWalletDB *pwalletdbEncryption;
@ -182,7 +182,7 @@ public:
bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; } bool CanSupportFeature(enum WalletFeature wf) { AssertLockHeld(cs_wallet); return nWalletMaxVersion >= wf; }
void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL) const; void AvailableCoins(std::vector<COutput>& vCoins, bool fOnlyConfirmed=true, const CCoinControl *coinControl = NULL) const;
bool SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const; bool SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, std::vector<COutput> vCoins, std::set<std::pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet) const;
bool IsSpent(const uint256& hash, unsigned int n) const; bool IsSpent(const uint256& hash, unsigned int n) const;
@ -253,21 +253,21 @@ public:
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false); int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
void ReacceptWalletTransactions(); void ReacceptWalletTransactions();
void ResendWalletTransactions(); void ResendWalletTransactions();
int64_t GetBalance() const; CAmount GetBalance() const;
int64_t GetUnconfirmedBalance() const; CAmount GetUnconfirmedBalance() const;
int64_t GetImmatureBalance() const; CAmount GetImmatureBalance() const;
int64_t GetWatchOnlyBalance() const; CAmount GetWatchOnlyBalance() const;
int64_t GetUnconfirmedWatchOnlyBalance() const; CAmount GetUnconfirmedWatchOnlyBalance() const;
int64_t GetImmatureWatchOnlyBalance() const; CAmount GetImmatureWatchOnlyBalance() const;
bool CreateTransaction(const std::vector<std::pair<CScript, int64_t> >& vecSend, bool CreateTransaction(const std::vector<std::pair<CScript, CAmount> >& vecSend,
CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL); CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
bool CreateTransaction(CScript scriptPubKey, int64_t nValue, bool CreateTransaction(CScript scriptPubKey, const CAmount& nValue,
CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL); CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey); bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey);
std::string SendMoney(const CTxDestination &address, int64_t nValue, CWalletTx& wtxNew); std::string SendMoney(const CTxDestination &address, CAmount nValue, CWalletTx& wtxNew);
static CFeeRate minTxFee; static CFeeRate minTxFee;
static int64_t GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool); static CAmount GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarget, const CTxMemPool& pool);
bool NewKeyPool(); bool NewKeyPool();
bool TopUpKeyPool(unsigned int kpSize = 0); bool TopUpKeyPool(unsigned int kpSize = 0);
@ -279,24 +279,24 @@ public:
void GetAllReserveKeys(std::set<CKeyID>& setAddress) const; void GetAllReserveKeys(std::set<CKeyID>& setAddress) const;
std::set< std::set<CTxDestination> > GetAddressGroupings(); std::set< std::set<CTxDestination> > GetAddressGroupings();
std::map<CTxDestination, int64_t> GetAddressBalances(); std::map<CTxDestination, CAmount> GetAddressBalances();
std::set<CTxDestination> GetAccountAddresses(std::string strAccount) const; std::set<CTxDestination> GetAccountAddresses(std::string strAccount) const;
isminetype IsMine(const CTxIn& txin) const; isminetype IsMine(const CTxIn& txin) const;
int64_t GetDebit(const CTxIn& txin, const isminefilter& filter) const; CAmount GetDebit(const CTxIn& txin, const isminefilter& filter) const;
isminetype IsMine(const CTxOut& txout) const isminetype IsMine(const CTxOut& txout) const
{ {
return ::IsMine(*this, txout.scriptPubKey); return ::IsMine(*this, txout.scriptPubKey);
} }
int64_t GetCredit(const CTxOut& txout, const isminefilter& filter) const CAmount GetCredit(const CTxOut& txout, const isminefilter& filter) const
{ {
if (!MoneyRange(txout.nValue)) if (!MoneyRange(txout.nValue))
throw std::runtime_error("CWallet::GetCredit() : value out of range"); throw std::runtime_error("CWallet::GetCredit() : value out of range");
return ((IsMine(txout) & filter) ? txout.nValue : 0); return ((IsMine(txout) & filter) ? txout.nValue : 0);
} }
bool IsChange(const CTxOut& txout) const; bool IsChange(const CTxOut& txout) const;
int64_t GetChange(const CTxOut& txout) const CAmount GetChange(const CTxOut& txout) const
{ {
if (!MoneyRange(txout.nValue)) if (!MoneyRange(txout.nValue))
throw std::runtime_error("CWallet::GetChange() : value out of range"); throw std::runtime_error("CWallet::GetChange() : value out of range");
@ -313,9 +313,9 @@ public:
{ {
return (GetDebit(tx, ISMINE_ALL) > 0); return (GetDebit(tx, ISMINE_ALL) > 0);
} }
int64_t GetDebit(const CTransaction& tx, const isminefilter& filter) const CAmount GetDebit(const CTransaction& tx, const isminefilter& filter) const
{ {
int64_t nDebit = 0; CAmount nDebit = 0;
BOOST_FOREACH(const CTxIn& txin, tx.vin) BOOST_FOREACH(const CTxIn& txin, tx.vin)
{ {
nDebit += GetDebit(txin, filter); nDebit += GetDebit(txin, filter);
@ -324,9 +324,9 @@ public:
} }
return nDebit; return nDebit;
} }
int64_t GetCredit(const CTransaction& tx, const isminefilter& filter) const CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const
{ {
int64_t nCredit = 0; CAmount nCredit = 0;
BOOST_FOREACH(const CTxOut& txout, tx.vout) BOOST_FOREACH(const CTxOut& txout, tx.vout)
{ {
nCredit += GetCredit(txout, filter); nCredit += GetCredit(txout, filter);
@ -335,9 +335,9 @@ public:
} }
return nCredit; return nCredit;
} }
int64_t GetChange(const CTransaction& tx) const CAmount GetChange(const CTransaction& tx) const
{ {
int64_t nChange = 0; CAmount nChange = 0;
BOOST_FOREACH(const CTxOut& txout, tx.vout) BOOST_FOREACH(const CTxOut& txout, tx.vout)
{ {
nChange += GetChange(txout); nChange += GetChange(txout);
@ -457,7 +457,7 @@ static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
struct COutputEntry struct COutputEntry
{ {
CTxDestination destination; CTxDestination destination;
int64_t amount; CAmount amount;
int vout; int vout;
}; };
@ -545,15 +545,15 @@ public:
mutable bool fImmatureWatchCreditCached; mutable bool fImmatureWatchCreditCached;
mutable bool fAvailableWatchCreditCached; mutable bool fAvailableWatchCreditCached;
mutable bool fChangeCached; mutable bool fChangeCached;
mutable int64_t nDebitCached; mutable CAmount nDebitCached;
mutable int64_t nCreditCached; mutable CAmount nCreditCached;
mutable int64_t nImmatureCreditCached; mutable CAmount nImmatureCreditCached;
mutable int64_t nAvailableCreditCached; mutable CAmount nAvailableCreditCached;
mutable int64_t nWatchDebitCached; mutable CAmount nWatchDebitCached;
mutable int64_t nWatchCreditCached; mutable CAmount nWatchCreditCached;
mutable int64_t nImmatureWatchCreditCached; mutable CAmount nImmatureWatchCreditCached;
mutable int64_t nAvailableWatchCreditCached; mutable CAmount nAvailableWatchCreditCached;
mutable int64_t nChangeCached; mutable CAmount nChangeCached;
CWalletTx() CWalletTx()
{ {
@ -670,12 +670,12 @@ public:
} }
// filter decides which addresses will count towards the debit // filter decides which addresses will count towards the debit
int64_t GetDebit(const isminefilter& filter) const CAmount GetDebit(const isminefilter& filter) const
{ {
if (vin.empty()) if (vin.empty())
return 0; return 0;
int64_t debit = 0; CAmount debit = 0;
if(filter & ISMINE_SPENDABLE) if(filter & ISMINE_SPENDABLE)
{ {
if (fDebitCached) if (fDebitCached)
@ -701,7 +701,7 @@ public:
return debit; return debit;
} }
int64_t GetCredit(bool fUseCache=true) const CAmount GetCredit(bool fUseCache=true) const
{ {
// Must wait until coinbase is safely deep enough in the chain before valuing it // Must wait until coinbase is safely deep enough in the chain before valuing it
if (IsCoinBase() && GetBlocksToMaturity() > 0) if (IsCoinBase() && GetBlocksToMaturity() > 0)
@ -715,7 +715,7 @@ public:
return nCreditCached; return nCreditCached;
} }
int64_t GetImmatureCredit(bool fUseCache=true) const CAmount GetImmatureCredit(bool fUseCache=true) const
{ {
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
{ {
@ -729,7 +729,7 @@ public:
return 0; return 0;
} }
int64_t GetAvailableCredit(bool fUseCache=true) const CAmount GetAvailableCredit(bool fUseCache=true) const
{ {
if (pwallet == 0) if (pwallet == 0)
return 0; return 0;
@ -741,7 +741,7 @@ public:
if (fUseCache && fAvailableCreditCached) if (fUseCache && fAvailableCreditCached)
return nAvailableCreditCached; return nAvailableCreditCached;
int64_t nCredit = 0; CAmount nCredit = 0;
uint256 hashTx = GetHash(); uint256 hashTx = GetHash();
for (unsigned int i = 0; i < vout.size(); i++) for (unsigned int i = 0; i < vout.size(); i++)
{ {
@ -759,7 +759,7 @@ public:
return nCredit; return nCredit;
} }
int64_t GetImmatureWatchOnlyCredit(const bool& fUseCache=true) const CAmount GetImmatureWatchOnlyCredit(const bool& fUseCache=true) const
{ {
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain()) if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
{ {
@ -773,7 +773,7 @@ public:
return 0; return 0;
} }
int64_t GetAvailableWatchOnlyCredit(const bool& fUseCache=true) const CAmount GetAvailableWatchOnlyCredit(const bool& fUseCache=true) const
{ {
if (pwallet == 0) if (pwallet == 0)
return 0; return 0;
@ -785,7 +785,7 @@ public:
if (fUseCache && fAvailableWatchCreditCached) if (fUseCache && fAvailableWatchCreditCached)
return nAvailableWatchCreditCached; return nAvailableWatchCreditCached;
int64_t nCredit = 0; CAmount nCredit = 0;
for (unsigned int i = 0; i < vout.size(); i++) for (unsigned int i = 0; i < vout.size(); i++)
{ {
if (!pwallet->IsSpent(GetHash(), i)) if (!pwallet->IsSpent(GetHash(), i))
@ -802,7 +802,7 @@ public:
return nCredit; return nCredit;
} }
int64_t GetChange() const CAmount GetChange() const
{ {
if (fChangeCached) if (fChangeCached)
return nChangeCached; return nChangeCached;
@ -812,10 +812,10 @@ public:
} }
void GetAmounts(std::list<COutputEntry>& listReceived, void GetAmounts(std::list<COutputEntry>& listReceived,
std::list<COutputEntry>& listSent, int64_t& nFee, std::string& strSentAccount, const isminefilter& filter) const; std::list<COutputEntry>& listSent, CAmount& nFee, std::string& strSentAccount, const isminefilter& filter) const;
void GetAccountAmounts(const std::string& strAccount, int64_t& nReceived, void GetAccountAmounts(const std::string& strAccount, CAmount& nReceived,
int64_t& nSent, int64_t& nFee, const isminefilter& filter) const; CAmount& nSent, CAmount& nFee, const isminefilter& filter) const;
bool IsFromMe(const isminefilter& filter) const bool IsFromMe(const isminefilter& filter) const
{ {
@ -949,7 +949,7 @@ class CAccountingEntry
{ {
public: public:
std::string strAccount; std::string strAccount;
int64_t nCreditDebit; CAmount nCreditDebit;
int64_t nTime; int64_t nTime;
std::string strOtherAccount; std::string strOtherAccount;
std::string strComment; std::string strComment;

4
src/walletdb.cpp

@ -187,12 +187,12 @@ bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
return WriteAccountingEntry(++nAccountingEntryNumber, acentry); return WriteAccountingEntry(++nAccountingEntryNumber, acentry);
} }
int64_t CWalletDB::GetAccountCreditDebit(const string& strAccount) CAmount CWalletDB::GetAccountCreditDebit(const string& strAccount)
{ {
list<CAccountingEntry> entries; list<CAccountingEntry> entries;
ListAccountCreditDebit(strAccount, entries); ListAccountCreditDebit(strAccount, entries);
int64_t nCreditDebit = 0; CAmount nCreditDebit = 0;
BOOST_FOREACH (const CAccountingEntry& entry, entries) BOOST_FOREACH (const CAccountingEntry& entry, entries)
nCreditDebit += entry.nCreditDebit; nCreditDebit += entry.nCreditDebit;

3
src/walletdb.h

@ -6,6 +6,7 @@
#ifndef BITCOIN_WALLETDB_H #ifndef BITCOIN_WALLETDB_H
#define BITCOIN_WALLETDB_H #define BITCOIN_WALLETDB_H
#include "amount.h"
#include "db.h" #include "db.h"
#include "key.h" #include "key.h"
#include "keystore.h" #include "keystore.h"
@ -118,7 +119,7 @@ public:
bool EraseDestData(const std::string &address, const std::string &key); bool EraseDestData(const std::string &address, const std::string &key);
bool WriteAccountingEntry(const CAccountingEntry& acentry); bool WriteAccountingEntry(const CAccountingEntry& acentry);
int64_t GetAccountCreditDebit(const std::string& strAccount); CAmount GetAccountCreditDebit(const std::string& strAccount);
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries); void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& acentries);
DBErrors ReorderTransactions(CWallet* pwallet); DBErrors ReorderTransactions(CWallet* pwallet);

Loading…
Cancel
Save