return DoS(100, error("CTransaction::CheckTransaction() : size limits failed"));
// Check for negative or overflow output values
- int64_t nValueOut = 0;
- for (unsigned int i = 0; i < vout.size(); i++)
+ CBigNum nValueOut = 0;
+ for (uint32_t i = 0; i < vout.size(); i++)
{
- const CTxOut& txout = vout[i];
+ const auto& txout = vout[i];
if (txout.IsEmpty() && !IsCoinBase() && !IsCoinStake())
return DoS(100, error("CTransaction::CheckTransaction() : txout empty for user transaction"));
if (!MoneyRange(txout.nValue))
if (IsCoinBase())
return 0;
- int64_t nResult = 0;
- for (unsigned int i = 0; i < vin.size(); i++)
+ CBigNum nResult = 0;
+ for (uint32_t i = 0; i < vin.size(); i++)
{
- nResult += GetOutputFor(vin[i], inputs).nValue;
+ const auto& txOut = GetOutputFor(vin[i], inputs);
+ nResult += txOut.nValue;
+ if (!MoneyRange(txOut.nValue) || !MoneyRange(nResult))
+ throw runtime_error("CTransaction::GetValueIn() : value out of range");
}
- return nResult;
+ return nResult.getint64();
}
if (!IsCoinBase())
{
int64_t nValueIn = 0;
- int64_t nFees = 0;
- for (unsigned int i = 0; i < vin.size(); i++)
{
- auto prevout = vin[i].prevout;
- assert(inputs.count(prevout.hash) > 0);
- CTxIndex& txindex = inputs[prevout.hash].first;
- CTransaction& txPrev = inputs[prevout.hash].second;
-
- if (prevout.n >= txPrev.vout.size() || prevout.n >= txindex.vSpent.size())
- return DoS(100, error("ConnectInputs() : %s prevout.n out of range %d %" PRIszu " %" PRIszu " prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str()));
-
- // If prev is coinbase or coinstake, check that it's matured
- if (txPrev.IsCoinBase() || txPrev.IsCoinStake())
- for (const CBlockIndex* pindex = pindexBlock; pindex && pindexBlock->nHeight - pindex->nHeight < nCoinbaseMaturity; pindex = pindex->pprev)
- if (pindex->nBlockPos == txindex.pos.nBlockPos && pindex->nFile == txindex.pos.nFile)
- return error("ConnectInputs() : tried to spend %s at depth %d", txPrev.IsCoinBase() ? "coinbase" : "coinstake", pindexBlock->nHeight - pindex->nHeight);
-
- // ppcoin: check transaction timestamp
- if (txPrev.nTime > nTime)
- return DoS(100, error("ConnectInputs() : transaction timestamp earlier than input transaction"));
-
- // Check for negative or overflow input values
- nValueIn += txPrev.vout[prevout.n].nValue;
- if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(nValueIn))
- return DoS(100, error("ConnectInputs() : txin values out of range"));
-
+ CBigNum bnValueIn = 0;
+ for (uint32_t i = 0; i < vin.size(); i++)
+ {
+ auto prevout = vin[i].prevout;
+ assert(inputs.count(prevout.hash) > 0);
+ CTxIndex& txindex = inputs[prevout.hash].first;
+ CTransaction& txPrev = inputs[prevout.hash].second;
+
+ if (prevout.n >= txPrev.vout.size() || prevout.n >= txindex.vSpent.size())
+ return DoS(100, error("ConnectInputs() : %s prevout.n out of range %d %" PRIszu " %" PRIszu " prev tx %s\n%s", GetHash().ToString().substr(0,10).c_str(), prevout.n, txPrev.vout.size(), txindex.vSpent.size(), prevout.hash.ToString().substr(0,10).c_str(), txPrev.ToString().c_str()));
+
+ // If prev is coinbase or coinstake, check that it's matured
+ if (txPrev.IsCoinBase() || txPrev.IsCoinStake())
+ for (const CBlockIndex* pindex = pindexBlock; pindex && pindexBlock->nHeight - pindex->nHeight < nCoinbaseMaturity; pindex = pindex->pprev)
+ if (pindex->nBlockPos == txindex.pos.nBlockPos && pindex->nFile == txindex.pos.nFile)
+ return error("ConnectInputs() : tried to spend %s at depth %d", txPrev.IsCoinBase() ? "coinbase" : "coinstake", pindexBlock->nHeight - pindex->nHeight);
+
+ // ppcoin: check transaction timestamp
+ if (txPrev.nTime > nTime)
+ return DoS(100, error("ConnectInputs() : transaction timestamp earlier than input transaction"));
+
+ // Check for negative or overflow input values
+ bnValueIn += txPrev.vout[prevout.n].nValue;
+ if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(bnValueIn))
+ return DoS(100, error("ConnectInputs() : txin values out of range"));
+ }
+ nValueIn = bnValueIn.getint64();
}
if (pvChecks)
// Tally transaction fees
auto nTxFee = nValueIn - GetValueOut();
- if (nTxFee < 0)
- return DoS(100, error("ConnectInputs() : %s nTxFee < 0", GetHash().ToString().substr(0,10).c_str()));
-
- nFees += nTxFee;
- if (!MoneyRange(nFees))
+ if (!MoneyRange(nTxFee))
return DoS(100, error("ConnectInputs() : nFees out of range"));
}
}
// Take over previous transactions' spent pointers
{
LOCK(mempool.cs);
- int64_t nValueIn = 0;
- for (unsigned int i = 0; i < vin.size(); i++)
+ CBigNum bnValueIn = 0;
+ for (uint32_t i = 0; i < vin.size(); i++)
{
// Get prev tx from single transactions in memory
auto prevout = vin[i].prevout;
// // Flag outpoints as used
// txPrev.vout[prevout.n].posNext = posThisTx;
- nValueIn += txPrev.vout[prevout.n].nValue;
+ bnValueIn += txPrev.vout[prevout.n].nValue;
- if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(nValueIn))
+ if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(bnValueIn))
return error("ClientConnectInputs() : txin values out of range");
}
- if (GetValueOut() > nValueIn)
+ if (GetValueOut() > bnValueIn.getint64())
return false;
}
int64_t CWallet::GetDebit(const CTransaction& tx, const isminefilter& filter) const
{
- int64_t nDebit = 0;
+ CBigNum nDebit = 0;
for(const CTxIn& txin : tx.vin)
{
- nDebit += GetDebit(txin, filter);
- if (!MoneyRange(nDebit))
+ auto nValue = GetDebit(txin, filter);
+ nDebit += nValue;
+ if (!MoneyRange(nValue) || !MoneyRange(nDebit))
throw runtime_error("CWallet::GetDebit() : value out of range");
}
- return nDebit;
+ return nDebit.getint64();
}
int64_t CWallet::GetCredit(const CTransaction& tx, const isminefilter& filter) const
{
- int64_t nCredit = 0;
+ CBigNum nCredit = 0;
for(const CTxOut& txout : tx.vout)
{
- nCredit += GetCredit(txout, filter);
- if (!MoneyRange(nCredit))
+ auto nValue = GetCredit(txout, filter);
+ nCredit += nValue;
+ if (!MoneyRange(nValue) || !MoneyRange(nCredit))
throw runtime_error("CWallet::GetCredit() : value out of range");
}
- return nCredit;
+ return nCredit.getint64();
}
int64_t CWallet::GetChange(const CTransaction& tx) const
{
- int64_t nChange = 0;
+ CBigNum nChange = 0;
for(const CTxOut& txout : tx.vout)
{
- nChange += GetChange(txout);
- if (!MoneyRange(nChange))
+ int64_t nValue = GetChange(txout);
+ nChange += nValue;
+ if (!MoneyRange(nValue) || !MoneyRange(nChange))
throw runtime_error("CWallet::GetChange() : value out of range");
}
- return nChange;
+ return nChange.getint64();
}
int64_t CWalletTx::GetTxTime() const
return nAvailableCreditCached;
}
- int64_t nCredit = 0;
- for (unsigned int i = 0; i < vout.size(); i++)
+ CBigNum nCredit = 0;
+ for (uint32_t i = 0; i < vout.size(); i++)
{
if (!IsSpent(i))
{
const CTxOut &txout = vout[i];
- nCredit += pwallet->GetCredit(txout, MINE_SPENDABLE);
- if (!MoneyRange(nCredit))
+ int64_t nValue = pwallet->GetCredit(txout, MINE_SPENDABLE);
+ nCredit += nValue;
+ if (!MoneyRange(nValue) || !MoneyRange(nCredit))
throw runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
}
}
- nAvailableCreditCached = nCredit;
+ nAvailableCreditCached = nCredit.getint64();
fAvailableCreditCached = true;
- return nCredit;
+ return nCredit.getint64();
}
int64_t CWalletTx::GetAvailableWatchCredit(bool fUseCache) const
return nAvailableWatchCreditCached;
}
- int64_t nCredit = 0;
+ CBigNum nCredit = 0;
for (unsigned int i = 0; i < vout.size(); i++)
{
if (!IsSpent(i))
{
const CTxOut &txout = vout[i];
- nCredit += pwallet->GetCredit(txout, MINE_WATCH_ONLY);
- if (!MoneyRange(nCredit))
+ int64_t nValue = pwallet->GetCredit(txout, MINE_WATCH_ONLY);
+ nCredit += nValue;
+ if (!MoneyRange(nValue) || !MoneyRange(nCredit))
throw runtime_error("CWalletTx::GetAvailableCredit() : value out of range");
}
}
- nAvailableWatchCreditCached = nCredit;
+ nAvailableWatchCreditCached = nCredit.getint64();
fAvailableWatchCreditCached = true;
- return nCredit;
+ return nCredit.getint64();
}
int64_t CWalletTx::GetChange() const