Skip to content
Permalink
Browse files

don't count or spend payments until they have 1 confirmation,

misc cleanup,
changed internal version number from 312 to 31300
-- version 0.3.13

git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@158 1a98c847-1fd6-4fd8-948a-caf3550aa51b
  • Loading branch information...
non-github-bitcoin committed Sep 30, 2010
1 parent 9b8eb4d commit a790fa46f40d751307f86c37a709eb119768ce5b
2 db.cpp
@@ -465,7 +465,7 @@ bool CTxDB::LoadBlockIndex()
CBlockIndex* pindexFork = NULL;
for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)
{
if (pindex->nHeight < 74000 && !mapArgs.count("-checkblocks"))
if (pindex->nHeight < nBestHeight-2500 && !mapArgs.count("-checkblocks"))
break;
CBlock block;
if (!block.ReadFromDisk(pindex))
@@ -203,7 +203,7 @@ bool AppInit2(int argc, char* argv[])
if (!fDebug && !pszSetDataDir[0])
ShrinkDebugFile();
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("Bitcoin version %d.%d.%d%s beta\n", VERSION/10000, (VERSION/100)%100, VERSION%100, pszSubVer);
printf("Bitcoin version %s%s beta\n", FormatVersion(VERSION).c_str(), pszSubVer);
#ifdef GUI
printf("OS version %s\n", ((string)wxGetOsDescription()).c_str());
printf("System default language is %d %s\n", g_locale.GetSystemLanguage(), ((string)g_locale.GetSysName()).c_str());
BIN -6 Bytes (100%) locale/de/LC_MESSAGES/bitcoin.mo
Binary file not shown.
@@ -321,8 +321,8 @@ msgstr "Beim schließen &Minimieren"

#: ../../../ui.cpp:1595
#, c-format
msgid "version 0.%d.%d beta"
msgstr "Version 0.%d.%d Beta"
msgid "version %s%s beta"
msgstr "Version %s%s Beta"

#: ../../../ui.cpp:1681
msgid "Will appear as \"From: Unknown\""
BIN -8 Bytes (100%) locale/es/LC_MESSAGES/bitcoin.mo
Binary file not shown.
@@ -350,8 +350,8 @@ msgstr "&Minimizar al cerrar"

#: ../../../ui.cpp:1610
#, c-format
msgid "version %d.%d.%d beta"
msgstr "version %d.%d.%d beta"
msgid "version %s%s beta"
msgstr "version %s%s beta"

#: ../../../ui.cpp:1696
msgid "Will appear as \"From: Unknown\""
BIN -8 Bytes (100%) locale/fr/LC_MESSAGES/bitcoin.mo
Binary file not shown.
@@ -351,8 +351,8 @@ msgstr "&Réduire à la fermeture"

#: ../../../ui.cpp:1610
#, c-format
msgid "version %d.%d.%d beta"
msgstr "version %d.%d.%d beta"
msgid "version %s%s beta"
msgstr "version %s%s beta"

#: ../../../ui.cpp:1696
msgid "Will appear as \"From: Unknown\""
BIN -6 Bytes (100%) locale/it/LC_MESSAGES/bitcoin.mo
Binary file not shown.
@@ -319,8 +319,8 @@ msgstr "&Minimizza se chiuso"

#: ../../../ui.cpp:1595
#, c-format
msgid "version 0.%d.%d beta"
msgstr "versione 0.%d.%d beta"
msgid "version %s%s beta"
msgstr "versione %s%s beta"

#: ../../../ui.cpp:1681
msgid "Will appear as \"From: Unknown\""
BIN -6 Bytes (100%) locale/nl/LC_MESSAGES/bitcoin.mo
Binary file not shown.
@@ -320,8 +320,8 @@ msgstr "&Minimalizeer bij sluiten"

#: ../../../ui.cpp:1595
#, c-format
msgid "version 0.%d.%d beta"
msgstr "versie 0.%d.%d beta"
msgid "version %s%s beta"
msgstr "versie %s%s beta"

#: ../../../ui.cpp:1681
msgid "Will appear as \"From: Unknown\""
BIN -6 Bytes (100%) locale/pt/LC_MESSAGES/bitcoin.mo
Binary file not shown.
@@ -319,8 +319,8 @@ msgstr "&Minimizar ao fechar"

#: ../../../ui.cpp:1595
#, c-format
msgid "version 0.%d.%d beta"
msgstr "versão 0.%d.%d beta"
msgid "version %s%s beta"
msgstr "versão %s%s beta"

#: ../../../ui.cpp:1681
msgid "Will appear as \"From: Unknown\""
@@ -487,18 +487,56 @@ void CWalletTx::AddSupportingTransactions(CTxDB& txdb)



bool CTransaction::CheckTransaction() const
{
// Basic checks that don't depend on any context
if (vin.empty() || vout.empty())
return error("CTransaction::CheckTransaction() : vin or vout empty");

// Size limits
if (::GetSerializeSize(*this, SER_NETWORK) > MAX_BLOCK_SIZE)
return error("CTransaction::CheckTransaction() : size limits failed");

// Check for negative or overflow output values
int64 nValueOut = 0;
foreach(const CTxOut& txout, vout)
{
if (txout.nValue < 0)
return error("CTransaction::CheckTransaction() : txout.nValue negative");
if (txout.nValue > MAX_MONEY)
return error("CTransaction::CheckTransaction() : txout.nValue too high");
nValueOut += txout.nValue;
if (!MoneyRange(nValueOut))
return error("CTransaction::CheckTransaction() : txout total out of range");
}

if (IsCoinBase())
{
if (vin[0].scriptSig.size() < 2 || vin[0].scriptSig.size() > 100)
return error("CTransaction::CheckTransaction() : coinbase script size");
}
else
{
foreach(const CTxIn& txin, vin)
if (txin.prevout.IsNull())
return error("CTransaction::CheckTransaction() : prevout is null");
}

return true;
}

bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMissingInputs)
{
if (pfMissingInputs)
*pfMissingInputs = false;

if (!CheckTransaction())
return error("AcceptToMemoryPool() : CheckTransaction failed");

// Coinbase is only valid in a block, not as a loose transaction
if (IsCoinBase())
return error("AcceptToMemoryPool() : coinbase as individual tx");

if (!CheckTransaction())
return error("AcceptToMemoryPool() : CheckTransaction failed");

// To help v0.1.5 clients who would see it as a negative number
if ((int64)nLockTime > INT_MAX)
return error("AcceptToMemoryPool() : not accepting nLockTime beyond 2038 yet");
@@ -815,7 +853,7 @@ uint256 GetOrphanRoot(const CBlock* pblock)
return pblock->GetHash();
}

int64 CBlock::GetBlockValue(int nHeight, int64 nFees) const
int64 GetBlockValue(int nHeight, int64 nFees)
{
int64 nSubsidy = 50 * COIN;

@@ -1024,6 +1062,11 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPoo
if (!txindex.vSpent[prevout.n].IsNull())
return fMiner ? false : error("ConnectInputs() : %s prev tx already used at %s", GetHash().ToString().substr(0,6).c_str(), txindex.vSpent[prevout.n].ToString().c_str());

// Check for negative or overflow input values
nValueIn += txPrev.vout[prevout.n].nValue;
if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(nValueIn))
return error("ConnectInputs() : txin values out of range");

// Mark outpoints as spent
txindex.vSpent[prevout.n] = posThisTx;

@@ -1032,12 +1075,6 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPoo
txdb.UpdateTxIndex(prevout.hash, txindex);
else if (fMiner)
mapTestPool[prevout.hash] = txindex;

nValueIn += txPrev.vout[prevout.n].nValue;

// Check for negative or overflow input values
if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(nValueIn))
return error("ConnectInputs() : txin values out of range");
}

if (nValueIn < GetValueOut())
@@ -2967,7 +3004,7 @@ void BitcoinMiner()
}
}
pblock->nBits = nBits;
pblock->vtx[0].vout[0].nValue = pblock->GetBlockValue(pindexPrev->nHeight+1, nFees);
pblock->vtx[0].vout[0].nValue = GetBlockValue(pindexPrev->nHeight+1, nFees);
printf("Running BitcoinMiner with %d transactions in block\n", pblock->vtx.size());


@@ -3169,6 +3206,8 @@ int64 GetBalance()
CWalletTx* pcoin = &(*it).second;
if (!pcoin->IsFinal() || pcoin->fSpent)
continue;
if (pcoin->GetDepthInMainChain() < 1 && pcoin->GetDebit() <= 0)
continue;
nTotal += pcoin->GetCredit(true);
}
}
@@ -3200,6 +3239,8 @@ bool SelectCoins(int64 nTargetValue, set<CWalletTx*>& setCoinsRet)
{
if (!pcoin->IsFinal() || pcoin->fSpent)
continue;
if (pcoin->GetDepthInMainChain() < 1 && pcoin->GetDebit() <= 0)
continue;
int64 n = pcoin->GetCredit();
if (n <= 0)
continue;
100 main.h
@@ -469,44 +469,6 @@ class CTransaction
return (vin.size() == 1 && vin[0].prevout.IsNull());
}

bool CheckTransaction() const
{
// Basic checks that don't depend on any context
if (vin.empty() || vout.empty())
return error("CTransaction::CheckTransaction() : vin or vout empty");

// Size limits
if (::GetSerializeSize(*this, SER_NETWORK) > MAX_BLOCK_SIZE)
return error("CTransaction::CheckTransaction() : size limits failed");

// Check for negative or overflow output values
int64 nValueOut = 0;
foreach(const CTxOut& txout, vout)
{
if (txout.nValue < 0)
return error("CTransaction::CheckTransaction() : txout.nValue negative");
if (txout.nValue > MAX_MONEY)
return error("CTransaction::CheckTransaction() : txout.nValue too high");
nValueOut += txout.nValue;
if (!MoneyRange(nValueOut))
return error("CTransaction::CheckTransaction() : txout total out of range");
}

if (IsCoinBase())
{
if (vin[0].scriptSig.size() < 2 || vin[0].scriptSig.size() > 100)
return error("CTransaction::CheckTransaction() : coinbase script size");
}
else
{
foreach(const CTxIn& txin, vin)
if (txin.prevout.IsNull())
return error("CTransaction::CheckTransaction() : prevout is null");
}

return true;
}

int GetSigOpCount() const
{
int n = 0;
@@ -655,20 +617,17 @@ class CTransaction
}



bool DisconnectInputs(CTxDB& txdb);
bool ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx,
CBlockIndex* pindexBlock, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee=0);
bool ClientConnectInputs();

bool CheckTransaction() const;
bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL);

bool AcceptToMemoryPool(bool fCheckInputs=true, bool* pfMissingInputs=NULL)
{
CTxDB txdb("r");
return AcceptToMemoryPool(txdb, fCheckInputs, pfMissingInputs);
}

protected:
bool AddToMemoryPoolUnchecked();
public:
@@ -690,9 +649,7 @@ class CMerkleTx : public CTransaction
int nIndex;

// memory only
mutable bool fMerkleVerified;
mutable bool fGetCreditCached;
mutable int64 nGetCreditCached;
mutable char fMerkleVerified;


CMerkleTx()
@@ -710,8 +667,6 @@ class CMerkleTx : public CTransaction
hashBlock = 0;
nIndex = -1;
fMerkleVerified = false;
fGetCreditCached = false;
nGetCreditCached = 0;
}

IMPLEMENT_SERIALIZE
@@ -723,20 +678,6 @@ class CMerkleTx : public CTransaction
READWRITE(nIndex);
)

int64 GetCredit(bool fUseCache=false) const
{
// Must wait until coinbase is safely deep enough in the chain before valuing it
if (IsCoinBase() && GetBlocksToMaturity() > 0)
return 0;

// GetBalance can assume transactions in mapWallet won't change
if (fUseCache && fGetCreditCached)
return nGetCreditCached;
nGetCreditCached = CTransaction::GetCredit();
fGetCreditCached = true;
return nGetCreditCached;
}


int SetMerkleBranch(const CBlock* pblock=NULL);
int GetDepthInMainChain(int& nHeightRet) const;
@@ -767,9 +708,16 @@ class CWalletTx : public CMerkleTx
char fSpent;
//// probably need to sign the order info so know it came from payer

// memory only
mutable char fDebitCached;
mutable char fCreditCached;
mutable int64 nDebitCached;
mutable int64 nCreditCached;

// memory only UI hints
mutable unsigned int nTimeDisplayed;
mutable int nLinesDisplayed;
mutable char fConfirmedDisplayed;


CWalletTx()
@@ -793,6 +741,10 @@ class CWalletTx : public CMerkleTx
nTimeReceived = 0;
fFromMe = false;
fSpent = false;
fDebitCached = false;
fCreditCached = false;
nDebitCached = 0;
nCreditCached = 0;
nTimeDisplayed = 0;
nLinesDisplayed = 0;
}
@@ -810,6 +762,31 @@ class CWalletTx : public CMerkleTx
READWRITE(fSpent);
)

int64 GetDebit() const
{
if (vin.empty())
return 0;
if (fDebitCached)
return nDebitCached;
nDebitCached = CTransaction::GetDebit();
fDebitCached = true;
return nDebitCached;
}

int64 GetCredit(bool fUseCache=false) const
{
// Must wait until coinbase is safely deep enough in the chain before valuing it
if (IsCoinBase() && GetBlocksToMaturity() > 0)
return 0;

// GetBalance can assume transactions in mapWallet won't change
if (fUseCache && fCreditCached)
return nCreditCached;
nCreditCached = CTransaction::GetCredit();
fCreditCached = true;
return nCreditCached;
}

bool WriteToDisk()
{
return CWalletDB().WriteTx(GetHash(), *this);
@@ -1103,7 +1080,6 @@ class CBlock
}


int64 GetBlockValue(int nHeight, int64 nFees) const;
bool DisconnectBlock(CTxDB& txdb, CBlockIndex* pindex);
bool ConnectBlock(CTxDB& txdb, CBlockIndex* pindex);
bool ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions=true);
@@ -778,6 +778,14 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
int nKeysCount = CastToBigNum(stacktop(-i)).getint();
if (nKeysCount < 0)
return false;
if (nBestHeight > 84000)
{
if (nKeysCount > 20)
return false;
nOpCount += nKeysCount;
if (nOpCount > 201)
return false;
}
int ikey = ++i;
i += nKeysCount;
if (stack.size() < i)

0 comments on commit a790fa4

Please sign in to comment.
You can’t perform that action at this time.