mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
Use a typedef for monetary values
This commit is contained in:
parent
64cfaf891f
commit
a372168e77
@ -65,6 +65,7 @@ BITCOIN_CORE_H = \
|
||||
addrman.h \
|
||||
alert.h \
|
||||
allocators.h \
|
||||
amount.h \
|
||||
base58.h \
|
||||
bloom.h \
|
||||
chainparams.h \
|
||||
|
13
src/amount.h
Normal file
13
src/amount.h
Normal 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
|
@ -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");
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
12
src/core.cpp
12
src/core.cpp
@ -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;
|
||||
|
21
src/core.h
21
src/core.h
@ -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.
|
||||
|
||||
|
@ -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)
|
||||
|
26
src/main.cpp
26
src/main.cpp
@ -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()));
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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"),
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
@ -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()));
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -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)) {
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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>";
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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 */
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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]);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "config/bitcoin-config.h"
|
||||
#endif
|
||||
|
||||
#include "amount.h"
|
||||
#include "compat.h"
|
||||
#include "tinyformat.h"
|
||||
#include "utiltime.h"
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
108
src/wallet.cpp
108
src/wallet.cpp
@ -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
|
||||
{
|
||||
{
|
||||
LOCK(cs_wallet);
|
||||
@ -781,7 +781,7 @@ int CWalletTx::GetRequestCount() const
|
||||
}
|
||||
|
||||
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;
|
||||
listReceived.clear();
|
||||
@ -789,10 +789,10 @@ void CWalletTx::GetAmounts(list<COutputEntry>& listReceived,
|
||||
strSentAccount = strFromAccount;
|
||||
|
||||
// Compute fee:
|
||||
int64_t nDebit = GetDebit(filter);
|
||||
CAmount nDebit = GetDebit(filter);
|
||||
if (nDebit > 0) // debit>0 means we signed/sent this transaction
|
||||
{
|
||||
int64_t nValueOut = GetValueOut();
|
||||
CAmount nValueOut = GetValueOut();
|
||||
nFee = nDebit - nValueOut;
|
||||
}
|
||||
|
||||
@ -835,12 +835,12 @@ void CWalletTx::GetAmounts(list<COutputEntry>& listReceived,
|
||||
|
||||
}
|
||||
|
||||
void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nReceived,
|
||||
int64_t& nSent, int64_t& nFee, const isminefilter& filter) const
|
||||
void CWalletTx::GetAccountAmounts(const string& strAccount, CAmount& nReceived,
|
||||
CAmount& nSent, CAmount& nFee, const isminefilter& filter) const
|
||||
{
|
||||
nReceived = nSent = nFee = 0;
|
||||
|
||||
int64_t allFee;
|
||||
CAmount allFee;
|
||||
string strSentAccount;
|
||||
list<COutputEntry> listReceived;
|
||||
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);
|
||||
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
|
||||
@ -1027,9 +1027,9 @@ int64_t CWallet::GetBalance() const
|
||||
return nTotal;
|
||||
}
|
||||
|
||||
int64_t CWallet::GetUnconfirmedBalance() const
|
||||
CAmount CWallet::GetUnconfirmedBalance() const
|
||||
{
|
||||
int64_t nTotal = 0;
|
||||
CAmount nTotal = 0;
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
|
||||
@ -1042,9 +1042,9 @@ int64_t CWallet::GetUnconfirmedBalance() const
|
||||
return nTotal;
|
||||
}
|
||||
|
||||
int64_t CWallet::GetImmatureBalance() const
|
||||
CAmount CWallet::GetImmatureBalance() const
|
||||
{
|
||||
int64_t nTotal = 0;
|
||||
CAmount nTotal = 0;
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
|
||||
@ -1056,9 +1056,9 @@ int64_t CWallet::GetImmatureBalance() const
|
||||
return nTotal;
|
||||
}
|
||||
|
||||
int64_t CWallet::GetWatchOnlyBalance() const
|
||||
CAmount CWallet::GetWatchOnlyBalance() const
|
||||
{
|
||||
int64_t nTotal = 0;
|
||||
CAmount nTotal = 0;
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
|
||||
@ -1072,9 +1072,9 @@ int64_t CWallet::GetWatchOnlyBalance() const
|
||||
return nTotal;
|
||||
}
|
||||
|
||||
int64_t CWallet::GetUnconfirmedWatchOnlyBalance() const
|
||||
CAmount CWallet::GetUnconfirmedWatchOnlyBalance() const
|
||||
{
|
||||
int64_t nTotal = 0;
|
||||
CAmount nTotal = 0;
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
for (map<uint256, CWalletTx>::const_iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)
|
||||
@ -1087,9 +1087,9 @@ int64_t CWallet::GetUnconfirmedWatchOnlyBalance() const
|
||||
return nTotal;
|
||||
}
|
||||
|
||||
int64_t CWallet::GetImmatureWatchOnlyBalance() const
|
||||
CAmount CWallet::GetImmatureWatchOnlyBalance() const
|
||||
{
|
||||
int64_t nTotal = 0;
|
||||
CAmount nTotal = 0;
|
||||
{
|
||||
LOCK2(cs_main, cs_wallet);
|
||||
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,
|
||||
vector<char>& vfBest, int64_t& nBest, int iterations = 1000)
|
||||
static void ApproximateBestSubset(vector<pair<CAmount, pair<const CWalletTx*,unsigned int> > >vValue, const CAmount& nTotalLower, const CAmount& nTargetValue,
|
||||
vector<char>& vfBest, CAmount& nBest, int iterations = 1000)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
vfIncluded.assign(vValue.size(), false);
|
||||
int64_t nTotal = 0;
|
||||
CAmount nTotal = 0;
|
||||
bool fReachedTarget = false;
|
||||
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,
|
||||
set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, int64_t& nValueRet) const
|
||||
bool CWallet::SelectCoinsMinConf(const CAmount& nTargetValue, int nConfMine, int nConfTheirs, vector<COutput> vCoins,
|
||||
set<pair<const CWalletTx*,unsigned int> >& setCoinsRet, CAmount& nValueRet) const
|
||||
{
|
||||
setCoinsRet.clear();
|
||||
nValueRet = 0;
|
||||
|
||||
// List of values less than target
|
||||
pair<int64_t, pair<const CWalletTx*,unsigned int> > coinLowestLarger;
|
||||
coinLowestLarger.first = std::numeric_limits<int64_t>::max();
|
||||
pair<CAmount, pair<const CWalletTx*,unsigned int> > coinLowestLarger;
|
||||
coinLowestLarger.first = std::numeric_limits<CAmount>::max();
|
||||
coinLowestLarger.second.first = NULL;
|
||||
vector<pair<int64_t, pair<const CWalletTx*,unsigned int> > > vValue;
|
||||
int64_t nTotalLower = 0;
|
||||
vector<pair<CAmount, pair<const CWalletTx*,unsigned int> > > vValue;
|
||||
CAmount nTotalLower = 0;
|
||||
|
||||
random_shuffle(vCoins.begin(), vCoins.end(), GetRandInt);
|
||||
|
||||
@ -1209,9 +1209,9 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfT
|
||||
continue;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -1252,7 +1252,7 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfT
|
||||
// Solve subset sum by stochastic approximation
|
||||
sort(vValue.rbegin(), vValue.rend(), CompareValueOnly());
|
||||
vector<char> vfBest;
|
||||
int64_t nBest;
|
||||
CAmount nBest;
|
||||
|
||||
ApproximateBestSubset(vValue, nTotalLower, nTargetValue, vfBest, nBest, 1000);
|
||||
if (nBest != nTargetValue && nTotalLower >= nTargetValue + CENT)
|
||||
@ -1284,7 +1284,7 @@ bool CWallet::SelectCoinsMinConf(int64_t nTargetValue, int nConfMine, int nConfT
|
||||
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;
|
||||
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,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl)
|
||||
bool CWallet::CreateTransaction(const vector<pair<CScript, CAmount> >& vecSend,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl)
|
||||
{
|
||||
int64_t nValue = 0;
|
||||
BOOST_FOREACH (const PAIRTYPE(CScript, int64_t)& s, vecSend)
|
||||
CAmount nValue = 0;
|
||||
BOOST_FOREACH (const PAIRTYPE(CScript, CAmount)& s, vecSend)
|
||||
{
|
||||
if (nValue < 0)
|
||||
{
|
||||
@ -1343,10 +1343,10 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
|
||||
txNew.vout.clear();
|
||||
wtxNew.fFromMe = true;
|
||||
|
||||
int64_t nTotalValue = nValue + nFeeRet;
|
||||
CAmount nTotalValue = nValue + nFeeRet;
|
||||
double dPriority = 0;
|
||||
// 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);
|
||||
if (txout.IsDust(::minRelayTxFee))
|
||||
@ -1359,7 +1359,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
|
||||
|
||||
// Choose coins to use
|
||||
set<pair<const CWalletTx*,unsigned int> > setCoins;
|
||||
int64_t nValueIn = 0;
|
||||
CAmount nValueIn = 0;
|
||||
if (!SelectCoins(nTotalValue, setCoins, nValueIn, coinControl))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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,
|
||||
//reflecting an assumption the user would accept a bit more delay for
|
||||
//a chance at a free transaction.
|
||||
dPriority += (double)nCredit * (pcoin.first->GetDepthInMainChain()+1);
|
||||
}
|
||||
|
||||
int64_t nChange = nValueIn - nValue - nFeeRet;
|
||||
CAmount nChange = nValueIn - nValue - nFeeRet;
|
||||
|
||||
if (nChange > 0)
|
||||
{
|
||||
@ -1450,7 +1450,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
|
||||
}
|
||||
dPriority = wtxNew.ComputePriority(dPriority, nBytes);
|
||||
|
||||
int64_t nFeeNeeded = GetMinimumFee(nBytes, nTxConfirmTarget, mempool);
|
||||
CAmount nFeeNeeded = GetMinimumFee(nBytes, nTxConfirmTarget, mempool);
|
||||
|
||||
if (nFeeRet >= nFeeNeeded)
|
||||
break; // Done, enough fee included.
|
||||
@ -1481,10 +1481,10 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CWallet::CreateTransaction(CScript scriptPubKey, int64_t nValue,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl* coinControl)
|
||||
bool CWallet::CreateTransaction(CScript scriptPubKey, const CAmount& nValue,
|
||||
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));
|
||||
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
|
||||
if (nValue <= 0)
|
||||
@ -1560,7 +1560,7 @@ string CWallet::SendMoney(const CTxDestination &address, int64_t nValue, CWallet
|
||||
|
||||
// Create and send the transaction
|
||||
CReserveKey reservekey(this);
|
||||
int64_t nFeeRequired;
|
||||
CAmount nFeeRequired;
|
||||
if (!CreateTransaction(scriptPubKey, nValue, wtxNew, reservekey, nFeeRequired, strError))
|
||||
{
|
||||
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"
|
||||
int64_t nFeeNeeded = payTxFee.GetFee(nTxBytes);
|
||||
CAmount nFeeNeeded = payTxFee.GetFee(nTxBytes);
|
||||
// User didn't set: use -txconfirmtarget to estimate...
|
||||
if (nFeeNeeded == 0)
|
||||
nFeeNeeded = pool.estimateFee(nConfirmTarget).GetFee(nTxBytes);
|
||||
@ -1838,9 +1838,9 @@ int64_t CWallet::GetOldestKeyPoolTime()
|
||||
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);
|
||||
@ -1866,7 +1866,7 @@ std::map<CTxDestination, int64_t> CWallet::GetAddressBalances()
|
||||
if(!ExtractDestination(pcoin->vout[i].scriptPubKey, addr))
|
||||
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))
|
||||
balances[addr] = 0;
|
||||
|
100
src/wallet.h
100
src/wallet.h
@ -30,9 +30,9 @@ extern unsigned int nTxConfirmTarget;
|
||||
extern bool bSpendZeroConfChange;
|
||||
|
||||
// -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
|
||||
static const int nHighTransactionFeeWarning = 0.01 * COIN;
|
||||
static const CAmount nHighTransactionFeeWarning = 0.01 * COIN;
|
||||
// Largest (in bytes) free transaction we're willing to create
|
||||
static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000;
|
||||
|
||||
@ -98,7 +98,7 @@ public:
|
||||
class CWallet : public CCryptoKeyStore, public CWalletInterface
|
||||
{
|
||||
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;
|
||||
|
||||
@ -182,7 +182,7 @@ public:
|
||||
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;
|
||||
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;
|
||||
|
||||
@ -253,21 +253,21 @@ public:
|
||||
int ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate = false);
|
||||
void ReacceptWalletTransactions();
|
||||
void ResendWalletTransactions();
|
||||
int64_t GetBalance() const;
|
||||
int64_t GetUnconfirmedBalance() const;
|
||||
int64_t GetImmatureBalance() const;
|
||||
int64_t GetWatchOnlyBalance() const;
|
||||
int64_t GetUnconfirmedWatchOnlyBalance() const;
|
||||
int64_t GetImmatureWatchOnlyBalance() const;
|
||||
bool CreateTransaction(const std::vector<std::pair<CScript, int64_t> >& vecSend,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
|
||||
bool CreateTransaction(CScript scriptPubKey, int64_t nValue,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, int64_t& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
|
||||
CAmount GetBalance() const;
|
||||
CAmount GetUnconfirmedBalance() const;
|
||||
CAmount GetImmatureBalance() const;
|
||||
CAmount GetWatchOnlyBalance() const;
|
||||
CAmount GetUnconfirmedWatchOnlyBalance() const;
|
||||
CAmount GetImmatureWatchOnlyBalance() const;
|
||||
bool CreateTransaction(const std::vector<std::pair<CScript, CAmount> >& vecSend,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
|
||||
bool CreateTransaction(CScript scriptPubKey, const CAmount& nValue,
|
||||
CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, std::string& strFailReason, const CCoinControl *coinControl = NULL);
|
||||
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 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 TopUpKeyPool(unsigned int kpSize = 0);
|
||||
@ -279,24 +279,24 @@ public:
|
||||
void GetAllReserveKeys(std::set<CKeyID>& setAddress) const;
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
{
|
||||
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))
|
||||
throw std::runtime_error("CWallet::GetCredit() : value out of range");
|
||||
return ((IsMine(txout) & filter) ? txout.nValue : 0);
|
||||
}
|
||||
bool IsChange(const CTxOut& txout) const;
|
||||
int64_t GetChange(const CTxOut& txout) const
|
||||
CAmount GetChange(const CTxOut& txout) const
|
||||
{
|
||||
if (!MoneyRange(txout.nValue))
|
||||
throw std::runtime_error("CWallet::GetChange() : value out of range");
|
||||
@ -313,9 +313,9 @@ public:
|
||||
{
|
||||
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)
|
||||
{
|
||||
nDebit += GetDebit(txin, filter);
|
||||
@ -324,9 +324,9 @@ public:
|
||||
}
|
||||
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)
|
||||
{
|
||||
nCredit += GetCredit(txout, filter);
|
||||
@ -335,9 +335,9 @@ public:
|
||||
}
|
||||
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)
|
||||
{
|
||||
nChange += GetChange(txout);
|
||||
@ -457,7 +457,7 @@ static void WriteOrderPos(const int64_t& nOrderPos, mapValue_t& mapValue)
|
||||
struct COutputEntry
|
||||
{
|
||||
CTxDestination destination;
|
||||
int64_t amount;
|
||||
CAmount amount;
|
||||
int vout;
|
||||
};
|
||||
|
||||
@ -545,15 +545,15 @@ public:
|
||||
mutable bool fImmatureWatchCreditCached;
|
||||
mutable bool fAvailableWatchCreditCached;
|
||||
mutable bool fChangeCached;
|
||||
mutable int64_t nDebitCached;
|
||||
mutable int64_t nCreditCached;
|
||||
mutable int64_t nImmatureCreditCached;
|
||||
mutable int64_t nAvailableCreditCached;
|
||||
mutable int64_t nWatchDebitCached;
|
||||
mutable int64_t nWatchCreditCached;
|
||||
mutable int64_t nImmatureWatchCreditCached;
|
||||
mutable int64_t nAvailableWatchCreditCached;
|
||||
mutable int64_t nChangeCached;
|
||||
mutable CAmount nDebitCached;
|
||||
mutable CAmount nCreditCached;
|
||||
mutable CAmount nImmatureCreditCached;
|
||||
mutable CAmount nAvailableCreditCached;
|
||||
mutable CAmount nWatchDebitCached;
|
||||
mutable CAmount nWatchCreditCached;
|
||||
mutable CAmount nImmatureWatchCreditCached;
|
||||
mutable CAmount nAvailableWatchCreditCached;
|
||||
mutable CAmount nChangeCached;
|
||||
|
||||
CWalletTx()
|
||||
{
|
||||
@ -670,12 +670,12 @@ public:
|
||||
}
|
||||
|
||||
// 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())
|
||||
return 0;
|
||||
|
||||
int64_t debit = 0;
|
||||
CAmount debit = 0;
|
||||
if(filter & ISMINE_SPENDABLE)
|
||||
{
|
||||
if (fDebitCached)
|
||||
@ -701,7 +701,7 @@ public:
|
||||
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
|
||||
if (IsCoinBase() && GetBlocksToMaturity() > 0)
|
||||
@ -715,7 +715,7 @@ public:
|
||||
return nCreditCached;
|
||||
}
|
||||
|
||||
int64_t GetImmatureCredit(bool fUseCache=true) const
|
||||
CAmount GetImmatureCredit(bool fUseCache=true) const
|
||||
{
|
||||
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
|
||||
{
|
||||
@ -729,7 +729,7 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t GetAvailableCredit(bool fUseCache=true) const
|
||||
CAmount GetAvailableCredit(bool fUseCache=true) const
|
||||
{
|
||||
if (pwallet == 0)
|
||||
return 0;
|
||||
@ -741,7 +741,7 @@ public:
|
||||
if (fUseCache && fAvailableCreditCached)
|
||||
return nAvailableCreditCached;
|
||||
|
||||
int64_t nCredit = 0;
|
||||
CAmount nCredit = 0;
|
||||
uint256 hashTx = GetHash();
|
||||
for (unsigned int i = 0; i < vout.size(); i++)
|
||||
{
|
||||
@ -759,7 +759,7 @@ public:
|
||||
return nCredit;
|
||||
}
|
||||
|
||||
int64_t GetImmatureWatchOnlyCredit(const bool& fUseCache=true) const
|
||||
CAmount GetImmatureWatchOnlyCredit(const bool& fUseCache=true) const
|
||||
{
|
||||
if (IsCoinBase() && GetBlocksToMaturity() > 0 && IsInMainChain())
|
||||
{
|
||||
@ -773,7 +773,7 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t GetAvailableWatchOnlyCredit(const bool& fUseCache=true) const
|
||||
CAmount GetAvailableWatchOnlyCredit(const bool& fUseCache=true) const
|
||||
{
|
||||
if (pwallet == 0)
|
||||
return 0;
|
||||
@ -785,7 +785,7 @@ public:
|
||||
if (fUseCache && fAvailableWatchCreditCached)
|
||||
return nAvailableWatchCreditCached;
|
||||
|
||||
int64_t nCredit = 0;
|
||||
CAmount nCredit = 0;
|
||||
for (unsigned int i = 0; i < vout.size(); i++)
|
||||
{
|
||||
if (!pwallet->IsSpent(GetHash(), i))
|
||||
@ -802,7 +802,7 @@ public:
|
||||
return nCredit;
|
||||
}
|
||||
|
||||
int64_t GetChange() const
|
||||
CAmount GetChange() const
|
||||
{
|
||||
if (fChangeCached)
|
||||
return nChangeCached;
|
||||
@ -812,10 +812,10 @@ public:
|
||||
}
|
||||
|
||||
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,
|
||||
int64_t& nSent, int64_t& nFee, const isminefilter& filter) const;
|
||||
void GetAccountAmounts(const std::string& strAccount, CAmount& nReceived,
|
||||
CAmount& nSent, CAmount& nFee, const isminefilter& filter) const;
|
||||
|
||||
bool IsFromMe(const isminefilter& filter) const
|
||||
{
|
||||
@ -949,7 +949,7 @@ class CAccountingEntry
|
||||
{
|
||||
public:
|
||||
std::string strAccount;
|
||||
int64_t nCreditDebit;
|
||||
CAmount nCreditDebit;
|
||||
int64_t nTime;
|
||||
std::string strOtherAccount;
|
||||
std::string strComment;
|
||||
|
@ -187,12 +187,12 @@ bool CWalletDB::WriteAccountingEntry(const CAccountingEntry& acentry)
|
||||
return WriteAccountingEntry(++nAccountingEntryNumber, acentry);
|
||||
}
|
||||
|
||||
int64_t CWalletDB::GetAccountCreditDebit(const string& strAccount)
|
||||
CAmount CWalletDB::GetAccountCreditDebit(const string& strAccount)
|
||||
{
|
||||
list<CAccountingEntry> entries;
|
||||
ListAccountCreditDebit(strAccount, entries);
|
||||
|
||||
int64_t nCreditDebit = 0;
|
||||
CAmount nCreditDebit = 0;
|
||||
BOOST_FOREACH (const CAccountingEntry& entry, entries)
|
||||
nCreditDebit += entry.nCreditDebit;
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#ifndef BITCOIN_WALLETDB_H
|
||||
#define BITCOIN_WALLETDB_H
|
||||
|
||||
#include "amount.h"
|
||||
#include "db.h"
|
||||
#include "key.h"
|
||||
#include "keystore.h"
|
||||
@ -118,7 +119,7 @@ public:
|
||||
bool EraseDestData(const std::string &address, const std::string &key);
|
||||
|
||||
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);
|
||||
|
||||
DBErrors ReorderTransactions(CWallet* pwallet);
|
||||
|
Loading…
Reference in New Issue
Block a user