What changed
Bitcoin v0.3.12 → v0.3.13
Release commit message: fixed linux build, dkaparis: _WIN32_WINNT 0x500 -- version 0.3.13 release
Previous diff: v0.3.10 → v0.3.12. Next: v0.3.13 → v0.3.14.
- db.cpp modified · +1 −2
- headers.h modified · +2 −1
- init.cpp modified · +14 −2
- main.cpp modified · +244 −124
- main.h modified · +60 −76
- net.cpp modified · +5 −1
- rpc.cpp modified · +18 −6
- script.cpp modified · +8 −0
- serialize.h modified · +24 −30
- setup.nsi modified · +3 −3
- sha256.cpp modified · +52 −2
- ui.cpp modified · +51 −14
- ui.h modified · +1 −2
- util.cpp modified · +40 −9
- util.h modified · +27 −1
db.cpp (modified)
1--- v0.3.12/db.cpp2+++ v0.3.13/db.cpp3@@ -77,7 +77,6 @@4 DB_INIT_MPOOL |5 DB_INIT_TXN |6 DB_THREAD |7- DB_PRIVATE |8 DB_RECOVER,9 S_IRUSR | S_IWUSR);10 if (ret > 0)11@@ -466,7 +465,7 @@12 CBlockIndex* pindexFork = NULL;13 for (CBlockIndex* pindex = pindexBest; pindex && pindex->pprev; pindex = pindex->pprev)14 {15- if (pindex->nHeight < 74000 && !mapArgs.count("-checkblocks"))16+ if (pindex->nHeight < nBestHeight-2500 && !mapArgs.count("-checkblocks"))17 break;18 CBlock block;19 if (!block.ReadFromDisk(pindex))
headers.h (modified)
1--- v0.3.12/headers.h2+++ v0.3.13/headers.h3@@ -11,7 +11,7 @@4 #ifdef _WIN32_WINNT5 #undef _WIN32_WINNT6 #endif7-#define _WIN32_WINNT 0x04008+#define _WIN32_WINNT 0x05009 #ifdef _WIN32_IE10 #undef _WIN32_IE11 #endif12@@ -99,6 +99,7 @@13 #include <net/if.h>14 #include <ifaddrs.h>15 #include <fcntl.h>16+#include <signal.h>17 #endif18 #ifdef BSD19 #include <netinet/in.h>
init.cpp (modified)
1--- v0.3.12/init.cpp2+++ v0.3.13/init.cpp3@@ -3,7 +3,6 @@4 // file license.txt or http://www.opensource.org/licenses/mit-license.php.5 6 #include "headers.h"7-8 9 10 11@@ -57,6 +56,11 @@12 }13 }14 15+void HandleSIGTERM(int)16+{17+ fRequestShutdown = true;18+}19+20 21 22 23@@ -129,6 +133,14 @@24 #endif25 #ifndef __WXMSW__26 umask(077);27+#endif28+#ifndef __WXMSW__29+ // Clean shutdown on SIGTERM30+ struct sigaction sa;31+ sa.sa_handler = HandleSIGTERM;32+ sigemptyset(&sa.sa_mask);33+ sa.sa_flags = 0;34+ sigaction(SIGTERM, &sa, NULL);35 #endif36 37 //38@@ -191,7 +203,7 @@39 if (!fDebug && !pszSetDataDir[0])40 ShrinkDebugFile();41 printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");42- printf("Bitcoin version %d.%d.%d%s beta\n", VERSION/10000, (VERSION/100)%100, VERSION%100, pszSubVer);43+ printf("Bitcoin version %s%s beta\n", FormatVersion(VERSION).c_str(), pszSubVer);44 #ifdef GUI45 printf("OS version %s\n", ((string)wxGetOsDescription()).c_str());46 printf("System default language is %d %s\n", g_locale.GetSystemLanguage(), ((string)g_locale.GetSysName()).c_str());
main.cpp (modified)
1--- v0.3.12/main.cpp2+++ v0.3.13/main.cpp3@@ -487,17 +487,55 @@4 5 6 7+bool CTransaction::CheckTransaction() const8+{9+ // Basic checks that don't depend on any context10+ if (vin.empty() || vout.empty())11+ return error("CTransaction::CheckTransaction() : vin or vout empty");12+13+ // Size limits14+ if (::GetSerializeSize(*this, SER_NETWORK) > MAX_BLOCK_SIZE)15+ return error("CTransaction::CheckTransaction() : size limits failed");16+17+ // Check for negative or overflow output values18+ int64 nValueOut = 0;19+ foreach(const CTxOut& txout, vout)20+ {21+ if (txout.nValue < 0)22+ return error("CTransaction::CheckTransaction() : txout.nValue negative");23+ if (txout.nValue > MAX_MONEY)24+ return error("CTransaction::CheckTransaction() : txout.nValue too high");25+ nValueOut += txout.nValue;26+ if (!MoneyRange(nValueOut))27+ return error("CTransaction::CheckTransaction() : txout total out of range");28+ }29+30+ if (IsCoinBase())31+ {32+ if (vin[0].scriptSig.size() < 2 || vin[0].scriptSig.size() > 100)33+ return error("CTransaction::CheckTransaction() : coinbase script size");34+ }35+ else36+ {37+ foreach(const CTxIn& txin, vin)38+ if (txin.prevout.IsNull())39+ return error("CTransaction::CheckTransaction() : prevout is null");40+ }41+42+ return true;43+}44+45 bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMissingInputs)46 {47 if (pfMissingInputs)48 *pfMissingInputs = false;49+50+ if (!CheckTransaction())51+ return error("AcceptToMemoryPool() : CheckTransaction failed");52 53 // Coinbase is only valid in a block, not as a loose transaction54 if (IsCoinBase())55 return error("AcceptToMemoryPool() : coinbase as individual tx");56-57- if (!CheckTransaction())58- return error("AcceptToMemoryPool() : CheckTransaction failed");59 60 // To help v0.1.5 clients who would see it as a negative number61 if ((int64)nLockTime > INT_MAX)62@@ -815,7 +853,7 @@63 return pblock->GetHash();64 }65 66-int64 CBlock::GetBlockValue(int nHeight, int64 nFees) const67+int64 GetBlockValue(int nHeight, int64 nFees)68 {69 int64 nSubsidy = 50 * COIN;70 71@@ -1024,6 +1062,11 @@72 if (!txindex.vSpent[prevout.n].IsNull())73 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());74 75+ // Check for negative or overflow input values76+ nValueIn += txPrev.vout[prevout.n].nValue;77+ if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(nValueIn))78+ return error("ConnectInputs() : txin values out of range");79+80 // Mark outpoints as spent81 txindex.vSpent[prevout.n] = posThisTx;82 83@@ -1032,12 +1075,6 @@84 txdb.UpdateTxIndex(prevout.hash, txindex);85 else if (fMiner)86 mapTestPool[prevout.hash] = txindex;87-88- nValueIn += txPrev.vout[prevout.n].nValue;89-90- // Check for negative or overflow input values91- if (!MoneyRange(txPrev.vout[prevout.n].nValue) || !MoneyRange(nValueIn))92- return error("ConnectInputs() : txin values out of range");93 }94 95 if (nValueIn < GetValueOut())96@@ -1374,8 +1411,12 @@97 // that can be verified before saving an orphan block.98 99 // Size limits100- if (vtx.empty() || vtx.size() > MAX_SIZE || ::GetSerializeSize(*this, SER_NETWORK) > MAX_SIZE)101+ if (vtx.empty() || vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(*this, SER_NETWORK) > MAX_BLOCK_SIZE)102 return error("CheckBlock() : size limits failed");103+104+ // Check proof of work matches claimed amount105+ if (!CheckProofOfWork(GetHash(), nBits))106+ return error("CheckBlock() : proof of work failed");107 108 // Check timestamp109 if (GetBlockTime() > GetAdjustedTime() + 2 * 60 * 60)110@@ -1393,9 +1434,9 @@111 if (!tx.CheckTransaction())112 return error("CheckBlock() : CheckTransaction failed");113 114- // Check proof of work matches claimed amount115- if (!CheckProofOfWork(GetHash(), nBits))116- return error("CheckBlock() : proof of work failed");117+ // Check that it's not full of nonstandard transactions118+ if (GetSigOpCount() > MAX_BLOCK_SIGOPS)119+ return error("CheckBlock() : too many nonstandard transactions");120 121 // Check merkleroot122 if (hashMerkleRoot != BuildMerkleTree())123@@ -1418,13 +1459,9 @@124 CBlockIndex* pindexPrev = (*mi).second;125 int nHeight = pindexPrev->nHeight+1;126 127- // Check size128- if (nHeight > 79400 && ::GetSerializeSize(*this, SER_NETWORK) > MAX_BLOCK_SIZE)129- return error("AcceptBlock() : over size limit");130-131- // Check that it's not full of nonstandard transactions132- if (nHeight > 79400 && GetSigOpCount() > MAX_BLOCK_SIGOPS)133- return error("AcceptBlock() : too many nonstandard transactions");134+ // Check proof of work135+ if (nBits != GetNextWorkRequired(pindexPrev))136+ return error("AcceptBlock() : incorrect proof of work");137 138 // Check timestamp against prev139 if (GetBlockTime() <= pindexPrev->GetMedianTimePast())140@@ -1434,10 +1471,6 @@141 foreach(const CTransaction& tx, vtx)142 if (!tx.IsFinal(nHeight, GetBlockTime()))143 return error("AcceptBlock() : contains a non-final transaction");144-145- // Check proof of work146- if (nBits != GetNextWorkRequired(pindexPrev))147- return error("AcceptBlock() : incorrect proof of work");148 149 // Check that the block chain matches the known block chain up to a checkpoint150 if ((nHeight == 11111 && hash != uint256("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")) ||151@@ -2392,13 +2425,11 @@152 153 else if (strCommand == "getaddr")154 {155- // This includes all nodes that are currently online,156- // since they rebroadcast an addr every 24 hours157+ // Nodes rebroadcast an addr every 24 hours158 pfrom->vAddrToSend.clear();159- int64 nSince = GetAdjustedTime() - 12 * 60 * 60; // in the last 12 hours160+ int64 nSince = GetAdjustedTime() - 6 * 60 * 60; // in the last 6 hours161 CRITICAL_BLOCK(cs_mapAddresses)162 {163- unsigned int nSize = mapAddresses.size();164 foreach(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses)165 {166 if (fShutdown)167@@ -2417,6 +2448,12 @@168 CWalletTx order;169 vRecv >> hashReply >> order;170 171+ if (!mapArgs.count("-allowreceivebyip") || mapArgs["-allowreceivebyip"] == "0")172+ {173+ pfrom->PushMessage("reply", hashReply, (int)2, string(""));174+ return true;175+ }176+177 /// we have a chance to check the order here178 179 // Keep giving the same key to the same ip until they use it180@@ -2436,6 +2473,12 @@181 CWalletTx wtxNew;182 vRecv >> hashReply >> wtxNew;183 wtxNew.fFromMe = false;184+185+ if (!mapArgs.count("-allowreceivebyip") || mapArgs["-allowreceivebyip"] == "0")186+ {187+ pfrom->PushMessage("reply", hashReply, (int)2);188+ return true;189+ }190 191 // Broadcast192 if (!wtxNew.AcceptWalletTransaction())193@@ -2738,6 +2781,68 @@194 printf("ThreadBitcoinMiner exiting, %d threads remaining\n", vnThreadsRunning[3]);195 }196 197+#if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE)198+void CallCPUID(int in, int& aret, int& cret)199+{200+ int a, c;201+ asm (202+ "mov %2, %%eax; " // in into eax203+ "cpuid;"204+ "mov %%eax, %0;" // eax into a205+ "mov %%ecx, %1;" // eax into c206+ :"=r"(a),"=r"(c) /* output */207+ :"r"(in) /* input */208+ :"%eax","%ecx" /* clobbered register */209+ );210+ aret = a;211+ cret = c;212+}213+214+bool Detect128BitSSE2()215+{216+ int a, c, nBrand;217+ CallCPUID(0, a, nBrand);218+ bool fIntel = (nBrand == 0x6c65746e); // ntel219+ bool fAMD = (nBrand == 0x444d4163); // cAMD220+221+ struct222+ {223+ unsigned int nStepping : 4;224+ unsigned int nModel : 4;225+ unsigned int nFamily : 4;226+ unsigned int nProcessorType : 2;227+ unsigned int nUnused : 2;228+ unsigned int nExtendedModel : 4;229+ unsigned int nExtendedFamily : 8;230+ }231+ cpu;232+ CallCPUID(1, a, c);233+ memcpy(&cpu, &a, sizeof(cpu));234+ int nFamily = cpu.nExtendedFamily + cpu.nFamily;235+ int nModel = cpu.nExtendedModel*16 + cpu.nModel;236+237+ // We need Intel Nehalem or AMD K10 or better for 128bit SSE2238+ // Nehalem = i3/i5/i7 and some Xeon239+ // K10 = Opterons with 4 or more cores, Phenom, Phenom II, Athlon II240+ // Intel Core i5 family 6, model 26 or 30241+ // Intel Core i7 family 6, model 26 or 30242+ // Intel Core i3 family 6, model 37243+ // AMD Phenom family 16, model 10244+ bool fUseSSE2 = ((fIntel && nFamily * 10000 + nModel >= 60026) ||245+ (fAMD && nFamily * 10000 + nModel >= 160010));246+247+ static bool fPrinted;248+ if (!fPrinted)249+ {250+ fPrinted = true;251+ printf("CPUID %08x family %d, model %d, stepping %d, fUseSSE2=%d\n", nBrand, nFamily, nModel, cpu.nStepping, fUseSSE2);252+ }253+ return fUseSSE2;254+}255+#else256+bool Detect128BitSSE2() { return false; }257+#endif258+259 int FormatHashBlocks(void* pbuffer, unsigned int len)260 {261 unsigned char* pdata = (unsigned char*)pbuffer;262@@ -2764,8 +2869,40 @@263 CryptoPP::SHA256::Transform((CryptoPP::word32*)pstate, (CryptoPP::word32*)pinput);264 }265 266-static const int NPAR = 32;267-extern void Double_BlockSHA256(const void* pin, void* pout, const void* pinit, unsigned int hash[8][NPAR], const void* init2);268+//269+// ScanHash scans nonces looking for a hash with at least some zero bits.270+// It operates on big endian data. Caller does the byte reversing.271+// All input buffers are 16-byte aligned. nNonce is usually preserved272+// between calls, but periodically or if nNonce is above 0xff000000,273+// the block is rebuilt and nNonce starts over at zero.274+//275+unsigned int ScanHash_CryptoPP(char* pmidstate, char* pblock, char* phash1, char* phash, unsigned int& nHashesDone)276+{277+ unsigned int& nNonce = *(unsigned int*)(pblock + 12);278+ for (;;)279+ {280+ // Crypto++ SHA-256281+ // Hash pblock using pmidstate as the starting state into282+ // preformatted buffer phash1, then hash phash1 into phash283+ nNonce++;284+ SHA256Transform(phash1, pblock, pmidstate);285+ SHA256Transform(phash, phash1, pSHA256InitState);286+287+ // Return the nonce if the hash has at least some zero bits,288+ // caller will check if it has enough to reach the target289+ if (((unsigned short*)phash)[14] == 0)290+ return nNonce;291+292+ // If nothing found after trying for a while, return -1293+ if ((nNonce & 0xffff) == 0)294+ {295+ nHashesDone = 0xffff+1;296+ return -1;297+ }298+ }299+}300+301+extern unsigned int ScanHash_4WaySSE2(char* pmidstate, char* pblock, char* phash1, char* phash, unsigned int& nHashesDone);302 303 304 305@@ -2774,6 +2911,9 @@306 {307 printf("BitcoinMiner started\n");308 SetThreadPriority(THREAD_PRIORITY_LOWEST);309+ bool f4WaySSE2 = Detect128BitSSE2();310+ if (mapArgs.count("-4way"))311+ f4WaySSE2 = (mapArgs["-4way"] != "0");312 313 CKey key;314 key.MakeNewKey();315@@ -2818,7 +2958,7 @@316 // Add our coinbase tx as first transaction317 pblock->vtx.push_back(txNew);318 319- // Collect the latest transactions into the block320+ // Collect memory pool transactions into the block321 int64 nFees = 0;322 CRITICAL_BLOCK(cs_main)323 CRITICAL_BLOCK(cs_mapTransactions)324@@ -2826,9 +2966,9 @@325 CTxDB txdb("r");326 map<uint256, CTxIndex> mapTestPool;327 vector<char> vfAlreadyAdded(mapTransactions.size());328+ uint64 nBlockSize = 1000;329+ int nBlockSigOps = 100;330 bool fFoundSomething = true;331- uint64 nBlockSize = 10000;332- int nBlockSigOps = 100;333 while (fFoundSomething)334 {335 fFoundSomething = false;336@@ -2841,7 +2981,7 @@337 if (tx.IsCoinBase() || !tx.IsFinal())338 continue;339 unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK);340- if (nBlockSize + nTxSize >= MAX_BLOCK_SIZE)341+ if (nBlockSize + nTxSize >= MAX_BLOCK_SIZE_GEN)342 continue;343 int nTxSigOps = tx.GetSigOpCount();344 if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS)345@@ -2864,7 +3004,7 @@346 }347 }348 pblock->nBits = nBits;349- pblock->vtx[0].vout[0].nValue = pblock->GetBlockValue(pindexPrev->nHeight+1, nFees);350+ pblock->vtx[0].vout[0].nValue = GetBlockValue(pindexPrev->nHeight+1, nFees);351 printf("Running BitcoinMiner with %d transactions in block\n", pblock->vtx.size());352 353 354@@ -2913,53 +3053,34 @@355 //356 // Search357 //358- bool f4WaySSE2 = mapArgs.count("-4way");359 int64 nStart = GetTime();360 uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();361 uint256 hashbuf[2];362 uint256& hash = *alignup<16>(hashbuf);363 loop364 {365+ unsigned int nHashesDone = 0;366+ unsigned int nNonceFound;367+368 #ifdef FOURWAYSSE2369 if (f4WaySSE2)370- {371- // tcatm's 4-way SSE2 SHA-256372- tmp.block.nNonce += NPAR;373- unsigned int thashbuf[9][NPAR];374- unsigned int (&thash)[9][NPAR] = *alignup<16>(&thashbuf);375- Double_BlockSHA256((char*)&tmp.block + 64, &tmp.hash1, &midstate, thash, pSHA256InitState);376- ((unsigned short*)&hash)[14] = 0xffff;377- for (int j = 0; j < NPAR; j++)378- {379- if (thash[7][j] == 0)380- {381- for (int i = 0; i < sizeof(hash)/4; i++)382- ((unsigned int*)&hash)[i] = thash[i][j];383- pblock->nNonce = ByteReverse(tmp.block.nNonce + j);384- }385- }386- }387+ // tcatm's 4-way 128-bit SSE2 SHA-256388+ nNonceFound = ScanHash_4WaySSE2((char*)&midstate, (char*)&tmp.block + 64, (char*)&tmp.hash1, (char*)&hash, nHashesDone);389 else390 #endif391- {392 // Crypto++ SHA-256393- tmp.block.nNonce++;394- SHA256Transform(&tmp.hash1, (char*)&tmp.block + 64, &midstate);395- SHA256Transform(&hash, &tmp.hash1, pSHA256InitState);396- }397-398- if (((unsigned short*)&hash)[14] == 0)399- {400- // Byte swap the result after preliminary check401+ nNonceFound = ScanHash_CryptoPP((char*)&midstate, (char*)&tmp.block + 64, (char*)&tmp.hash1, (char*)&hash, nHashesDone);402+403+ // Check if something found404+ if (nNonceFound != -1)405+ {406 for (int i = 0; i < sizeof(hash)/4; i++)407 ((unsigned int*)&hash)[i] = ByteReverse(((unsigned int*)&hash)[i]);408 409 if (hash <= hashTarget)410 {411-#ifdef FOURWAYSSE2412- if (!f4WaySSE2)413-#endif414- pblock->nNonce = ByteReverse(tmp.block.nNonce);415+ // Found a solution416+ pblock->nNonce = ByteReverse(nNonceFound);417 assert(hash == pblock->GetHash());418 419 //// debug print420@@ -2995,62 +3116,57 @@421 }422 }423 424- // Update nTime every few seconds425- const unsigned int nMask = 0xffff;426- const int nHashesPerCycle = (nMask+1);427- if ((tmp.block.nNonce & nMask) == 0)428- {429- // Meter hashes/sec430- static int nCycleCounter;431- if (nHPSTimerStart == 0)432+ // Meter hashes/sec433+ static int64 nHashCounter;434+ if (nHPSTimerStart == 0)435+ {436+ nHPSTimerStart = GetTimeMillis();437+ nHashCounter = 0;438+ }439+ else440+ nHashCounter += nHashesDone;441+ if (GetTimeMillis() - nHPSTimerStart > 4000)442+ {443+ static CCriticalSection cs;444+ CRITICAL_BLOCK(cs)445 {446- nHPSTimerStart = GetTimeMillis();447- nCycleCounter = 0;448- }449- else450- nCycleCounter++;451- if (GetTimeMillis() - nHPSTimerStart > 4000)452- {453- static CCriticalSection cs;454- CRITICAL_BLOCK(cs)455+ if (GetTimeMillis() - nHPSTimerStart > 4000)456 {457- if (GetTimeMillis() - nHPSTimerStart > 4000)458+ dHashesPerSec = 1000.0 * nHashCounter / (GetTimeMillis() - nHPSTimerStart);459+ nHPSTimerStart = GetTimeMillis();460+ nHashCounter = 0;461+ string strStatus = strprintf(" %.0f khash/s", dHashesPerSec/1000.0);462+ UIThreadCall(bind(CalledSetStatusBar, strStatus, 0));463+ static int64 nLogTime;464+ if (GetTime() - nLogTime > 30 * 60)465 {466- dHashesPerSec = 1000.0 * nHashesPerCycle * nCycleCounter / (GetTimeMillis() - nHPSTimerStart);467- nHPSTimerStart = GetTimeMillis();468- nCycleCounter = 0;469- string strStatus = strprintf(" %.0f khash/s", dHashesPerSec/1000.0);470- UIThreadCall(bind(CalledSetStatusBar, strStatus, 0));471- static int64 nLogTime;472- if (GetTime() - nLogTime > 30 * 60)473- {474- nLogTime = GetTime();475- printf("%s ", DateTimeStrFormat("%x %H:%M", GetTime()).c_str());476- printf("hashmeter %3d CPUs %6.0f khash/s\n", vnThreadsRunning[3], dHashesPerSec/1000.0);477- }478+ nLogTime = GetTime();479+ printf("%s ", DateTimeStrFormat("%x %H:%M", GetTime()).c_str());480+ printf("hashmeter %3d CPUs %6.0f khash/s\n", vnThreadsRunning[3], dHashesPerSec/1000.0);481 }482 }483 }484-485- // Check for stop or if block needs to be rebuilt486- if (fShutdown)487- return;488- if (!fGenerateBitcoins)489- return;490- if (fLimitProcessors && vnThreadsRunning[3] > nLimitProcessors)491- return;492- if (vNodes.empty())493- break;494- if (tmp.block.nNonce == 0)495- break;496- if (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60)497- break;498- if (pindexPrev != pindexBest)499- break;500-501- pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());502- tmp.block.nTime = ByteReverse(pblock->nTime);503- }504+ }505+506+ // Check for stop or if block needs to be rebuilt507+ if (fShutdown)508+ return;509+ if (!fGenerateBitcoins)510+ return;511+ if (fLimitProcessors && vnThreadsRunning[3] > nLimitProcessors)512+ return;513+ if (vNodes.empty())514+ break;515+ if (tmp.block.nNonce >= 0xff000000)516+ break;517+ if (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60)518+ break;519+ if (pindexPrev != pindexBest)520+ break;521+522+ // Update nTime every few seconds523+ pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());524+ tmp.block.nTime = ByteReverse(pblock->nTime);525 }526 }527 }528@@ -3090,6 +3206,8 @@529 CWalletTx* pcoin = &(*it).second;530 if (!pcoin->IsFinal() || pcoin->fSpent)531 continue;532+ if (pcoin->GetDepthInMainChain() < 1 && pcoin->GetDebit() <= 0)533+ continue;534 nTotal += pcoin->GetCredit(true);535 }536 }537@@ -3098,11 +3216,6 @@538 return nTotal;539 }540 541-542-int GetRandInt(int nMax)543-{544- return GetRand(nMax);545-}546 547 bool SelectCoins(int64 nTargetValue, set<CWalletTx*>& setCoinsRet)548 {549@@ -3125,6 +3238,8 @@550 foreach(CWalletTx* pcoin, vCoins)551 {552 if (!pcoin->IsFinal() || pcoin->fSpent)553+ continue;554+ if (pcoin->GetDepthInMainChain() < 1 && pcoin->GetDebit() <= 0)555 continue;556 int64 n = pcoin->GetCredit();557 if (n <= 0)558@@ -3247,7 +3362,8 @@559 wtxNew.vout.push_back(CTxOut(nValueOut, scriptPubKey));560 561 // Fill a vout back to self with any change562- if (nValueIn > nTotalValue)563+ int64 nChange = nValueIn - nTotalValue;564+ if (nChange >= CENT)565 {566 // Note: We use a new key here to keep it from being obvious which side is the change.567 // The drawback is that by not reusing a previous key, the change may be lost if a568@@ -3266,7 +3382,7 @@569 scriptChange.SetBitcoinAddress(keyRet.GetPubKey());570 else571 scriptChange << keyRet.GetPubKey() << OP_CHECKSIG;572- wtxNew.vout.push_back(CTxOut(nValueIn - nTotalValue, scriptChange));573+ wtxNew.vout.push_back(CTxOut(nChange, scriptChange));574 }575 576 // Fill a vout to the payee577@@ -3287,6 +3403,10 @@578 if (!SignSignature(*pcoin, wtxNew, nIn++))579 return false;580 581+ // Limit size582+ if (::GetSerializeSize(*(CTransaction*)&wtxNew, SER_NETWORK) >= MAX_BLOCK_SIZE_GEN/5)583+ return false;584+585 // Check that enough fee is included586 if (nFee < wtxNew.GetMinFee())587 {
main.h (modified)
1--- v0.3.12/main.h2+++ v0.3.13/main.h3@@ -15,6 +15,7 @@4 class CKeyItem;5 6 static const unsigned int MAX_BLOCK_SIZE = 1000000;7+static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;8 static const int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;9 static const int64 COIN = 100000000;10 static const int64 CENT = 1000000;11@@ -468,44 +469,6 @@12 return (vin.size() == 1 && vin[0].prevout.IsNull());13 }14 15- bool CheckTransaction() const16- {17- // Basic checks that don't depend on any context18- if (vin.empty() || vout.empty())19- return error("CTransaction::CheckTransaction() : vin or vout empty");20-21- // Size limits22- if (::GetSerializeSize(*this, SER_NETWORK) > MAX_SIZE)23- return error("CTransaction::CheckTransaction() : size limits failed");24-25- // Check for negative or overflow output values26- int64 nValueOut = 0;27- foreach(const CTxOut& txout, vout)28- {29- if (txout.nValue < 0)30- return error("CTransaction::CheckTransaction() : txout.nValue negative");31- if (txout.nValue > MAX_MONEY)32- return error("CTransaction::CheckTransaction() : txout.nValue too high");33- nValueOut += txout.nValue;34- if (!MoneyRange(nValueOut))35- return error("CTransaction::CheckTransaction() : txout total out of range");36- }37-38- if (IsCoinBase())39- {40- if (vin[0].scriptSig.size() < 2 || vin[0].scriptSig.size() > 100)41- return error("CTransaction::CheckTransaction() : coinbase script size");42- }43- else44- {45- foreach(const CTxIn& txin, vin)46- if (txin.prevout.IsNull())47- return error("CTransaction::CheckTransaction() : prevout is null");48- }49-50- return true;51- }52-53 int GetSigOpCount() const54 {55 int n = 0;56@@ -564,15 +527,16 @@57 {58 // Base fee is 1 cent per kilobyte59 unsigned int nBytes = ::GetSerializeSize(*this, SER_NETWORK);60+ unsigned int nNewBlockSize = nBlockSize + nBytes;61 int64 nMinFee = (1 + (int64)nBytes / 1000) * CENT;62 63- // Transactions under 60K are free as long as block size is under 80K64- // (about 27,000bc if made of 50bc inputs)65- if (nBytes < 60000 && nBlockSize < 80000)66+ // Transactions under 25K are free as long as block size is under 40K67+ // (about 11,000bc if made of 50bc inputs)68+ if (nBytes < 25000 && nNewBlockSize < 40000)69 nMinFee = 0;70 71- // Transactions under 3K are free as long as block size is under 200K72- if (nBytes < 3000 && nBlockSize < 200000)73+ // Transactions under 3K are free as long as block size is under 50K74+ if (nBytes < 3000 && nNewBlockSize < 50000)75 nMinFee = 0;76 77 // To limit dust spam, require a 0.01 fee if any output is less than 0.0178@@ -582,11 +546,15 @@79 nMinFee = CENT;80 81 // Raise the price as the block approaches full82- if (MAX_BLOCK_SIZE/2 <= nBlockSize && nBlockSize < MAX_BLOCK_SIZE)83- nMinFee *= MAX_BLOCK_SIZE / (MAX_BLOCK_SIZE - nBlockSize);84+ if (nBlockSize != 1 && nNewBlockSize >= MAX_BLOCK_SIZE_GEN/2)85+ {86+ if (nNewBlockSize >= MAX_BLOCK_SIZE_GEN)87+ return MAX_MONEY;88+ nMinFee *= MAX_BLOCK_SIZE_GEN / (MAX_BLOCK_SIZE_GEN - nNewBlockSize);89+ }90+91 if (!MoneyRange(nMinFee))92 nMinFee = MAX_MONEY;93-94 return nMinFee;95 }96 97@@ -649,20 +617,17 @@98 }99 100 101-102 bool DisconnectInputs(CTxDB& txdb);103 bool ConnectInputs(CTxDB& txdb, map<uint256, CTxIndex>& mapTestPool, CDiskTxPos posThisTx,104 CBlockIndex* pindexBlock, int64& nFees, bool fBlock, bool fMiner, int64 nMinFee=0);105 bool ClientConnectInputs();106-107+ bool CheckTransaction() const;108 bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL);109-110 bool AcceptToMemoryPool(bool fCheckInputs=true, bool* pfMissingInputs=NULL)111 {112 CTxDB txdb("r");113 return AcceptToMemoryPool(txdb, fCheckInputs, pfMissingInputs);114 }115-116 protected:117 bool AddToMemoryPoolUnchecked();118 public:119@@ -684,9 +649,7 @@120 int nIndex;121 122 // memory only123- mutable bool fMerkleVerified;124- mutable bool fGetCreditCached;125- mutable int64 nGetCreditCached;126+ mutable char fMerkleVerified;127 128 129 CMerkleTx()130@@ -704,8 +667,6 @@131 hashBlock = 0;132 nIndex = -1;133 fMerkleVerified = false;134- fGetCreditCached = false;135- nGetCreditCached = 0;136 }137 138 IMPLEMENT_SERIALIZE139@@ -716,20 +677,6 @@140 READWRITE(vMerkleBranch);141 READWRITE(nIndex);142 )143-144- int64 GetCredit(bool fUseCache=false) const145- {146- // Must wait until coinbase is safely deep enough in the chain before valuing it147- if (IsCoinBase() && GetBlocksToMaturity() > 0)148- return 0;149-150- // GetBalance can assume transactions in mapWallet won't change151- if (fUseCache && fGetCreditCached)152- return nGetCreditCached;153- nGetCreditCached = CTransaction::GetCredit();154- fGetCreditCached = true;155- return nGetCreditCached;156- }157 158 159 int SetMerkleBranch(const CBlock* pblock=NULL);160@@ -761,9 +708,16 @@161 char fSpent;162 //// probably need to sign the order info so know it came from payer163 164+ // memory only165+ mutable char fDebitCached;166+ mutable char fCreditCached;167+ mutable int64 nDebitCached;168+ mutable int64 nCreditCached;169+170 // memory only UI hints171 mutable unsigned int nTimeDisplayed;172 mutable int nLinesDisplayed;173+ mutable char fConfirmedDisplayed;174 175 176 CWalletTx()177@@ -787,6 +741,10 @@178 nTimeReceived = 0;179 fFromMe = false;180 fSpent = false;181+ fDebitCached = false;182+ fCreditCached = false;183+ nDebitCached = 0;184+ nCreditCached = 0;185 nTimeDisplayed = 0;186 nLinesDisplayed = 0;187 }188@@ -803,6 +761,31 @@189 READWRITE(fFromMe);190 READWRITE(fSpent);191 )192+193+ int64 GetDebit() const194+ {195+ if (vin.empty())196+ return 0;197+ if (fDebitCached)198+ return nDebitCached;199+ nDebitCached = CTransaction::GetDebit();200+ fDebitCached = true;201+ return nDebitCached;202+ }203+204+ int64 GetCredit(bool fUseCache=false) const205+ {206+ // Must wait until coinbase is safely deep enough in the chain before valuing it207+ if (IsCoinBase() && GetBlocksToMaturity() > 0)208+ return 0;209+210+ // GetBalance can assume transactions in mapWallet won't change211+ if (fUseCache && fCreditCached)212+ return nCreditCached;213+ nCreditCached = CTransaction::GetCredit();214+ fCreditCached = true;215+ return nCreditCached;216+ }217 218 bool WriteToDisk()219 {220@@ -1097,7 +1080,6 @@221 }222 223 224- int64 GetBlockValue(int nHeight, int64 nFees) const;225 bool DisconnectBlock(CTxDB& txdb, CBlockIndex* pindex);226 bool ConnectBlock(CTxDB& txdb, CBlockIndex* pindex);227 bool ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions=true);228@@ -1185,9 +1167,11 @@229 230 CBigNum GetBlockWork() const231 {232- if (CBigNum().SetCompact(nBits) <= 0)233+ CBigNum bnTarget;234+ bnTarget.SetCompact(nBits);235+ if (bnTarget <= 0)236 return 0;237- return (CBigNum(1)<<256) / (CBigNum().SetCompact(nBits)+1);238+ return (CBigNum(1)<<256) / (bnTarget+1);239 }240 241 bool IsInMainChain() const242@@ -1469,10 +1453,10 @@243 //// todo: add something to note what created it (user, getnewaddress, change)244 //// maybe should have a map<string, string> property map245 246- CWalletKey(int64 nTimeExpiresIn=0)247- {248- nTimeCreated = (nTimeExpiresIn ? GetTime() : 0);249- nTimeExpires = nTimeExpiresIn;250+ CWalletKey(int64 nExpires=0)251+ {252+ nTimeCreated = (nExpires ? GetTime() : 0);253+ nTimeExpires = nExpires;254 }255 256 IMPLEMENT_SERIALIZE
net.cpp (modified)
1--- v0.3.12/net.cpp2+++ v0.3.13/net.cpp3@@ -1160,9 +1160,13 @@4 pnode->Release();5 }6 7- // Wait and allow messages to bunch up8+ // Wait and allow messages to bunch up.9+ // Reduce vnThreadsRunning so StopNode has permission to exit while10+ // we're sleeping, but we must always check fShutdown after doing this.11 vnThreadsRunning[2]--;12 Sleep(100);13+ if (fRequestShutdown)14+ Shutdown(NULL);15 vnThreadsRunning[2]++;16 if (fShutdown)17 return;
rpc.cpp (modified)
1--- v0.3.12/rpc.cpp2+++ v0.3.13/rpc.cpp3@@ -783,8 +783,9 @@4 getline(stream, str);5 vector<string> vWords;6 boost::split(vWords, str, boost::is_any_of(" "));7- int nStatus = atoi(vWords[1].c_str());8- return nStatus;9+ if (vWords.size() < 2)10+ return 500;11+ return atoi(vWords[1].c_str());12 }13 14 int ReadHTTPHeader(tcp::iostream& stream, map<string, string>& mapHeadersRet)15@@ -916,6 +917,17 @@16 reply.push_back(Pair("error", error));17 reply.push_back(Pair("id", id));18 return write_string(Value(reply), false) + "\n";19+}20+21+bool ClientAllowed(const string& strAddress)22+{23+ if (strAddress == asio::ip::address_v4::loopback().to_string())24+ return true;25+ const vector<string>& vAllow = mapMultiArgs["-rpcallowip"];26+ foreach(string strAllow, vAllow)27+ if (WildcardMatch(strAddress, strAllow))28+ return true;29+ return false;30 }31 32 33@@ -962,7 +974,7 @@34 35 // Bind to loopback 127.0.0.1 so the socket can only be accessed locally36 boost::asio::io_service io_service;37- tcp::endpoint endpoint(boost::asio::ip::address_v4::loopback(), 8332);38+ tcp::endpoint endpoint(mapArgs.count("-rpcallowip") ? asio::ip::address_v4::any() : asio::ip::address_v4::loopback(), 8332);39 tcp::acceptor acceptor(io_service, endpoint);40 41 loop42@@ -976,8 +988,8 @@43 if (fShutdown)44 return;45 46- // Shouldn't be possible for anyone else to connect, but just in case47- if (peer.address().to_string() != "127.0.0.1")48+ // Restrict callers by IP49+ if (!ClientAllowed(peer.address().to_string()))50 continue;51 52 // Receive request53@@ -1090,7 +1102,7 @@54 GetConfigFile().c_str()));55 56 // Connect to localhost57- tcp::iostream stream("127.0.0.1", "8332");58+ tcp::iostream stream(GetArg("-rpcconnect", "127.0.0.1"), "8332");59 if (stream.fail())60 throw runtime_error("couldn't connect to server");61
script.cpp (modified)
1--- v0.3.12/script.cpp2+++ v0.3.13/script.cpp3@@ -778,6 +778,14 @@4 int nKeysCount = CastToBigNum(stacktop(-i)).getint();5 if (nKeysCount < 0)6 return false;7+ if (nBestHeight > 84000)8+ {9+ if (nKeysCount > 20)10+ return false;11+ nOpCount += nKeysCount;12+ if (nOpCount > 201)13+ return false;14+ }15 int ikey = ++i;16 i += nKeysCount;17 if (stack.size() < i)
serialize.h (modified)
1--- v0.3.12/serialize.h2+++ v0.3.13/serialize.h3@@ -22,8 +22,8 @@4 class CAutoFile;5 static const unsigned int MAX_SIZE = 0x02000000;6 7-static const int VERSION = 312;8-static const char* pszSubVer = ".1";9+static const int VERSION = 31300;10+static const char* pszSubVer = "";11 12 13 14@@ -85,13 +85,6 @@15 16 #define READWRITE(obj) (nSerSize += ::SerReadWrite(s, (obj), nType, nVersion, ser_action))17 18-#define READWRITEVER(obj) \19- do { \20- READWRITE((obj)); \21- if ((obj) == 10300) \22- (obj) = 300; \23- } while (false)24-25 26 27 28@@ -163,7 +156,7 @@29 //30 inline unsigned int GetSizeOfCompactSize(uint64 nSize)31 {32- if (nSize < UCHAR_MAX-2) return sizeof(unsigned char);33+ if (nSize < 253) return sizeof(unsigned char);34 else if (nSize <= USHRT_MAX) return sizeof(unsigned char) + sizeof(unsigned short);35 else if (nSize <= UINT_MAX) return sizeof(unsigned char) + sizeof(unsigned int);36 else return sizeof(unsigned char) + sizeof(uint64);37@@ -172,30 +165,31 @@38 template<typename Stream>39 void WriteCompactSize(Stream& os, uint64 nSize)40 {41- if (nSize < UCHAR_MAX-2)42+ if (nSize < 253)43 {44 unsigned char chSize = nSize;45 WRITEDATA(os, chSize);46 }47 else if (nSize <= USHRT_MAX)48 {49- unsigned char chSize = UCHAR_MAX-2;50+ unsigned char chSize = 253;51 unsigned short xSize = nSize;52 WRITEDATA(os, chSize);53 WRITEDATA(os, xSize);54 }55 else if (nSize <= UINT_MAX)56 {57- unsigned char chSize = UCHAR_MAX-1;58+ unsigned char chSize = 254;59 unsigned int xSize = nSize;60 WRITEDATA(os, chSize);61 WRITEDATA(os, xSize);62 }63 else64 {65- unsigned char chSize = UCHAR_MAX;66+ unsigned char chSize = 255;67+ uint64 xSize = nSize;68 WRITEDATA(os, chSize);69- WRITEDATA(os, nSize);70+ WRITEDATA(os, xSize);71 }72 return;73 }74@@ -206,27 +200,27 @@75 unsigned char chSize;76 READDATA(is, chSize);77 uint64 nSizeRet = 0;78- if (chSize < UCHAR_MAX-2)79+ if (chSize < 253)80 {81 nSizeRet = chSize;82 }83- else if (chSize == UCHAR_MAX-2)84- {85- unsigned short nSize;86- READDATA(is, nSize);87- nSizeRet = nSize;88- }89- else if (chSize == UCHAR_MAX-1)90- {91- unsigned int nSize;92- READDATA(is, nSize);93- nSizeRet = nSize;94+ else if (chSize == 253)95+ {96+ unsigned short xSize;97+ READDATA(is, xSize);98+ nSizeRet = xSize;99+ }100+ else if (chSize == 254)101+ {102+ unsigned int xSize;103+ READDATA(is, xSize);104+ nSizeRet = xSize;105 }106 else107 {108- uint64 nSize;109- READDATA(is, nSize);110- nSizeRet = nSize;111+ uint64 xSize;112+ READDATA(is, xSize);113+ nSizeRet = xSize;114 }115 if (nSizeRet > (uint64)MAX_SIZE)116 throw std::ios_base::failure("ReadCompactSize() : size too large");
setup.nsi (modified)
1--- v0.3.12/setup.nsi2+++ v0.3.13/setup.nsi3@@ -7,7 +7,7 @@4 5 # General Symbol Definitions6 !define REGKEY "SOFTWARE\$(^Name)"7-!define VERSION 0.3.128+!define VERSION 0.3.139 !define COMPANY "Bitcoin project"10 !define URL http://www.bitcoin.org/11 12@@ -42,12 +42,12 @@13 !insertmacro MUI_LANGUAGE English14 15 # Installer attributes16-OutFile bitcoin-0.3.12-win32-setup.exe17+OutFile bitcoin-0.3.13-win32-setup.exe18 InstallDir $PROGRAMFILES\Bitcoin19 CRCCheck on20 XPStyle on21 ShowInstDetails show22-VIProductVersion 0.3.12.023+VIProductVersion 0.3.13.024 VIAddVersionKey ProductName Bitcoin25 VIAddVersionKey ProductVersion "${VERSION}"26 VIAddVersionKey CompanyName "${COMPANY}"
sha256.cpp (modified)
1--- v0.3.12/sha256.cpp2+++ v0.3.13/sha256.cpp3@@ -2,6 +2,8 @@4 // Distributed under the MIT/X11 software license, see the accompanying5 // file license.txt or http://www.opensource.org/licenses/mit-license.php.6 7+// tcatm's 4-way 128-bit SSE2 SHA-2568+9 #ifdef FOURWAYSSE210 11 #include <string.h>12@@ -12,6 +14,8 @@13 #include <stdio.h>14 15 #define NPAR 3216+17+extern void DoubleBlockSHA256(const void* pin, void* pout, const void* pinit, unsigned int hash[8][NPAR], const void* init2);18 19 static const unsigned int sha256_consts[] = {20 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, /* 0 */21@@ -88,8 +92,54 @@22 #define dumpstate()23 #endif24 25-26-void Double_BlockSHA256(const void* pin, void* pad, const void *pre, unsigned int thash[9][NPAR], const void *init)27+// Align by increasing pointer, must have extra space at end of buffer28+template <size_t nBytes, typename T>29+T* alignup(T* p)30+{31+ union32+ {33+ T* ptr;34+ size_t n;35+ } u;36+ u.ptr = p;37+ u.n = (u.n + (nBytes-1)) & ~(nBytes-1);38+ return u.ptr;39+}40+41+static const unsigned int pSHA256InitState[8] =42+{0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};43+44+45+unsigned int ScanHash_4WaySSE2(char* pmidstate, char* pblock, char* phash1, char* phash, unsigned int& nHashesDone)46+{47+ unsigned int& nNonce = *(unsigned int*)(pblock + 12);48+ for (;;)49+ {50+ nNonce += NPAR;51+ unsigned int thashbuf[9][NPAR];52+ unsigned int (&thash)[9][NPAR] = *alignup<16>(&thashbuf);53+ DoubleBlockSHA256(pblock, phash1, pmidstate, thash, pSHA256InitState);54+55+ for (int j = 0; j < NPAR; j++)56+ {57+ if (thash[7][j] == 0)58+ {59+ for (int i = 0; i < 32/4; i++)60+ ((unsigned int*)phash)[i] = thash[i][j];61+ return nNonce + j;62+ }63+ }64+65+ if ((nNonce & 0xffff) == 0)66+ {67+ nHashesDone = 0xffff+1;68+ return -1;69+ }70+ }71+}72+73+74+void DoubleBlockSHA256(const void* pin, void* pad, const void *pre, unsigned int thash[9][NPAR], const void *init)75 {76 unsigned int* In = (unsigned int*)pin;77 unsigned int* Pad = (unsigned int*)pad;
ui.cpp (modified)
1--- v0.3.12/ui.cpp2+++ v0.3.13/ui.cpp3@@ -103,6 +103,18 @@4 return nIndex;5 }6 7+void SetItemTextColour(wxListCtrl* listCtrl, int nIndex, const wxColour& colour)8+{9+ // Repaint on Windows is more flickery if the colour has ever been set,10+ // so don't want to set it unless it's different. Default colour has11+ // alpha 0 transparent, so our colours don't match using operator==.12+ wxColour c1 = listCtrl->GetItemTextColour(nIndex);13+ if (!c1.IsOk())14+ c1 = wxColour(0,0,0);15+ if (colour.Red() != c1.Red() || colour.Green() != c1.Green() || colour.Blue() != c1.Blue())16+ listCtrl->SetItemTextColour(nIndex, colour);17+}18+19 void SetSelection(wxListCtrl* listCtrl, int nIndex)20 {21 int nSize = listCtrl->GetItemCount();22@@ -184,7 +196,7 @@23 24 bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent)25 {26- if (nFeeRequired == 0 || fDaemon)27+ if (nFeeRequired < CENT || fDaemon)28 return true;29 string strMessage = strprintf(30 _("This transaction is over the size limit. You can still send it for a fee of %s, "31@@ -434,7 +446,7 @@32 #endif33 }34 35-void CMainFrame::InsertLine(bool fNew, int nIndex, uint256 hashKey, string strSort, const wxString& str2, const wxString& str3, const wxString& str4, const wxString& str5, const wxString& str6)36+void CMainFrame::InsertLine(bool fNew, int nIndex, uint256 hashKey, string strSort, const wxColour& colour, const wxString& str2, const wxString& str3, const wxString& str4, const wxString& str5, const wxString& str6)37 {38 strSort = " " + strSort; // leading space to workaround wx2.9.0 ubuntu 9.10 bug39 long nData = *(long*)&hashKey; // where first char of hidden column is displayed40@@ -470,6 +482,7 @@41 m_listCtrl->SetItem(nIndex, 5, str5);42 m_listCtrl->SetItem(nIndex, 6, str6);43 m_listCtrl->SetItemData(nIndex, nData);44+ SetItemTextColour(m_listCtrl, nIndex, colour);45 }46 47 bool CMainFrame::DeleteLine(uint256 hashKey)48@@ -489,9 +502,10 @@49 return nIndex != -1;50 }51 52-string FormatTxStatus(const CWalletTx& wtx)53+string FormatTxStatus(const CWalletTx& wtx, bool& fConfirmed)54 {55 // Status56+ fConfirmed = false;57 if (!wtx.IsFinal())58 {59 if (wtx.nLockTime < 500000000)60@@ -502,6 +516,8 @@61 else62 {63 int nDepth = wtx.GetDepthInMainChain();64+ if (nDepth >= 1 || wtx.GetDebit() > 0)65+ fConfirmed = true;66 if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)67 return strprintf(_("%d/offline?"), nDepth);68 else if (nDepth < 6)69@@ -511,6 +527,12 @@70 }71 }72 73+string FormatTxStatus(const CWalletTx& wtx)74+{75+ bool fConfirmed;76+ return FormatTxStatus(wtx, fConfirmed);77+}78+79 string SingleLine(const string& strIn)80 {81 string strOut;82@@ -539,7 +561,10 @@83 int64 nDebit = wtx.GetDebit();84 int64 nNet = nCredit - nDebit;85 uint256 hash = wtx.GetHash();86- string strStatus = FormatTxStatus(wtx);87+ bool fConfirmed;88+ string strStatus = FormatTxStatus(wtx, fConfirmed);89+ wtx.fConfirmedDisplayed = fConfirmed;90+ wxColour colour = (fConfirmed ? wxColour(0,0,0) : wxColour(128,128,128));91 map<string, string> mapValue = wtx.mapValue;92 wtx.nLinesDisplayed = 1;93 nListViewUpdated++;94@@ -658,12 +683,16 @@95 }96 }97 98- InsertLine(fNew, nIndex, hash, strSort,99+ string strCredit = FormatMoney(nNet, true);100+ if (!fConfirmed)101+ strCredit = "[" + strCredit + "]";102+103+ InsertLine(fNew, nIndex, hash, strSort, colour,104 strStatus,105 nTime ? DateTimeStr(nTime) : "",106 SingleLine(strDescription),107 "",108- FormatMoney(nNet, true));109+ strCredit);110 }111 else112 {113@@ -679,7 +708,7 @@114 {115 // Payment to self116 int64 nValue = wtx.vout[0].nValue;117- InsertLine(fNew, nIndex, hash, strSort,118+ InsertLine(fNew, nIndex, hash, strSort, colour,119 strStatus,120 nTime ? DateTimeStr(nTime) : "",121 _("Payment to yourself"),122@@ -738,7 +767,7 @@123 nTxFee = 0;124 }125 126- InsertLine(fNew, nIndex, hash, strprintf("%s-%d", strSort.c_str(), nOut),127+ InsertLine(fNew, nIndex, hash, strprintf("%s-%d", strSort.c_str(), nOut), colour,128 strStatus,129 nTime ? DateTimeStr(nTime) : "",130 SingleLine(strDescription),131@@ -758,7 +787,7 @@132 foreach(const CTxIn& txin, wtx.vin)133 fAllMine = fAllMine && txin.IsMine();134 135- InsertLine(fNew, nIndex, hash, strSort,136+ InsertLine(fNew, nIndex, hash, strSort, colour,137 strStatus,138 nTime ? DateTimeStr(nTime) : "",139 "",140@@ -885,13 +914,17 @@141 continue;142 }143 CWalletTx& wtx = (*mi).second;144- if (wtx.IsCoinBase() || wtx.GetTxTime() != wtx.nTimeDisplayed)145+ bool fConfirmed;146+ string strStatus = FormatTxStatus(wtx, fConfirmed);147+ if (wtx.IsCoinBase() || wtx.GetTxTime() != wtx.nTimeDisplayed || fConfirmed != wtx.fConfirmedDisplayed)148 {149 if (!InsertTransaction(wtx, false, nIndex))150 m_listCtrl->DeleteItem(nIndex--);151 }152 else153- m_listCtrl->SetItem(nIndex, 2, FormatTxStatus(wtx));154+ {155+ m_listCtrl->SetItem(nIndex, 2, strStatus);156+ }157 }158 }159 }160@@ -1772,7 +1805,7 @@161 162 CAboutDialog::CAboutDialog(wxWindow* parent) : CAboutDialogBase(parent)163 {164- m_staticTextVersion->SetLabel(strprintf(_("version %d.%d.%d%s beta"), VERSION/10000, (VERSION/100)%100, VERSION%100, pszSubVer));165+ m_staticTextVersion->SetLabel(strprintf(_("version %s%s beta"), FormatVersion(VERSION).c_str(), pszSubVer));166 167 // Change (c) into UTF-8 or ANSI copyright symbol168 wxString str = m_staticTextMain->GetLabel();169@@ -2186,8 +2219,12 @@170 if (nRet > 0)171 {172 string strMessage;173- vRecv >> strMessage;174- Error(_("Transfer was not accepted"));175+ if (!vRecv.empty())176+ vRecv >> strMessage;177+ if (nRet == 2)178+ Error(_("Recipient is not accepting transactions sent by IP address"));179+ else180+ Error(_("Transfer was not accepted"));181 //// todo: enlarge the window and enable a hidden white box to put seller's message182 return;183 }
ui.h (modified)
1--- v0.3.12/ui.h2+++ v0.3.13/ui.h3@@ -11,7 +11,6 @@4 5 6 void HandleCtrlA(wxKeyEvent& event);7-string FormatTxStatus(const CWalletTx& wtx);8 void UIThreadCall(boost::function0<void>);9 int ThreadSafeMessageBox(const string& message, const string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);10 bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent);11@@ -96,7 +95,7 @@12 13 void OnUIThreadCall(wxCommandEvent& event);14 int GetSortIndex(const string& strSort);15- void InsertLine(bool fNew, int nIndex, uint256 hashKey, string strSort, const wxString& str1, const wxString& str2, const wxString& str3, const wxString& str4, const wxString& str5);16+ void InsertLine(bool fNew, int nIndex, uint256 hashKey, string strSort, const wxColour& colour, const wxString& str1, const wxString& str2, const wxString& str3, const wxString& str4, const wxString& str5);17 bool DeleteLine(uint256 hashKey);18 bool InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex=-1);19 void RefreshListCtrl();
util.cpp (modified)
1--- v0.3.12/util.cpp2+++ v0.3.13/util.cpp3@@ -11,6 +11,7 @@4 bool fPrintToConsole = false;5 bool fPrintToDebugger = false;6 char pszSetDataDir[MAX_PATH] = "";7+bool fRequestShutdown = false;8 bool fShutdown = false;9 bool fDaemon = false;10 bool fCommandLine = false;11@@ -124,6 +125,11 @@12 RAND_bytes((unsigned char*)&nRand, sizeof(nRand));13 while (nRand >= nRange);14 return (nRand % nMax);15+}16+17+int GetRandInt(int nMax)18+{19+ return GetRand(nMax);20 }21 22 23@@ -404,7 +410,7 @@24 return vch;25 }26 27-vector<unsigned char> ParseHex(const std::string& str)28+vector<unsigned char> ParseHex(const string& str)29 {30 return ParseHex(str.c_str());31 }32@@ -472,6 +478,34 @@33 }34 35 36+bool WildcardMatch(const char* psz, const char* mask)37+{38+ loop39+ {40+ switch (*mask)41+ {42+ case '\0':43+ return (*psz == '\0');44+ case '*':45+ return WildcardMatch(psz, mask+1) || (*psz && WildcardMatch(psz+1, mask));46+ case '?':47+ if (*psz == '\0')48+ return false;49+ break;50+ default:51+ if (*psz != *mask)52+ return false;53+ break;54+ }55+ psz++;56+ mask++;57+ }58+}59+60+bool WildcardMatch(const string& str, const string& mask)61+{62+ return WildcardMatch(str.c_str(), mask.c_str());63+}64 65 66 67@@ -649,7 +683,7 @@68 string GetConfigFile()69 {70 namespace fs = boost::filesystem;71- fs::path pathConfig(mapArgs.count("-conf") ? mapArgs["-conf"] : string("bitcoin.conf"));72+ fs::path pathConfig(GetArg("-conf", "bitcoin.conf"));73 if (!pathConfig.is_complete())74 pathConfig = fs::path(GetDataDir()) / pathConfig;75 return pathConfig.string();76@@ -717,13 +751,10 @@77 78 //79 // "Never go to sea with two chronometers; take one or three."80-// Our three chronometers are:81+// Our three time sources are:82 // - System clock83-// - Median of other server's clocks84-// - NTP servers85-//86-// note: NTP isn't implemented yet, so until then we just use the median87-// of other nodes clocks to correct ours.88+// - Median of other nodes's clocks89+// - The user (asking the user to fix the system clock if the first two disagree)90 //91 int64 GetTime()92 {93@@ -767,7 +798,7 @@94 // If nobody else has the same time as us, give a warning95 bool fMatch = false;96 foreach(int64 nOffset, vTimeOffsets)97- if (nOffset != 0 && abs64(nOffset) < 10 * 60)98+ if (nOffset != 0 && abs64(nOffset) < 5 * 60)99 fMatch = true;100 static bool fDone;101 if (!fMatch && !fDone)
util.h (modified)
1--- v0.3.12/util.h2+++ v0.3.13/util.h3@@ -140,6 +140,7 @@4 extern bool fPrintToConsole;5 extern bool fPrintToDebugger;6 extern char pszSetDataDir[MAX_PATH];7+extern bool fRequestShutdown;8 extern bool fShutdown;9 extern bool fDaemon;10 extern bool fCommandLine;11@@ -159,9 +160,11 @@12 bool ParseMoney(const string& str, int64& nRet);13 bool ParseMoney(const char* pszIn, int64& nRet);14 vector<unsigned char> ParseHex(const char* psz);15-vector<unsigned char> ParseHex(const std::string& str);16+vector<unsigned char> ParseHex(const string& str);17 void ParseParameters(int argc, char* argv[]);18 const char* wxGetTranslation(const char* psz);19+bool WildcardMatch(const char* psz, const char* mask);20+bool WildcardMatch(const string& str, const string& mask);21 int GetFilesize(FILE* file);22 void GetDataDir(char* pszDirRet);23 string GetConfigFile();24@@ -172,6 +175,7 @@25 string GetDefaultDataDir();26 string GetDataDir();27 void ShrinkDebugFile();28+int GetRandInt(int nMax);29 uint64 GetRand(uint64 nMax);30 int64 GetTime();31 int64 GetAdjustedTime();32@@ -396,6 +400,28 @@33 #else34 return c == '-';35 #endif36+}37+38+inline string GetArg(const string& strArg, const string& strDefault)39+{40+ if (mapArgs.count(strArg))41+ return mapArgs[strArg];42+ return strDefault;43+}44+45+inline int64 GetArg(const string& strArg, int64 nDefault)46+{47+ if (mapArgs.count(strArg))48+ return atoi64(mapArgs[strArg]);49+ return nDefault;50+}51+52+inline string FormatVersion(int nVersion)53+{54+ if (nVersion%100 == 0)55+ return strprintf("%d.%d.%d", nVersion/1000000, (nVersion/10000)%100, (nVersion/100)%100);56+ else57+ return strprintf("%d.%d.%d.%d", nVersion/1000000, (nVersion/10000)%100, (nVersion/100)%100, nVersion%100);58 }59 60
