Browse Source

Use a typedef for monetary values

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

+ 1
- 0
src/Makefile.am View File

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

+ 13
- 0
src/amount.h View File

@@ -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

+ 2
- 2
src/bitcoin-tx.cpp View File

@@ -214,7 +214,7 @@ static void MutateTxAddOutAddr(CMutableTransaction& tx, const string& strInput)

// extract and validate VALUE
string strValue = strInput.substr(0, pos);
int64_t value;
CAmount value;
if (!ParseMoney(strValue, value))
throw runtime_error("invalid TX output value");

@@ -242,7 +242,7 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const string& strInput

// extract and validate VALUE
string strValue = strInput.substr(0, pos);
int64_t value;
CAmount value;
if (!ParseMoney(strValue, value))
throw runtime_error("invalid TX output value");


+ 2
- 2
src/coins.cpp View File

@@ -171,12 +171,12 @@ const CTxOut &CCoinsViewCache::GetOutputFor(const CTxIn& input) const
return coins->vout[input.prevout.n];
}

int64_t CCoinsViewCache::GetValueIn(const CTransaction& tx) const
CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const
{
if (tx.IsCoinBase())
return 0;

int64_t nResult = 0;
CAmount nResult = 0;
for (unsigned int i = 0; i < tx.vin.size(); i++)
nResult += GetOutputFor(tx.vin[i]).nValue;


+ 2
- 2
src/coins.h View File

@@ -266,7 +266,7 @@ struct CCoinsStats
uint64_t nTransactionOutputs;
uint64_t nSerializedSize;
uint256 hashSerialized;
int64_t nTotalAmount;
CAmount nTotalAmount;

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
@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
bool HaveInputs(const CTransaction& tx) const;

+ 6
- 6
src/core.cpp View File

@@ -43,7 +43,7 @@ std::string CTxIn::ToString() const
return str;
}

CTxOut::CTxOut(int64_t nValueIn, CScript scriptPubKeyIn)
CTxOut::CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn)
{
nValue = nValueIn;
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));
}

CFeeRate::CFeeRate(int64_t nFeePaid, size_t nSize)
CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize)
{
if (nSize > 0)
nSatoshisPerK = nFeePaid*1000/nSize;
@@ -67,9 +67,9 @@ CFeeRate::CFeeRate(int64_t nFeePaid, size_t nSize)
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)
nFee = nSatoshisPerK;
@@ -110,9 +110,9 @@ CTransaction& CTransaction::operator=(const CTransaction &tx) {
return *this;
}

int64_t CTransaction::GetValueOut() const
CAmount CTransaction::GetValueOut() const
{
int64_t nValueOut = 0;
CAmount nValueOut = 0;
BOOST_FOREACH(const CTxOut& txout, vout)
{
nValueOut += txout.nValue;

+ 11
- 10
src/core.h View File

@@ -6,6 +6,7 @@
#ifndef BITCOIN_CORE_H
#define BITCOIN_CORE_H

#include "amount.h"
#include "script/compressor.h"
#include "script/script.h"
#include "serialize.h"
@@ -19,8 +20,8 @@ static const int64_t COIN = 100000000;
static const int64_t CENT = 1000000;

/** No amount larger than this (in satoshi) is valid */
static const int64_t MAX_MONEY = 21000000 * COIN;
inline bool MoneyRange(int64_t nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
static const CAmount MAX_MONEY = 21000000 * COIN;
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 */
class COutPoint
@@ -129,15 +130,15 @@ public:
class CFeeRate
{
private:
int64_t nSatoshisPerK; // unit is satoshis-per-1,000-bytes
CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes
public:
CFeeRate() : nSatoshisPerK(0) { }
explicit CFeeRate(int64_t _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
CFeeRate(int64_t nFeePaid, size_t nSize);
explicit CFeeRate(const CAmount& _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) { }
CFeeRate(const CAmount& nFeePaid, size_t nSize);
CFeeRate(const CFeeRate& other) { nSatoshisPerK = other.nSatoshisPerK; }

int64_t GetFee(size_t size) const; // unit returned is satoshis
int64_t GetFeePerK() const { return GetFee(1000); } // satoshis-per-1000-bytes
CAmount GetFee(size_t size) const; // unit returned is satoshis
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; }
@@ -161,7 +162,7 @@ public:
class CTxOut
{
public:
int64_t nValue;
CAmount nValue;
CScript scriptPubKey;

CTxOut()
@@ -169,7 +170,7 @@ public:
SetNull();
}

CTxOut(int64_t nValueIn, CScript scriptPubKeyIn);
CTxOut(const CAmount& nValueIn, CScript scriptPubKeyIn);

ADD_SERIALIZE_METHODS;

@@ -276,7 +277,7 @@ public:
}

// Return sum of txouts.
int64_t GetValueOut() const;
CAmount GetValueOut() const;
// GetValueIn() is a method on CCoinsViewCache, because
// inputs must be known to compute value in.


+ 3
- 3
src/init.cpp View File

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

+ 13
- 13
src/main.cpp View File

@@ -781,7 +781,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
REJECT_INVALID, "bad-txns-oversize");

// Check for negative or overflow output values
int64_t nValueOut = 0;
CAmount nValueOut = 0;
BOOST_FOREACH(const CTxOut& txout, tx.vout)
{
if (txout.nValue < 0)
@@ -823,19 +823,19 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state)
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);
uint256 hash = tx.GetHash();
double dPriorityDelta = 0;
int64_t nFeeDelta = 0;
CAmount nFeeDelta = 0;
mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
if (dPriorityDelta > 0 || nFeeDelta > 0)
return 0;
}

int64_t nMinFee = ::minRelayTxFee.GetFee(nBytes);
CAmount nMinFee = ::minRelayTxFee.GetFee(nBytes);

if (fAllowFree)
{
@@ -898,7 +898,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
CCoinsView dummy;
CCoinsViewCache view(dummy);

int64_t nValueIn = 0;
CAmount nValueIn = 0;
{
LOCK(pool.cs);
CCoinsViewMemPool viewMemPool(*pcoinsTip, pool);
@@ -950,15 +950,15 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
hash.ToString(), nSigOps, MAX_TX_SIGOPS),
REJECT_NONSTANDARD, "bad-txns-too-many-sigops");

int64_t nValueOut = tx.GetValueOut();
int64_t nFees = nValueIn-nValueOut;
CAmount nValueOut = tx.GetValueOut();
CAmount nFees = nValueIn-nValueOut;
double dPriority = view.GetPriority(tx, chainActive.Height());

CTxMemPoolEntry entry(tx, nFees, GetTime(), dPriority, chainActive.Height());
unsigned int nSize = entry.GetTxSize();

// 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)
return state.DoS(0, error("AcceptToMemoryPool : not enough fees %s, %d < %d",
hash.ToString(), nFees, txMinFee),
@@ -1178,7 +1178,7 @@ void static PruneOrphanBlocks()
mapOrphanBlocks.erase(hash);
}

int64_t GetBlockValue(int nHeight, int64_t nFees)
CAmount GetBlockValue(int nHeight, const CAmount& nFees)
{
int64_t nSubsidy = 50 * COIN;
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.
CBlockIndex *pindexPrev = mapBlockIndex.find(inputs.GetBestBlock())->second;
int nSpendHeight = pindexPrev->nHeight + 1;
int64_t nValueIn = 0;
int64_t nFees = 0;
CAmount nValueIn = 0;
CAmount nFees = 0;
for (unsigned int i = 0; i < tx.vin.size(); i++)
{
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");

// Tally transaction fees
int64_t nTxFee = nValueIn - tx.GetValueOut();
CAmount nTxFee = nValueIn - tx.GetValueOut();
if (nTxFee < 0)
return state.DoS(100, error("CheckInputs() : %s nTxFee < 0", tx.GetHash().ToString()),
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);

int64_t nTimeStart = GetTimeMicros();
int64_t nFees = 0;
CAmount nFees = 0;
int nInputs = 0;
unsigned int nSigOps = 0;
CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));

+ 3
- 3
src/main.h View File

@@ -172,7 +172,7 @@ std::string GetWarnings(std::string strFor);
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 */
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 */
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
@@ -970,7 +970,7 @@ extern CBlockTreeDB *pblocktree;
struct CBlockTemplate
{
CBlock block;
std::vector<int64_t> vTxFees;
std::vector<CAmount> vTxFees;
std::vector<int64_t> vTxSigOps;
};


+ 5
- 5
src/miner.cpp View File

@@ -111,7 +111,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize);

// Collect memory pool transactions into the block
int64_t nFees = 0;
CAmount nFees = 0;

{
LOCK2(cs_main, mempool.cs);
@@ -135,7 +135,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)

COrphan* porphan = NULL;
double dPriority = 0;
int64_t nTotalIn = 0;
CAmount nTotalIn = 0;
bool fMissingInputs = false;
BOOST_FOREACH(const CTxIn& txin, tx.vin)
{
@@ -170,7 +170,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
const CCoins* coins = view.AccessCoins(txin.prevout.hash);
assert(coins);

int64_t nValueIn = coins->vout[txin.prevout.n].nValue;
CAmount nValueIn = coins->vout[txin.prevout.n].nValue;
nTotalIn += nValueIn;

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:
const uint256& hash = tx.GetHash();
double dPriorityDelta = 0;
int64_t nFeeDelta = 0;
CAmount nFeeDelta = 0;
mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta);
if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize))
continue;
@@ -247,7 +247,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
if (!view.HaveInputs(tx))
continue;

int64_t nTxFees = view.GetValueIn(tx)-tx.GetValueOut();
CAmount nTxFees = view.GetValueIn(tx)-tx.GetValueOut();

nTxSigOps += GetP2SHSigOpCount(tx, view);
if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)

+ 14
- 14
src/qt/bitcoinamountfield.cpp View File

@@ -44,7 +44,7 @@ public:
void fixup(QString &input) const
{
bool valid = false;
qint64 val = parse(input, &valid);
CAmount val = parse(input, &valid);
if(valid)
{
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);
}

void setValue(qint64 value)
void setValue(const CAmount& value)
{
lineEdit()->setText(BitcoinUnits::format(currentUnit, value, false, BitcoinUnits::separatorAlways));
emit valueChanged();
@@ -66,9 +66,9 @@ public:
void stepBy(int steps)
{
bool valid = false;
qint64 val = value(&valid);
CAmount val = value(&valid);
val = val + steps * singleStep;
val = qMin(qMax(val, Q_INT64_C(0)), BitcoinUnits::maxMoney());
val = qMin(qMax(val, CAmount(0)), BitcoinUnits::maxMoney());
setValue(val);
}

@@ -78,7 +78,7 @@ public:
if(text().isEmpty()) // Allow step-up with empty field
return StepUpEnabled;
bool valid = false;
qint64 val = value(&valid);
CAmount val = value(&valid);
if(valid)
{
if(val > 0)
@@ -92,7 +92,7 @@ public:
void setDisplayUnit(int unit)
{
bool valid = false;
qint64 val = value(&valid);
CAmount val = value(&valid);

currentUnit = unit;

@@ -102,7 +102,7 @@ public:
clear();
}

void setSingleStep(qint64 step)
void setSingleStep(const CAmount& step)
{
singleStep = step;
}
@@ -140,7 +140,7 @@ public:
}
private:
int currentUnit;
qint64 singleStep;
CAmount singleStep;
mutable QSize cachedMinimumSizeHint;

/**
@@ -148,9 +148,9 @@ private:
* return validity.
* @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);
if(valid)
{
@@ -253,12 +253,12 @@ QWidget *BitcoinAmountField::setupTabChain(QWidget *prev)
return unit;
}

qint64 BitcoinAmountField::value(bool *valid_out) const
CAmount BitcoinAmountField::value(bool *valid_out) const
{
return amount->value(valid_out);
}

void BitcoinAmountField::setValue(qint64 value)
void BitcoinAmountField::setValue(const CAmount& value)
{
amount->setValue(value);
}
@@ -285,7 +285,7 @@ void BitcoinAmountField::setDisplayUnit(int newUnit)
unit->setValue(newUnit);
}

void BitcoinAmountField::setSingleStep(qint64 step)
void BitcoinAmountField::setSingleStep(const CAmount& step)
{
amount->setSingleStep(step);
}

+ 6
- 4
src/qt/bitcoinamountfield.h View File

@@ -5,6 +5,8 @@
#ifndef BITCOINAMOUNTFIELD_H
#define BITCOINAMOUNTFIELD_H

#include "amount.h"

#include <QWidget>

class AmountSpinBox;
@@ -19,16 +21,16 @@ class BitcoinAmountField: public QWidget
{
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:
explicit BitcoinAmountField(QWidget *parent = 0);

qint64 value(bool *valid=0) const;
void setValue(qint64 value);
CAmount value(bool *value=0) const;
void setValue(const CAmount& value);

/** Set single step in satoshis **/
void setSingleStep(qint64 step);
void setSingleStep(const CAmount& step);

/** Make read-only **/
void setReadOnly(bool fReadOnly);

+ 1
- 1
src/qt/bitcoingui.cpp View File

@@ -864,7 +864,7 @@ void BitcoinGUI::closeEvent(QCloseEvent *event)
}

#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
message((amount)<0 ? tr("Sent transaction") : tr("Incoming transaction"),

+ 3
- 1
src/qt/bitcoingui.h View File

@@ -9,6 +9,8 @@
#include "config/bitcoin-config.h"
#endif

#include "amount.h"

#include <QLabel>
#include <QMainWindow>
#include <QMap>
@@ -159,7 +161,7 @@ public slots:
bool handlePaymentRequest(const SendCoinsRecipient& recipient);

/** 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

private slots:

+ 7
- 6
src/qt/bitcoinunits.cpp View File

@@ -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
// localized number formatting.
if(!valid(unit))
return QString(); // Refuse to format invalid unit
qint64 n = (qint64)nIn;
qint64 coin = factor(unit);
int num_decimals = decimals(unit);
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
// 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);
}

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));
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())
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
}
qint64 retvalue = str.toLongLong(&ok);
CAmount retvalue(str.toLongLong(&ok));
if(val_out)
{
*val_out = retvalue;
@@ -226,7 +227,7 @@ QVariant BitcoinUnits::data(const QModelIndex &index, int role) const
return QVariant();
}

qint64 BitcoinUnits::maxMoney()
CAmount BitcoinUnits::maxMoney()
{
return MAX_MONEY;
}

+ 7
- 5
src/qt/bitcoinunits.h View File

@@ -5,6 +5,8 @@
#ifndef BITCOINUNITS_H
#define BITCOINUNITS_H

#include "amount.h"

#include <QAbstractListModel>
#include <QString>

@@ -85,12 +87,12 @@ public:
//! Number of decimals left
static int decimals(int unit);
//! 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)
static QString formatWithUnit(int unit, qint64 amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
static QString formatHtmlWithUnit(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, const CAmount& amount, bool plussign=false, SeparatorStyle separators=separatorStandard);
//! 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 */
static QString getAmountColumnTitle(int unit);
///@}
@@ -117,7 +119,7 @@ public:
}

//! Return maximum number of base units (Satoshis)
static qint64 maxMoney();
static CAmount maxMoney();

private:
QList<BitcoinUnits::Unit> unitlist;

+ 8
- 8
src/qt/coincontroldialog.cpp View File

@@ -29,7 +29,7 @@
#include <QTreeWidgetItem>

using namespace std;
QList<qint64> CoinControlDialog::payAmounts;
QList<CAmount> CoinControlDialog::payAmounts;
CCoinControl* CoinControlDialog::coinControl = new CCoinControl();

CoinControlDialog::CoinControlDialog(QWidget *parent) :
@@ -443,10 +443,10 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
return;

// nPayAmount
qint64 nPayAmount = 0;
CAmount nPayAmount = 0;
bool fDust = false;
CMutableTransaction txDummy;
foreach(const qint64 &amount, CoinControlDialog::payAmounts)
foreach(const CAmount &amount, CoinControlDialog::payAmounts)
{
nPayAmount += amount;

@@ -460,10 +460,10 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog)
}

QString sPriorityLabel = tr("none");
int64_t nAmount = 0;
int64_t nPayFee = 0;
int64_t nAfterFee = 0;
int64_t nChange = 0;
CAmount nAmount = 0;
CAmount nPayFee = 0;
CAmount nAfterFee = 0;
CAmount nChange = 0;
unsigned int nBytes = 0;
unsigned int nBytesInputs = 0;
double dPriority = 0;
@@ -684,7 +684,7 @@ void CoinControlDialog::updateView()
itemWalletAddress->setText(COLUMN_ADDRESS, sWalletAddress);
}

int64_t nSum = 0;
CAmount nSum = 0;
double dPrioritySum = 0;
int nChildren = 0;
int nInputSum = 0;

+ 3
- 1
src/qt/coincontroldialog.h View File

@@ -5,6 +5,8 @@
#ifndef COINCONTROLDIALOG_H
#define COINCONTROLDIALOG_H

#include "amount.h"

#include <QAbstractButton>
#include <QAction>
#include <QDialog>
@@ -37,7 +39,7 @@ public:
static void updateLabels(WalletModel*, QDialog*);
static QString getPriorityLabel(const CTxMemPool& pool, double);

static QList<qint64> payAmounts;
static QList<CAmount> payAmounts;
static CCoinControl *coinControl;

private:

+ 1
- 1
src/qt/guiutil.cpp View File

@@ -221,7 +221,7 @@ QString formatBitcoinURI(const SendCoinsRecipient &info)
return ret;
}

bool isDust(const QString& address, qint64 amount)
bool isDust(const QString& address, const CAmount& amount)
{
CTxDestination dest = CBitcoinAddress(address.toStdString()).Get();
CScript script = GetScriptForDestination(dest);

+ 3
- 1
src/qt/guiutil.h View File

@@ -5,6 +5,8 @@
#ifndef GUIUTIL_H
#define GUIUTIL_H

#include "amount.h"

#include <QHeaderView>
#include <QMessageBox>
#include <QObject>
@@ -46,7 +48,7 @@ namespace GUIUtil
QString formatBitcoinURI(const SendCoinsRecipient &info);

// 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
QString HtmlEscape(const QString& str, bool fMultiLine=false);

+ 2
- 2
src/qt/optionsmodel.cpp View File

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

+ 3
- 1
src/qt/optionsmodel.h View File

@@ -5,6 +5,8 @@
#ifndef OPTIONSMODEL_H
#define OPTIONSMODEL_H

#include "amount.h"

#include <QAbstractListModel>

QT_BEGIN_NAMESPACE
@@ -82,7 +84,7 @@ private:

signals:
void displayUnitChanged(int unit);
void transactionFeeChanged(qint64);
void transactionFeeChanged(const CAmount&);
void coinControlFeaturesChanged(bool);
};


+ 2
- 2
src/qt/overviewpage.cpp View File

@@ -146,7 +146,7 @@ OverviewPage::~OverviewPage()
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();
currentBalance = balance;
@@ -220,7 +220,7 @@ void OverviewPage::setWalletModel(WalletModel *model)
// Keep up to date with wallet
setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(),
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()));


+ 10
- 8
src/qt/overviewpage.h View File

@@ -5,6 +5,8 @@
#ifndef OVERVIEWPAGE_H
#define OVERVIEWPAGE_H

#include "amount.h"

#include <QWidget>

class ClientModel;
@@ -34,8 +36,8 @@ public:
void showOutOfSyncWarning(bool fShow);

public slots:
void setBalance(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance,
qint64 watchOnlyBalance, qint64 watchUnconfBalance, qint64 watchImmatureBalance);
void setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance);

signals:
void transactionClicked(const QModelIndex &index);
@@ -44,12 +46,12 @@ private:
Ui::OverviewPage *ui;
ClientModel *clientModel;
WalletModel *walletModel;
qint64 currentBalance;
qint64 currentUnconfirmedBalance;
qint64 currentImmatureBalance;
qint64 currentWatchOnlyBalance;
qint64 currentWatchUnconfBalance;
qint64 currentWatchImmatureBalance;
CAmount currentBalance;
CAmount currentUnconfirmedBalance;
CAmount currentImmatureBalance;
CAmount currentWatchOnlyBalance;
CAmount currentWatchUnconfBalance;
CAmount currentWatchImmatureBalance;

TxViewDelegate *txdelegate;
TransactionFilterProxy *filter;

+ 2
- 2
src/qt/paymentrequestplus.cpp View File

@@ -196,9 +196,9 @@ bool PaymentRequestPlus::getMerchant(X509_STORE* certStore, QString& merchant) c
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++)
{
const unsigned char* scriptStr = (const unsigned char*)details.outputs(i).script().data();

+ 1
- 1
src/qt/paymentrequestplus.h View File

@@ -33,7 +33,7 @@ public:
bool getMerchant(X509_STORE* certStore, QString& merchant) const;

// 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; }


+ 2
- 2
src/qt/paymentserver.cpp View File

@@ -532,10 +532,10 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins

request.getMerchant(PaymentServer::certStore, recipient.authenticatedMerchant);

QList<std::pair<CScript, qint64> > sendingTos = request.getPayTo();
QList<std::pair<CScript, CAmount> > sendingTos = request.getPayTo();
QStringList addresses;

foreach(const PAIRTYPE(CScript, qint64)& sendingTo, sendingTos) {
foreach(const PAIRTYPE(CScript, CAmount)& sendingTo, sendingTos) {
// Extract and check destination addresses
CTxDestination dest;
if (ExtractDestination(sendingTo.first, dest)) {

+ 5
- 5
src/qt/sendcoinsdialog.cpp View File

@@ -92,7 +92,7 @@ void SendCoinsDialog::setModel(WalletModel *model)

setBalance(model->getBalance(), model->getUnconfirmedBalance(), model->getImmatureBalance(),
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()));

// Coin Control
@@ -203,7 +203,7 @@ void SendCoinsDialog::on_sendButton_clicked()
return;
}

qint64 txFee = currentTransaction.getTransactionFee();
CAmount txFee = currentTransaction.getTransactionFee();
QString questionString = tr("Are you sure you want to send?");
questionString.append("<br /><br />%1");

@@ -218,7 +218,7 @@ void SendCoinsDialog::on_sendButton_clicked()

// add total amount in all subdivision units
questionString.append("<hr />");
qint64 totalAmount = currentTransaction.getTotalTransactionAmount() + txFee;
CAmount totalAmount = currentTransaction.getTotalTransactionAmount() + txFee;
QStringList alternativeUnits;
foreach(BitcoinUnits::Unit u, BitcoinUnits::availableUnits())
{
@@ -384,8 +384,8 @@ bool SendCoinsDialog::handlePaymentRequest(const SendCoinsRecipient &rv)
return true;
}

void SendCoinsDialog::setBalance(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance,
qint64 watchBalance, qint64 watchUnconfirmedBalance, qint64 watchImmatureBalance)
void SendCoinsDialog::setBalance(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
const CAmount& watchBalance, const CAmount& watchUnconfirmedBalance, const CAmount& watchImmatureBalance)
{
Q_UNUSED(unconfirmedBalance);
Q_UNUSED(immatureBalance);

+ 2
- 2
src/qt/sendcoinsdialog.h View File

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

private:
Ui::SendCoinsDialog *ui;

+ 7
- 7
src/qt/transactiondesc.cpp View File

@@ -56,9 +56,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
strHTML += "<html><font face='verdana, arial, helvetica, sans-serif'>";

int64_t nTime = wtx.GetTxTime();
int64_t nCredit = wtx.GetCredit(ISMINE_ALL);
int64_t nDebit = wtx.GetDebit(ISMINE_ALL);
int64_t nNet = nCredit - nDebit;
CAmount nCredit = wtx.GetCredit(ISMINE_ALL);
CAmount nDebit = wtx.GetDebit(ISMINE_ALL);
CAmount nNet = nCredit - nDebit;

strHTML += "<b>" + tr("Status") + ":</b> " + FormatTxStatus(wtx);
int nRequests = wtx.GetRequestCount();
@@ -132,7 +132,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
//
// Coinbase
//
int64_t nUnmatured = 0;
CAmount nUnmatured = 0;
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
nUnmatured += wallet->GetCredit(txout, ISMINE_ALL);
strHTML += "<b>" + tr("Credit") + ":</b> ";
@@ -206,13 +206,13 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
if (fAllToMe)
{
// Payment to self
int64_t nChange = wtx.GetChange();
int64_t nValue = nCredit - nChange;
CAmount nChange = wtx.GetChange();
CAmount nValue = nCredit - nChange;
strHTML += "<b>" + tr("Total debit") + ":</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)
strHTML += "<b>" + tr("Transaction fee") + ":</b> " + BitcoinUnits::formatHtmlWithUnit(unit, -nTxFee) + "<br>";
}

+ 1
- 1
src/qt/transactionfilterproxy.cpp View File

@@ -78,7 +78,7 @@ void TransactionFilterProxy::setTypeFilter(quint32 modes)
invalidateFilter();
}

void TransactionFilterProxy::setMinAmount(qint64 minimum)
void TransactionFilterProxy::setMinAmount(const CAmount& minimum)
{
this->minAmount = minimum;
invalidateFilter();

+ 4
- 2
src/qt/transactionfilterproxy.h View File

@@ -5,6 +5,8 @@
#ifndef TRANSACTIONFILTERPROXY_H
#define TRANSACTIONFILTERPROXY_H

#include "amount.h"

#include <QDateTime>
#include <QSortFilterProxyModel>

@@ -38,7 +40,7 @@ public:
@note Type filter takes a bit field created with TYPE() or ALL_TYPES
*/
void setTypeFilter(quint32 modes);
void setMinAmount(qint64 minimum);
void setMinAmount(const CAmount& minimum);
void setWatchOnlyFilter(WatchOnlyFilter filter);

/** Set maximum number of rows returned, -1 if unlimited. */
@@ -58,7 +60,7 @@ private:
QString addrPrefix;
quint32 typeFilter;
WatchOnlyFilter watchOnlyFilter;
qint64 minAmount;
CAmount minAmount;
int limitRows;
bool showInactive;
};

+ 6
- 6
src/qt/transactionrecord.cpp View File

@@ -32,9 +32,9 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
{
QList<TransactionRecord> parts;
int64_t nTime = wtx.GetTxTime();
int64_t nCredit = wtx.GetCredit(true);
int64_t nDebit = wtx.GetDebit(ISMINE_ALL);
int64_t nNet = nCredit - nDebit;
CAmount nCredit = wtx.GetCredit(true);
CAmount nDebit = wtx.GetDebit(ISMINE_ALL);
CAmount nNet = nCredit - nDebit;
uint256 hash = wtx.GetHash();
std::map<std::string, std::string> mapValue = wtx.mapValue;

@@ -97,7 +97,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
if (fAllFromMe && fAllToMe)
{
// Payment to self
int64_t nChange = wtx.GetChange();
CAmount nChange = wtx.GetChange();

parts.append(TransactionRecord(hash, nTime, TransactionRecord::SendToSelf, "",
-(nDebit - nChange), nCredit - nChange));
@@ -108,7 +108,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
//
// Debit
//
int64_t nTxFee = nDebit - wtx.GetValueOut();
CAmount nTxFee = nDebit - wtx.GetValueOut();

for (unsigned int nOut = 0; nOut < wtx.vout.size(); nOut++)
{
@@ -138,7 +138,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(const CWallet *
sub.address = mapValue["to"];
}

int64_t nValue = txout.nValue;
CAmount nValue = txout.nValue;
/* Add fee to first output */
if (nTxFee > 0)
{

+ 4
- 3
src/qt/transactionrecord.h View File

@@ -5,6 +5,7 @@
#ifndef TRANSACTIONRECORD_H
#define TRANSACTIONRECORD_H

#include "amount.h"
#include "uint256.h"

#include <QList>
@@ -94,7 +95,7 @@ public:

TransactionRecord(uint256 hash, qint64 time,
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),
idx(0)
{
@@ -111,8 +112,8 @@ public:
qint64 time;
Type type;
std::string address;
qint64 debit;
qint64 credit;
CAmount debit;
CAmount credit;
/**@}*/

/** Subtransaction index, for sort key */

+ 2
- 2
src/qt/transactiontablemodel.cpp View File

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

+ 1
- 1
src/qt/transactionview.cpp View File

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

+ 20
- 20
src/qt/walletmodel.cpp View File

@@ -55,11 +55,11 @@ WalletModel::~WalletModel()
unsubscribeFromCoreSignals();
}

qint64 WalletModel::getBalance(const CCoinControl *coinControl) const
CAmount WalletModel::getBalance(const CCoinControl *coinControl) const
{
if (coinControl)
{
qint64 nBalance = 0;
CAmount nBalance = 0;
std::vector<COutput> vCoins;
wallet->AvailableCoins(vCoins, true, coinControl);
BOOST_FOREACH(const COutput& out, vCoins)
@@ -72,12 +72,12 @@ qint64 WalletModel::getBalance(const CCoinControl *coinControl) const
return wallet->GetBalance();
}

qint64 WalletModel::getUnconfirmedBalance() const
CAmount WalletModel::getUnconfirmedBalance() const
{
return wallet->GetUnconfirmedBalance();
}

qint64 WalletModel::getImmatureBalance() const
CAmount WalletModel::getImmatureBalance() const
{
return wallet->GetImmatureBalance();
}
@@ -87,17 +87,17 @@ bool WalletModel::haveWatchOnly() const
return fHaveWatchOnly;
}

qint64 WalletModel::getWatchBalance() const
CAmount WalletModel::getWatchBalance() const
{
return wallet->GetWatchOnlyBalance();
}

qint64 WalletModel::getWatchUnconfirmedBalance() const
CAmount WalletModel::getWatchUnconfirmedBalance() const
{
return wallet->GetUnconfirmedWatchOnlyBalance();
}

qint64 WalletModel::getWatchImmatureBalance() const
CAmount WalletModel::getWatchImmatureBalance() const
{
return wallet->GetImmatureWatchOnlyBalance();
}
@@ -137,12 +137,12 @@ void WalletModel::pollBalanceChanged()

void WalletModel::checkBalanceChanged()
{
qint64 newBalance = getBalance();
qint64 newUnconfirmedBalance = getUnconfirmedBalance();
qint64 newImmatureBalance = getImmatureBalance();
qint64 newWatchOnlyBalance = 0;
qint64 newWatchUnconfBalance = 0;
qint64 newWatchImmatureBalance = 0;
CAmount newBalance = getBalance();
CAmount newUnconfirmedBalance = getUnconfirmedBalance();
CAmount newImmatureBalance = getImmatureBalance();
CAmount newWatchOnlyBalance = 0;
CAmount newWatchUnconfBalance = 0;
CAmount newWatchImmatureBalance = 0;
if (haveWatchOnly())
{
newWatchOnlyBalance = getWatchBalance();
@@ -194,9 +194,9 @@ bool WalletModel::validateAddress(const QString &address)

WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransaction &transaction, const CCoinControl *coinControl)
{
qint64 total = 0;
CAmount total = 0;
QList<SendCoinsRecipient> recipients = transaction.getRecipients();
std::vector<std::pair<CScript, int64_t> > vecSend;
std::vector<std::pair<CScript, CAmount> > vecSend;

if(recipients.empty())
{
@@ -211,7 +211,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
{
if (rcp.paymentRequest.IsInitialized())
{ // PaymentRequest...
int64_t subtotal = 0;
CAmount subtotal = 0;
const payments::PaymentDetails& details = rcp.paymentRequest.getDetails();
for (int i = 0; i < details.outputs_size(); i++)
{
@@ -220,7 +220,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
subtotal += out.amount();
const unsigned char* scriptStr = (const unsigned char*)out.script().data();
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)
{
@@ -242,7 +242,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
++nAddresses;

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;
}
@@ -252,7 +252,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
return DuplicateAddress;
}

qint64 nBalance = getBalance(coinControl);
CAmount nBalance = getBalance(coinControl);

if(total > nBalance)
{
@@ -263,7 +263,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
LOCK2(cs_main, wallet->cs_wallet);

transaction.newPossibleKeyChange(wallet);
int64_t nFeeRequired = 0;
CAmount nFeeRequired = 0;
std::string strFailReason;

CWalletTx *newTx = transaction.getTransaction();

+ 16
- 16
src/qt/walletmodel.h View File

@@ -37,7 +37,7 @@ class SendCoinsRecipient
{
public:
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) {}

// 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!
QString address;
QString label;
qint64 amount;
CAmount amount;
// If from a payment request, this is used for storing the memo
QString message;

@@ -125,13 +125,13 @@ public:
TransactionTableModel *getTransactionTableModel();
RecentRequestsTableModel *getRecentRequestsTableModel();

qint64 getBalance(const CCoinControl *coinControl = NULL) const;
qint64 getUnconfirmedBalance() const;
qint64 getImmatureBalance() const;
CAmount getBalance(const CCoinControl *coinControl = NULL) const;
CAmount getUnconfirmedBalance() const;
CAmount getImmatureBalance() const;
bool haveWatchOnly() const;
qint64 getWatchBalance() const;
qint64 getWatchUnconfirmedBalance() const;
qint64 getWatchImmatureBalance() const;
CAmount getWatchBalance() const;
CAmount getWatchUnconfirmedBalance() const;
CAmount getWatchImmatureBalance() const;
EncryptionStatus getEncryptionStatus() const;
bool processingQueuedTransactions() { return fProcessingQueuedTransactions; }

@@ -210,12 +210,12 @@ private:
RecentRequestsTableModel *recentRequestsTableModel;

// Cache some values to be able to detect changes
qint64 cachedBalance;
qint64 cachedUnconfirmedBalance;
qint64 cachedImmatureBalance;
qint64 cachedWatchOnlyBalance;
qint64 cachedWatchUnconfBalance;
qint64 cachedWatchImmatureBalance;
CAmount cachedBalance;
CAmount cachedUnconfirmedBalance;
CAmount cachedImmatureBalance;
CAmount cachedWatchOnlyBalance;
CAmount cachedWatchUnconfBalance;
CAmount cachedWatchImmatureBalance;
EncryptionStatus cachedEncryptionStatus;
int cachedNumBlocks;

@@ -227,8 +227,8 @@ private:

signals:
// Signal that balance in wallet changed
void balanceChanged(qint64 balance, qint64 unconfirmedBalance, qint64 immatureBalance,
qint64 watchOnlyBalance, qint64 watchUnconfBalance, qint64 watchImmatureBalance);
void balanceChanged(const CAmount& balance, const CAmount& unconfirmedBalance, const CAmount& immatureBalance,
const CAmount& watchOnlyBalance, const CAmount& watchUnconfBalance, const CAmount& watchImmatureBalance);

// Encryption status of wallet changed
void encryptionStatusChanged(int status);

+ 4
- 4
src/qt/walletmodeltransaction.cpp View File

@@ -31,19 +31,19 @@ CWalletTx *WalletModelTransaction::getTransaction()
return walletTransaction;
}

qint64 WalletModelTransaction::getTransactionFee()
CAmount WalletModelTransaction::getTransactionFee()
{
return fee;
}

void WalletModelTransaction::setTransactionFee(qint64 newFee)
void WalletModelTransaction::setTransactionFee(const CAmount& newFee)
{
fee = newFee;
}

qint64 WalletModelTransaction::getTotalTransactionAmount()
CAmount WalletModelTransaction::getTotalTransactionAmount()
{
qint64 totalTransactionAmount = 0;
CAmount totalTransactionAmount = 0;
foreach(const SendCoinsRecipient &rcp, recipients)
{
totalTransactionAmount += rcp.amount;

+ 4
- 4
src/qt/walletmodeltransaction.h View File

@@ -26,10 +26,10 @@ public:

CWalletTx *getTransaction();

void setTransactionFee(qint64 newFee);
qint64 getTransactionFee();
void setTransactionFee(const CAmount& newFee);
CAmount getTransactionFee();

qint64 getTotalTransactionAmount();
CAmount getTotalTransactionAmount();

void newPossibleKeyChange(CWallet *wallet);
CReserveKey *getPossibleKeyChange();
@@ -38,7 +38,7 @@ private:
const QList<SendCoinsRecipient> recipients;
CWalletTx *walletTransaction;
CReserveKey *keyChange;
qint64 fee;
CAmount fee;
};

#endif // WALLETMODELTRANSACTION_H

+ 1
- 1
src/qt/walletview.cpp View File

@@ -92,7 +92,7 @@ void WalletView::setBitcoinGUI(BitcoinGUI *gui)
connect(this, SIGNAL(encryptionStatusChanged(int)), gui, SLOT(setEncryptionStatus(int)));

// 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)));
}
}


+ 3
- 1
src/qt/walletview.h View File

@@ -5,6 +5,8 @@
#ifndef WALLETVIEW_H
#define WALLETVIEW_H

#include "amount.h"

#include <QStackedWidget>

class BitcoinGUI;
@@ -111,7 +113,7 @@ signals:
/** Encryption status of wallet changed */
void encryptionStatusChanged(int status);
/** 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

+ 1
- 1
src/rpcmining.cpp View File

@@ -273,7 +273,7 @@ Value prioritisetransaction(const Array& params, bool fHelp)
uint256 hash;
hash.SetHex(params[0].get_str());

int64_t nAmount = 0;
CAmount nAmount = 0;
if (params[2].get_real() != 0.0)
nAmount = AmountFromValue(params[2]);


+ 2
- 2
src/rpcrawtransaction.cpp View File

@@ -269,7 +269,7 @@ Value listunspent(const Array& params, bool fHelp)
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;
Object entry;
entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
@@ -367,7 +367,7 @@ Value createrawtransaction(const Array& params, bool fHelp)
setAddress.insert(address);

CScript scriptPubKey = GetScriptForDestination(address.Get());
int64_t nAmount = AmountFromValue(s.value_);
CAmount nAmount = AmountFromValue(s.value_);

CTxOut out(nAmount, scriptPubKey);
rawTx.vout.push_back(out);

+ 3
- 3
src/rpcserver.cpp View File

@@ -88,18 +88,18 @@ static inline int64_t roundint64(double d)
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();
if (dAmount <= 0.0 || dAmount > 21000000.0)
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
int64_t nAmount = roundint64(dAmount * COIN);
CAmount nAmount = roundint64(dAmount * COIN);
if (!MoneyRange(nAmount))
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
return nAmount;
}

Value ValueFromAmount(int64_t amount)
Value ValueFromAmount(const CAmount& amount)
{
return (double)amount / (double)COIN;
}

+ 3
- 2
src/rpcserver.h View File

@@ -6,6 +6,7 @@
#ifndef _BITCOINRPC_SERVER_H_
#define _BITCOINRPC_SERVER_H_

#include "amount.h"
#include "uint256.h"
#include "rpcprotocol.h"

@@ -116,8 +117,8 @@ extern void InitRPCMining();
extern void ShutdownRPCMining();

extern int64_t nWalletUnlockTime;
extern int64_t AmountFromValue(const json_spirit::Value& value);
extern json_spirit::Value ValueFromAmount(int64_t amount);
extern CAmount AmountFromValue(const json_spirit::Value& value);
extern json_spirit::Value ValueFromAmount(const CAmount& amount);
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
extern std::string HelpRequiringPassphrase();
extern std::string HelpExampleCli(std::string methodname, std::string args);

+ 31
- 31
src/rpcwallet.cpp View File

@@ -331,7 +331,7 @@ Value sendtoaddress(const Array& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");

// Amount
int64_t nAmount = AmountFromValue(params[1]);
CAmount nAmount = AmountFromValue(params[1]);

// Wallet comments
CWalletTx wtx;
@@ -375,7 +375,7 @@ Value listaddressgroupings(const Array& params, bool fHelp)
);

Array jsonGroupings;
map<CTxDestination, int64_t> balances = pwalletMain->GetAddressBalances();
map<CTxDestination, CAmount> balances = pwalletMain->GetAddressBalances();
BOOST_FOREACH(set<CTxDestination> grouping, pwalletMain->GetAddressGroupings())
{
Array jsonGrouping;
@@ -483,7 +483,7 @@ Value getreceivedbyaddress(const Array& params, bool fHelp)
nMinDepth = params[1].get_int();

// Tally
int64_t nAmount = 0;
CAmount nAmount = 0;
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
@@ -532,7 +532,7 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
set<CTxDestination> setAddress = pwalletMain->GetAccountAddresses(strAccount);

// Tally
int64_t nAmount = 0;
CAmount nAmount = 0;
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
@@ -552,9 +552,9 @@ Value getreceivedbyaccount(const Array& params, bool fHelp)
}


int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter)
CAmount GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth, const isminefilter& filter)
{
int64_t nBalance = 0;
CAmount nBalance = 0;

// Tally wallet transactions
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
@@ -563,7 +563,7 @@ int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi
if (!IsFinalTx(wtx) || wtx.GetBlocksToMaturity() > 0 || wtx.GetDepthInMainChain() < 0)
continue;

int64_t nReceived, nSent, nFee;
CAmount nReceived, nSent, nFee;
wtx.GetAccountAmounts(strAccount, nReceived, nSent, nFee, filter);

if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)
@@ -577,7 +577,7 @@ int64_t GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMi
return nBalance;
}

int64_t GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter)
CAmount GetAccountBalance(const string& strAccount, int nMinDepth, const isminefilter& filter)
{
CWalletDB walletdb(pwalletMain->strWalletFile);
return GetAccountBalance(walletdb, strAccount, nMinDepth, filter);
@@ -627,14 +627,14 @@ Value getbalance(const Array& params, bool fHelp)
// Calculate total balance a different way from GetBalance()
// (GetBalance() sums up all unspent TxOuts)
// getbalance and getbalance '*' 0 should return the same number
int64_t nBalance = 0;
CAmount nBalance = 0;
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
if (!wtx.IsTrusted() || wtx.GetBlocksToMaturity() > 0)
continue;

int64_t allFee;
CAmount allFee;
string strSentAccount;
list<COutputEntry> listReceived;
list<COutputEntry> listSent;
@@ -653,7 +653,7 @@ Value getbalance(const Array& params, bool fHelp)

string strAccount = AccountFromValue(params[0]);

int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, filter);
CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, filter);

return ValueFromAmount(nBalance);
}
@@ -692,7 +692,7 @@ Value movecmd(const Array& params, bool fHelp)

string strFrom = AccountFromValue(params[0]);
string strTo = AccountFromValue(params[1]);
int64_t nAmount = AmountFromValue(params[2]);
CAmount nAmount = AmountFromValue(params[2]);
if (params.size() > 3)
// unused parameter, used to be nMinDepth, keep type-checking it though
(void)params[3].get_int();
@@ -766,7 +766,7 @@ Value sendfrom(const Array& params, bool fHelp)
CBitcoinAddress address(params[1].get_str());
if (!address.IsValid())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
int64_t nAmount = AmountFromValue(params[2]);
CAmount nAmount = AmountFromValue(params[2]);
int nMinDepth = 1;
if (params.size() > 3)
nMinDepth = params[3].get_int();
@@ -781,7 +781,7 @@ Value sendfrom(const Array& params, bool fHelp)
EnsureWalletIsUnlocked();

// Check funds
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
if (nAmount > nBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");

@@ -834,9 +834,9 @@ Value sendmany(const Array& params, bool fHelp)
wtx.mapValue["comment"] = params[3].get_str();

set<CBitcoinAddress> setAddress;
vector<pair<CScript, int64_t> > vecSend;
vector<pair<CScript, CAmount> > vecSend;

int64_t totalAmount = 0;
CAmount totalAmount = 0;
BOOST_FOREACH(const Pair& s, sendTo)
{
CBitcoinAddress address(s.name_);
@@ -848,7 +848,7 @@ Value sendmany(const Array& params, bool fHelp)
setAddress.insert(address);

CScript scriptPubKey = GetScriptForDestination(address.Get());
int64_t nAmount = AmountFromValue(s.value_);
CAmount nAmount = AmountFromValue(s.value_);
totalAmount += nAmount;

vecSend.push_back(make_pair(scriptPubKey, nAmount));
@@ -857,13 +857,13 @@ Value sendmany(const Array& params, bool fHelp)
EnsureWalletIsUnlocked();

// Check funds
int64_t nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
CAmount nBalance = GetAccountBalance(strAccount, nMinDepth, ISMINE_SPENDABLE);
if (totalAmount > nBalance)
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Account has insufficient funds");

// Send
CReserveKey keyChange(pwalletMain);
int64_t nFeeRequired = 0;
CAmount nFeeRequired = 0;
string strFailReason;
bool fCreated = pwalletMain->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason);
if (!fCreated)
@@ -923,7 +923,7 @@ Value addmultisigaddress(const Array& params, bool fHelp)

struct tallyitem
{
int64_t nAmount;
CAmount nAmount;
int nConf;
vector<uint256> txids;
bool fIsWatchonly;
@@ -995,7 +995,7 @@ Value ListReceived(const Array& params, bool fByAccounts)
if (it == mapTally.end() && !fIncludeEmpty)
continue;

int64_t nAmount = 0;
CAmount nAmount = 0;
int nConf = std::numeric_limits<int>::max();
bool fIsWatchonly = false;
if (it != mapTally.end())
@@ -1038,7 +1038,7 @@ Value ListReceived(const Array& params, bool fByAccounts)
{
for (map<string, tallyitem>::iterator it = mapAccountTally.begin(); it != mapAccountTally.end(); ++it)
{
int64_t nAmount = (*it).second.nAmount;
CAmount nAmount = (*it).second.nAmount;
int nConf = (*it).second.nConf;
Object obj;
if((*it).second.fIsWatchonly)
@@ -1125,7 +1125,7 @@ static void MaybePushAddress(Object & entry, const CTxDestination &dest)

void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDepth, bool fLong, Array& ret, const isminefilter& filter)
{
int64_t nFee;
CAmount nFee;
string strSentAccount;
list<COutputEntry> listReceived;
list<COutputEntry> listSent;
@@ -1355,7 +1355,7 @@ Value listaccounts(const Array& params, bool fHelp)
if(params[1].get_bool())
includeWatchonly = includeWatchonly | ISMINE_WATCH_ONLY;

map<string, int64_t> mapAccountBalances;
map<string, CAmount> mapAccountBalances;
BOOST_FOREACH(const PAIRTYPE(CTxDestination, CAddressBookData)& entry, pwalletMain->mapAddressBook) {
if (IsMine(*pwalletMain, entry.first) & includeWatchonly) // This address belongs to me
mapAccountBalances[entry.second.name] = 0;
@@ -1364,7 +1364,7 @@ Value listaccounts(const Array& params, bool fHelp)
for (map<uint256, CWalletTx>::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it)
{
const CWalletTx& wtx = (*it).second;
int64_t nFee;
CAmount nFee;
string strSentAccount;
list<COutputEntry> listReceived;
list<COutputEntry> listSent;
@@ -1391,7 +1391,7 @@ Value listaccounts(const Array& params, bool fHelp)
mapAccountBalances[entry.strAccount] += entry.nCreditDebit;

Object ret;
BOOST_FOREACH(const PAIRTYPE(string, int64_t)& accountBalance, mapAccountBalances) {
BOOST_FOREACH(const PAIRTYPE(string, CAmount)& accountBalance, mapAccountBalances) {
ret.push_back(Pair(accountBalance.first, ValueFromAmount(accountBalance.second)));
}
return ret;
@@ -1534,10 +1534,10 @@ Value gettransaction(const Array& params, bool fHelp)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
const CWalletTx& wtx = pwalletMain->mapWallet[hash];

int64_t nCredit = wtx.GetCredit(filter != 0);
int64_t nDebit = wtx.GetDebit(filter);
int64_t nNet = nCredit - nDebit;
int64_t nFee = (wtx.IsFromMe(filter) ? wtx.GetValueOut() - nDebit : 0);
CAmount nCredit = wtx.GetCredit(filter != 0);
CAmount nDebit = wtx.GetDebit(filter);
CAmount nNet = nCredit - nDebit;
CAmount nFee = (wtx.IsFromMe(filter) ? wtx.GetValueOut() - nDebit : 0);

entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));
if (wtx.IsFromMe(filter))
@@ -1937,7 +1937,7 @@ Value settxfee(const Array& params, bool fHelp)
);

// Amount
int64_t nAmount = 0;
CAmount nAmount = 0;
if (params[0].get_real() != 0.0)
nAmount = AmountFromValue(params[0]); // rejects 0.0 amounts


+ 2
- 2
src/test/accounting_tests.cpp View File

@@ -15,7 +15,7 @@ extern CWallet* pwalletMain;
BOOST_AUTO_TEST_SUITE(accounting_tests)

static void
GetResults(CWalletDB& walletdb, std::map<int64_t, CAccountingEntry>& results)
GetResults(CWalletDB& walletdb, std::map<CAmount, CAccountingEntry>& results)
{
std::list<CAccountingEntry> aes;

@@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE(acc_orderupgrade)
std::vector<CWalletTx*> vpwtx;
CWalletTx wtx;
CAccountingEntry ae;
std::map<int64_t, CAccountingEntry> results;
std::map<CAmount, CAccountingEntry> results;

LOCK(pwalletMain->cs_wallet);


+ 2
- 2
src/test/main_tests.cpp View File

@@ -11,9 +11,9 @@ BOOST_AUTO_TEST_SUITE(main_tests)

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

+ 1
- 1
src/test/util_tests.cpp View File

@@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE(util_FormatMoney)

BOOST_AUTO_TEST_CASE(util_ParseMoney)
{
int64_t ret = 0;
CAmount ret = 0;
BOOST_CHECK(ParseMoney("0.0", ret));
BOOST_CHECK_EQUAL(ret, 0);


+ 2
- 2
src/test/wallet_tests.cpp View File

@@ -28,7 +28,7 @@ BOOST_AUTO_TEST_SUITE(wallet_tests)
static CWallet wallet;
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;
CMutableTransaction tx;
@@ -66,7 +66,7 @@ static bool equal_sets(CoinSet a, CoinSet b)
BOOST_AUTO_TEST_CASE(coin_selection_tests)
{
CoinSet setCoinsRet, setCoinsRet2;
int64_t nValueRet;
CAmount nValueRet;

LOCK(wallet.cs_wallet);


+ 1
- 1
src/txdb.cpp View File

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

+ 9
- 8
src/txmempool.cpp View File

@@ -7,6 +7,7 @@

#include "core.h"
#include "util.h"
#include "utilmoneystr.h"

#include <boost/circular_buffer.hpp>

@@ -18,7 +19,7 @@ CTxMemPoolEntry::CTxMemPoolEntry():
nHeight = MEMPOOL_HEIGHT;
}

CTxMemPoolEntry::CTxMemPoolEntry(const CTransaction& _tx, int64_t _nFee,
CTxMemPoolEntry::CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
int64_t _nTime, double _dPriority,
unsigned int _nHeight):
tx(_tx), nFee(_nFee), nTime(_nTime), dPriority(_dPriority), nHeight(_nHeight)
@@ -36,7 +37,7 @@ CTxMemPoolEntry::CTxMemPoolEntry(const CTxMemPoolEntry& other)
double
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 dResult = dPriority + deltaPriority;
return dResult;
@@ -601,24 +602,24 @@ CTxMemPool::ReadFeeEstimates(CAutoFile& filein)
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);
std::pair<double, int64_t> &deltas = mapDeltas[hash];
std::pair<double, CAmount> &deltas = mapDeltas[hash];
deltas.first += dPriorityDelta;
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);
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())
return;
const std::pair<double, int64_t> &deltas = pos->second;
const std::pair<double, CAmount> &deltas = pos->second;
dPriorityDelta += deltas.first;
nFeeDelta += deltas.second;
}

+ 6
- 6
src/txmempool.h View File

@@ -29,7 +29,7 @@ class CTxMemPoolEntry
{
private:
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 nModSize; // ... and modified size for priority
int64_t nTime; // Local time when entering the mempool
@@ -37,14 +37,14 @@ private:
unsigned int nHeight; // Chain height when entering the mempool

public:
CTxMemPoolEntry(const CTransaction& _tx, int64_t _nFee,
CTxMemPoolEntry(const CTransaction& _tx, const CAmount& _nFee,
int64_t _nTime, double _dPriority, unsigned int _nHeight);
CTxMemPoolEntry();
CTxMemPoolEntry(const CTxMemPoolEntry& other);

const CTransaction& GetTx() const { return this->tx; }
double GetPriority(unsigned int currentHeight) const;
int64_t GetFee() const { return nFee; }
CAmount GetFee() const { return nFee; }
size_t GetTxSize() const { return nTxSize; }
int64_t GetTime() const { return nTime; }
unsigned int GetHeight() const { return nHeight; }
@@ -76,7 +76,7 @@ public:
mutable CCriticalSection cs;
std::map<uint256, CTxMemPoolEntry> mapTx;
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();
@@ -102,8 +102,8 @@ public:
void AddTransactionsUpdated(unsigned int n);

/** Affect CreateNewBlock prioritisation of transactions */
void PrioritiseTransaction(const uint256 hash, const std::string strHash, double dPriorityDelta, int64_t nFeeDelta);
void ApplyDeltas(const uint256 hash, 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, CAmount &nFeeDelta);
void ClearPrioritisation(const uint256 hash);

unsigned long size()

+ 1
- 0
src/util.h View File

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

#include "amount.h"
#include "compat.h"
#include "tinyformat.h"
#include "utiltime.h"

+ 4
- 4
src/utilmoneystr.cpp View File

@@ -10,7 +10,7 @@

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
// 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);
}

bool ParseMoney(const char* pszIn, int64_t& nRet)
bool ParseMoney(const char* pszIn, CAmount& nRet)
{
string strWhole;
int64_t nUnits = 0;
@@ -73,7 +73,7 @@ bool ParseMoney(const char* pszIn, int64_t& nRet)
if (nUnits < 0 || nUnits > COIN)
return false;
int64_t nWhole = atoi64(strWhole);
int64_t nValue = nWhole*COIN + nUnits;
CAmount nValue = nWhole*COIN + nUnits;

nRet = nValue;
return true;

+ 5
- 3
src/utilmoneystr.h View File

@@ -12,8 +12,10 @@
#include <stdint.h>
#include <string>

std::string FormatMoney(int64_t n, bool fPlus=false);
bool ParseMoney(const std::string& str, int64_t& nRet);
bool ParseMoney(const char* pszIn, int64_t& nRet);
#include "amount.h"

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

+ 54
- 54
src/wallet.cpp View File

@@ -35,8 +35,8 @@ CFeeRate CWallet::minTxFee = CFeeRate(10000); // Override with -mintxfee

struct CompareValueOnly
{
bool operator()(const pair<int64_t, pair<const CWalletTx*, unsigned int> >& t1,
const pair<int64_t, pair<const CWalletTx*, unsigned int> >& t2) const
bool operator()(const pair<CAmount, pair<const CWalletTx*, unsigned int> >& t1,
const pair<CAmount, pair<const CWalletTx*, unsigned int> >& t2) const
{
return t1.first < t2.first;
}
@@ -697,7 +697,7 @@ isminetype CWallet::IsMine(const CTxIn &txin) const
return ISMINE_NO;
}

int64_t CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const
CAmount CWallet::GetDebit(const CTxIn &txin, const isminefilter& filter) const