Research
Timechain
Search Donate
Sponsors
Cake Wallet, private Bitcoin and Monero walletSideShift.ai, no-signup crypto exchangeOrangeRock, non-custodial bitcoin spot and perps tradingBraiins Hashpower, buy and sell Bitcoin hashrateeCash.com
What changed

Bitcoin v0.3.17 → v0.3.18

15 files · +639 · −193 · 822018013 · 2010-12-08 · s_nakamoto

Release commit message: -- version 0.3.18 release

Previous diff: v0.3.15 → v0.3.17. Next: v0.3.18 → v0.3.19.

db.cpp (modified)

1--- v0.3.17/db.cpp2+++ v0.3.18/db.cpp3@@ -132,6 +132,8 @@4 5     // Flush database activity from memory pool to disk log6     unsigned int nMinutes = 0;7+    if (fReadOnly)8+        nMinutes = 1;9     if (strFile == "addr.dat")10         nMinutes = 2;11     if (strFile == "blkindex.dat" && IsInitialBlockDownload() && nBestHeight % 500 != 0)12@@ -592,23 +594,35 @@13 14 bool CWalletDB::WriteAccountingEntry(const string& strAccount, const CAccountingEntry& acentry)15 {16-    return Write(make_pair(string("acentry"), make_pair(strAccount, ++nAccountingEntryNumber)), acentry);17+    return Write(make_tuple(string("acentry"), strAccount, ++nAccountingEntryNumber), acentry);18 }19 20 int64 CWalletDB::GetAccountCreditDebit(const string& strAccount)21+{22+    list<CAccountingEntry> entries;23+    ListAccountCreditDebit(strAccount, entries);24+25+    int64 nCreditDebit = 0;26+    foreach (const CAccountingEntry& entry, entries)27+        nCreditDebit += entry.nCreditDebit;28+29+    return nCreditDebit;30+}31+32+void CWalletDB::ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& entries)33 {34     int64 nCreditDebit = 0;35 36     Dbc* pcursor = GetCursor();37     if (!pcursor)38-        throw runtime_error("CWalletDB::GetAccountCreditDebit() : cannot create DB cursor");39+        throw runtime_error("CWalletDB::ListAccountCreditDebit() : cannot create DB cursor");40     unsigned int fFlags = DB_SET_RANGE;41     loop42     {43         // Read next record44         CDataStream ssKey;45         if (fFlags == DB_SET_RANGE)46-            ssKey << make_pair(string("acentry"), make_pair(strAccount, uint64(0)));47+            ssKey << make_tuple(string("acentry"), strAccount, uint64(0));48         CDataStream ssValue;49         int ret = ReadAtCursor(pcursor, ssKey, ssValue, fFlags);50         fFlags = DB_NEXT;51@@ -617,7 +631,7 @@52         else if (ret != 0)53         {54             pcursor->close();55-            throw runtime_error("CWalletDB::GetAccountCreditDebit() : error scanning DB");56+            throw runtime_error("CWalletDB::ListAccountCreditDebit() : error scanning DB");57         }58 59         // Unserialize60@@ -632,17 +646,17 @@61 62         CAccountingEntry acentry;63         ssValue >> acentry;64-        nCreditDebit += acentry.nCreditDebit;65+        entries.push_back(acentry);66     }67 68     pcursor->close();69-    return nCreditDebit;70 }71 72 bool CWalletDB::LoadWallet()73 {74     vchDefaultKey.clear();75     int nFileVersion = 0;76+    vector<uint256> vWalletUpgrade;77 78     // Modify defaults79 #ifndef __WXMSW__80@@ -691,6 +705,25 @@81 82                 if (wtx.GetHash() != hash)83                     printf("Error in wallet.dat, hash mismatch\n");84+85+                // Undo serialize changes in 3160086+                if (31404 <= wtx.fTimeReceivedIsTxTime && wtx.fTimeReceivedIsTxTime <= 31703)87+                {88+                    if (!ssValue.empty())89+                    {90+                        char fTmp;91+                        char fUnused;92+                        ssValue >> fTmp >> fUnused >> wtx.strFromAccount;93+                        printf("LoadWallet() upgrading tx ver=%d %d '%s' %s\n", wtx.fTimeReceivedIsTxTime, fTmp, wtx.strFromAccount.c_str(), hash.ToString().c_str());94+                        wtx.fTimeReceivedIsTxTime = fTmp;95+                    }96+                    else97+                    {98+                        printf("LoadWallet() repairing tx ver=%d %s\n", wtx.fTimeReceivedIsTxTime, hash.ToString().c_str());99+                        wtx.fTimeReceivedIsTxTime = 0;100+                    }101+                    vWalletUpgrade.push_back(hash);102+                }103 104                 //// debug print105                 //printf("LoadWallet  %s\n", wtx.GetHash().ToString().c_str());106@@ -761,6 +794,9 @@107         pcursor->close();108     }109 110+    foreach(uint256 hash, vWalletUpgrade)111+        WriteTx(hash, mapWallet[hash]);112+113     printf("nFileVersion = %d\n", nFileVersion);114     printf("fGenerateBitcoins = %d\n", fGenerateBitcoins);115     printf("nTransactionFee = %"PRI64d"\n", nTransactionFee);116@@ -780,6 +816,7 @@117 118         WriteVersion(VERSION);119     }120+121 122     return true;123 }

db.h (modified)

1--- v0.3.17/db.h2+++ v0.3.18/db.h3@@ -265,7 +265,7 @@4 class CTxDB : public CDB5 {6 public:7-    CTxDB(const char* pszMode="r+") : CDB(!fClient ? "blkindex.dat" : NULL, pszMode) { }8+    CTxDB(const char* pszMode="r+") : CDB("blkindex.dat", pszMode) { }9 private:10     CTxDB(const CTxDB&);11     void operator=(const CTxDB&);12@@ -435,6 +435,7 @@13     bool WriteAccount(const string& strAccount, const CAccount& account);14     bool WriteAccountingEntry(const string& strAccount, const CAccountingEntry& acentry);15     int64 GetAccountCreditDebit(const string& strAccount);16+    void ListAccountCreditDebit(const string& strAccount, list<CAccountingEntry>& acentries);17 18     bool LoadWallet();19 protected:

init.cpp (modified)

1--- v0.3.17/init.cpp2+++ v0.3.18/init.cpp3@@ -206,14 +206,11 @@4         return false;5     }6 7-    if (mapArgs.count("-debug"))8-        fDebug = true;9-10-    if (mapArgs.count("-printtodebugger"))11-        fPrintToDebugger = true;12-13-    if (mapArgs.count("-testnet"))14-        fTestNet = true;15+    fDebug = GetBoolArg("-debug");16+17+    fPrintToDebugger = GetBoolArg("-printtodebugger");18+19+    fTestNet = GetBoolArg("-testnet");20 21     if (fCommandLine)22     {23@@ -232,7 +229,7 @@24 #endif25     printf("Default data directory %s\n", GetDefaultDataDir().c_str());26 27-    if (mapArgs.count("-loadblockindextest"))28+    if (GetBoolArg("-loadblockindextest"))29     {30         CTxDB txdb("r");31         txdb.LoadBlockIndex();32@@ -348,7 +345,7 @@33     //34     // Parameters35     //36-    if (mapArgs.count("-printblockindex") || mapArgs.count("-printblocktree"))37+    if (GetBoolArg("-printblockindex") || GetBoolArg("-printblocktree"))38     {39         PrintBlockTree();40         return false;41@@ -377,13 +374,7 @@42         return false;43     }44 45-    if (mapArgs.count("-gen"))46-    {47-        if (mapArgs["-gen"].empty())48-            fGenerateBitcoins = true;49-        else50-            fGenerateBitcoins = (atoi(mapArgs["-gen"].c_str()) != 0);51-    }52+    fGenerateBitcoins = GetBoolArg("-gen");53 54     if (mapArgs.count("-proxy"))55     {56@@ -434,7 +425,7 @@57     if (!CreateThread(StartNode, NULL))58         wxMessageBox("Error: CreateThread(StartNode) failed", "Bitcoin");59 60-    if (mapArgs.count("-server") || fDaemon)61+    if (GetBoolArg("-server") || fDaemon)62         CreateThread(ThreadRPCServer, NULL);63 64 #if defined(__WXMSW__) && defined(GUI)

irc.cpp (modified)

1--- v0.3.17/irc.cpp2+++ v0.3.18/irc.cpp3@@ -173,6 +173,68 @@4     return true;5 }6 7+bool RecvCodeLine(SOCKET hSocket, const char* psz1, string& strRet)8+{9+    strRet.clear();10+    loop11+    {12+        string strLine;13+        if (!RecvLineIRC(hSocket, strLine))14+            return false;15+16+        vector<string> vWords;17+        ParseString(strLine, ' ', vWords);18+        if (vWords.size() < 2)19+            continue;20+21+        if (vWords[1] == psz1)22+        {23+            printf("IRC %s\n", strLine.c_str());24+            strRet = strLine;25+            return true;26+        }27+    }28+}29+30+bool GetIPFromIRC(SOCKET hSocket, string strMyName, unsigned int& ipRet)31+{32+    Send(hSocket, strprintf("USERHOST %s\r", strMyName.c_str()).c_str());33+34+    string strLine;35+    if (!RecvCodeLine(hSocket, "302", strLine))36+        return false;37+38+    vector<string> vWords;39+    ParseString(strLine, ' ', vWords);40+    if (vWords.size() < 4)41+        return false;42+43+    string str = vWords[3];44+    if (str.rfind("@") == string::npos)45+        return false;46+    string strHost = str.substr(str.rfind("@")+1);47+48+    unsigned int a=0, b=0, c=0, d=0;49+    if (sscanf(strHost.c_str(), "%u.%u.%u.%u", &a, &b, &c, &d) == 4 &&50+        inet_addr(strHost.c_str()) != INADDR_NONE)51+    {52+        printf("GetIPFromIRC() userhost is IP %s\n", strHost.c_str());53+        ipRet = CAddress(strHost).ip;54+    }55+    else56+    {57+        printf("GetIPFromIRC() got userhost %s\n", strHost.c_str());58+        if (fUseProxy)59+            return false;60+        struct hostent* phostent = gethostbyname(strHost.c_str());61+        if (!phostent || !phostent->h_addr_list || !phostent->h_addr_list[0])62+            return false;63+        ipRet = *(u_long*)phostent->h_addr_list[0];64+    }65+66+    return true;67+}68+69 70 71 void ThreadIRCSeed(void* parg)72@@ -194,7 +256,7 @@73 {74     if (mapArgs.count("-connect"))75         return;76-    if (mapArgs.count("-noirc"))77+    if (GetBoolArg("-noirc"))78         return;79     printf("ThreadIRCSeed started\n");80     int nErrorWait = 10;81@@ -264,6 +326,20 @@82                 return;83         }84         Sleep(500);85+86+        // Get my external IP from IRC server87+        CAddress addrFromIRC;88+        if (GetIPFromIRC(hSocket, strMyName, addrFromIRC.ip))89+        {90+            // Just using it as a backup for now91+            printf("GetIPFromIRC() returned %s\n", addrFromIRC.ToStringIP().c_str());92+            if (addrFromIRC.IsRoutable() && !fUseProxy && !addrLocalHost.IsRoutable())93+            {94+                addrLocalHost.ip = addrFromIRC.ip;95+                strMyName = EncodeAddress(addrLocalHost);96+                Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());97+            }98+        }99 100         Send(hSocket, fTestNet ? "JOIN #bitcoinTEST\r" : "JOIN #bitcoin\r");101         Send(hSocket, fTestNet ? "WHO #bitcoinTEST\r"  : "WHO #bitcoin\r");

main.cpp (modified)

1--- v0.3.17/main.cpp2+++ v0.3.18/main.cpp3@@ -572,7 +572,7 @@4         return error("AcceptToMemoryPool() : not accepting nLockTime beyond 2038 yet");5 6     // Rather not work on nonstandard transactions7-    if (GetSigOpCount() > 2 || ::GetSerializeSize(*this, SER_NETWORK) < 100)8+    if (!IsStandard() || GetSigOpCount() > 2 || ::GetSerializeSize(*this, SER_NETWORK) < 100)9         return error("AcceptToMemoryPool() : nonstandard transaction");10 11     // Do we already have it?12@@ -870,6 +870,11 @@13 14 bool CBlock::ReadFromDisk(const CBlockIndex* pindex, bool fReadTransactions)15 {16+    if (!fReadTransactions)17+    {18+        *this = pindex->GetBlockHeader();19+        return true;20+    }21     if (!ReadFromDisk(pindex->nFile, pindex->nBlockPos, fReadTransactions))22         return false;23     if (GetHash() != pindex->GetBlockHash())24@@ -1425,7 +1430,10 @@25     pindexNew->bnChainWork = (pindexNew->pprev ? pindexNew->pprev->bnChainWork : 0) + pindexNew->GetBlockWork();26 27     CTxDB txdb;28+    txdb.TxnBegin();29     txdb.WriteBlockIndex(CDiskBlockIndex(pindexNew));30+    if (!txdb.TxnCommit())31+        return false;32 33     // New best34     if (pindexNew->bnChainWork > bnBestChainWork)35@@ -1529,9 +1537,9 @@36     // Write block to history file37     if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK)))38         return error("AcceptBlock() : out of disk space");39-    unsigned int nFile;40-    unsigned int nBlockPos;41-    if (!WriteToDisk(!fClient, nFile, nBlockPos))42+    unsigned int nFile = -1;43+    unsigned int nBlockPos = 0;44+    if (!WriteToDisk(nFile, nBlockPos))45         return error("AcceptBlock() : WriteToDisk failed");46     if (!AddToBlockIndex(nFile, nBlockPos))47         return error("AcceptBlock() : AddToBlockIndex failed");48@@ -1777,7 +1785,7 @@49         // Start new block file50         unsigned int nFile;51         unsigned int nBlockPos;52-        if (!block.WriteToDisk(!fClient, nFile, nBlockPos))53+        if (!block.WriteToDisk(nFile, nBlockPos))54             return error("LoadBlockIndex() : writing genesis block to disk failed");55         if (!block.AddToBlockIndex(nFile, nBlockPos))56             return error("LoadBlockIndex() : genesis block not accepted");57@@ -1891,7 +1899,7 @@58     int nPriority = 0;59     string strStatusBar;60     string strRPC;61-    if (mapArgs.count("-testsafemode"))62+    if (GetBoolArg("-testsafemode"))63         strRPC = "test";64 65     // Misc warnings like out of disk space and clock is wrong66@@ -2181,11 +2189,6 @@67         }68 69         pfrom->fClient = !(pfrom->nServices & NODE_NETWORK);70-        if (pfrom->fClient)71-        {72-            pfrom->vSend.nType |= SER_BLOCKHEADERONLY;73-            pfrom->vRecv.nType |= SER_BLOCKHEADERONLY;74-        }75 76         AddTimeData(pfrom->addr.ip, nTime);77 78@@ -2359,9 +2362,8 @@79                 map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(inv.hash);80                 if (mi != mapBlockIndex.end())81                 {82-                    //// could optimize this to send header straight from blockindex for client83                     CBlock block;84-                    block.ReadFromDisk((*mi).second, !pfrom->fClient);85+                    block.ReadFromDisk((*mi).second);86                     pfrom->PushMessage("block", block);87 88                     // Trigger them to send a getblocks request for the next batch of inventory89@@ -2405,7 +2407,7 @@90         uint256 hashStop;91         vRecv >> locator >> hashStop;92 93-        // Find the first block the caller has in the main chain94+        // Find the last block the caller has in the main chain95         CBlockIndex* pindex = locator.GetBlockIndex();96 97         // Send the rest of the chain98@@ -2430,6 +2432,42 @@99                 break;100             }101         }102+    }103+104+105+    else if (strCommand == "getheaders")106+    {107+        CBlockLocator locator;108+        uint256 hashStop;109+        vRecv >> locator >> hashStop;110+111+        CBlockIndex* pindex = NULL;112+        if (locator.IsNull())113+        {114+            // If locator is null, return the hashStop block115+            map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashStop);116+            if (mi == mapBlockIndex.end())117+                return true;118+            pindex = (*mi).second;119+        }120+        else121+        {122+            // Find the last block the caller has in the main chain123+            pindex = locator.GetBlockIndex();124+            if (pindex)125+                pindex = pindex->pnext;126+        }127+128+        vector<CBlock> vHeaders;129+        int nLimit = 2000 + locator.GetDistanceBack();130+        printf("getheaders %d to %s limit %d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString().substr(0,20).c_str(), nLimit);131+        for (; pindex; pindex = pindex->pnext)132+        {133+            vHeaders.push_back(pindex->GetBlockHeader());134+            if (--nLimit <= 0 || pindex->GetBlockHash() == hashStop)135+                break;136+        }137+        pfrom->PushMessage("headers", vHeaders);138     }139 140 141@@ -2488,17 +2526,16 @@142 143     else if (strCommand == "block")144     {145-        auto_ptr<CBlock> pblock(new CBlock);146-        vRecv >> *pblock;147-148-        //// debug print149-        printf("received block %s\n", pblock->GetHash().ToString().substr(0,20).c_str());150-        // pblock->print();151-152-        CInv inv(MSG_BLOCK, pblock->GetHash());153+        CBlock block;154+        vRecv >> block;155+156+        printf("received block %s\n", block.GetHash().ToString().substr(0,20).c_str());157+        // block.print();158+159+        CInv inv(MSG_BLOCK, block.GetHash());160         pfrom->AddInventoryKnown(inv);161 162-        if (ProcessBlock(pfrom, pblock.get()))163+        if (ProcessBlock(pfrom, &block))164             mapAlreadyAskedFor.erase(inv);165     }166 167@@ -2530,14 +2567,16 @@168     else if (strCommand == "checkorder")169     {170         uint256 hashReply;171-        CWalletTx order;172-        vRecv >> hashReply >> order;173-174-        if (!mapArgs.count("-allowreceivebyip") || mapArgs["-allowreceivebyip"] == "0")175+        vRecv >> hashReply;176+177+        if (!GetBoolArg("-allowreceivebyip"))178         {179             pfrom->PushMessage("reply", hashReply, (int)2, string(""));180             return true;181         }182+183+        CWalletTx order;184+        vRecv >> order;185 186         /// we have a chance to check the order here187 188@@ -2555,15 +2594,17 @@189     else if (strCommand == "submitorder")190     {191         uint256 hashReply;192-        CWalletTx wtxNew;193-        vRecv >> hashReply >> wtxNew;194-        wtxNew.fFromMe = false;195-196-        if (!mapArgs.count("-allowreceivebyip") || mapArgs["-allowreceivebyip"] == "0")197+        vRecv >> hashReply;198+199+        if (!GetBoolArg("-allowreceivebyip"))200         {201             pfrom->PushMessage("reply", hashReply, (int)2);202             return true;203         }204+205+        CWalletTx wtxNew;206+        vRecv >> wtxNew;207+        wtxNew.fFromMe = false;208 209         // Broadcast210         if (!wtxNew.AcceptWalletTransaction())211@@ -3123,7 +3164,7 @@212 213                 dPriority += (double)nValueIn * nConf;214 215-                if (fDebug && mapArgs.count("-printpriority"))216+                if (fDebug && GetBoolArg("-printpriority"))217                     printf("priority     nValueIn=%-12I64d nConf=%-5d dPriority=%-20.1f\n", nValueIn, nConf, dPriority);218             }219 220@@ -3135,7 +3176,7 @@221             else222                 mapPriority.insert(make_pair(-dPriority, &(*mi).second));223 224-            if (fDebug && mapArgs.count("-printpriority"))225+            if (fDebug && GetBoolArg("-printpriority"))226             {227                 printf("priority %-20.1f %s\n%s", dPriority, tx.GetHash().ToString().substr(0,10).c_str(), tx.ToString().c_str());228                 if (porphan)229@@ -3312,7 +3353,7 @@230     SetThreadPriority(THREAD_PRIORITY_LOWEST);231     bool f4WaySSE2 = Detect128BitSSE2();232     if (mapArgs.count("-4way"))233-        f4WaySSE2 = (mapArgs["-4way"] != "0");234+        f4WaySSE2 = GetBoolArg(mapArgs["-4way"]);235 236     // Each thread has its own key and counter237     CReserveKey reservekey;238@@ -3492,7 +3533,7 @@239             CWalletTx* pcoin = &(*it).second;240             if (!pcoin->IsFinal() || pcoin->fSpent || !pcoin->IsConfirmed())241                 continue;242-            nTotal += pcoin->GetCredit(true);243+            nTotal += pcoin->GetCredit();244         }245     }246 

main.h (modified)

1--- v0.3.17/main.h2+++ v0.3.18/main.h3@@ -345,9 +345,25 @@4     {5         if (!MoneyRange(nValue))6             throw runtime_error("CTxOut::GetCredit() : value out of range");7-        if (IsMine())8-            return nValue;9-        return 0;10+        return (IsMine() ? nValue : 0);11+    }12+13+    bool IsChange() const14+    {15+        // On a debit transaction, a txout that's mine but isn't in the address book is change16+        vector<unsigned char> vchPubKey;17+        if (ExtractPubKey(scriptPubKey, true, vchPubKey))18+            CRITICAL_BLOCK(cs_mapAddressBook)19+                if (!mapAddressBook.count(PubKeyToAddress(vchPubKey)))20+                    return true;21+        return false;22+    }23+24+    int64 GetChange() const25+    {26+        if (!MoneyRange(nValue))27+            throw runtime_error("CTxOut::GetChange() : value out of range");28+        return (IsChange() ? nValue : 0);29     }30 31     friend bool operator==(const CTxOut& a, const CTxOut& b)32@@ -483,6 +499,17 @@33         return n;34     }35 36+    bool IsStandard() const37+    {38+        foreach(const CTxIn& txin, vin)39+            if (!txin.scriptSig.IsPushOnly())40+                return error("nonstandard txin: %s", txin.scriptSig.ToString().c_str());41+        foreach(const CTxOut& txout, vout)42+            if (!::IsStandard(txout.scriptPubKey))43+                return error("nonstandard txout: %s", txout.scriptPubKey.ToString().c_str());44+        return true;45+    }46+47     bool IsMine() const48     {49         foreach(const CTxOut& txout, vout)50@@ -518,6 +545,20 @@51                 throw runtime_error("CTransaction::GetCredit() : value out of range");52         }53         return nCredit;54+    }55+56+    int64 GetChange() const57+    {58+        if (IsCoinBase())59+            return 0;60+        int64 nChange = 0;61+        foreach(const CTxOut& txout, vout)62+        {63+            nChange += txout.GetChange();64+            if (!MoneyRange(nChange))65+                throw runtime_error("CTransaction::GetChange() : value out of range");66+        }67+        return nChange;68     }69 70     int64 GetValueOut() const71@@ -721,18 +762,19 @@72     vector<CMerkleTx> vtxPrev;73     map<string, string> mapValue;74     vector<pair<string, string> > vOrderForm;75+    unsigned int fTimeReceivedIsTxTime;76     unsigned int nTimeReceived;  // time received by this node77     char fFromMe;78     char fSpent;79-    char fTimeReceivedIsTxTime;80-    char fUnused;81     string strFromAccount;82 83     // memory only84     mutable char fDebitCached;85     mutable char fCreditCached;86+    mutable char fChangeCached;87     mutable int64 nDebitCached;88     mutable int64 nCreditCached;89+    mutable int64 nChangeCached;90 91     // memory only UI hints92     mutable unsigned int nTimeDisplayed;93@@ -760,16 +802,17 @@94         vtxPrev.clear();95         mapValue.clear();96         vOrderForm.clear();97+        fTimeReceivedIsTxTime = false;98         nTimeReceived = 0;99         fFromMe = false;100         fSpent = false;101-        fTimeReceivedIsTxTime = false;102-        fUnused = false;103         strFromAccount.clear();104         fDebitCached = false;105         fCreditCached = false;106+        fChangeCached = false;107         nDebitCached = 0;108         nCreditCached = 0;109+        nChangeCached = 0;110         nTimeDisplayed = 0;111         nLinesDisplayed = 0;112         fConfirmedDisplayed = false;113@@ -777,24 +820,23 @@114 115     IMPLEMENT_SERIALIZE116     (117+        CWalletTx* pthis = const_cast<CWalletTx*>(this);118         if (fRead)119-            const_cast<CWalletTx*>(this)->Init();120+            pthis->Init();121         nSerSize += SerReadWrite(s, *(CMerkleTx*)this, nType, nVersion, ser_action);122         READWRITE(vtxPrev);123+124+        pthis->mapValue["fromaccount"] = pthis->strFromAccount;125         READWRITE(mapValue);126+        pthis->strFromAccount = pthis->mapValue["fromaccount"];127+        pthis->mapValue.erase("fromaccount");128+        pthis->mapValue.erase("version");129+130         READWRITE(vOrderForm);131-        READWRITE(nVersion);132-        if (fRead && nVersion < 100)133-            const_cast<CWalletTx*>(this)->fTimeReceivedIsTxTime = nVersion;134+        READWRITE(fTimeReceivedIsTxTime);135         READWRITE(nTimeReceived);136         READWRITE(fFromMe);137         READWRITE(fSpent);138-        if (nVersion >= 31404)139-        {140-            READWRITE(fTimeReceivedIsTxTime);141-            READWRITE(fUnused);142-            READWRITE(strFromAccount);143-        }144     )145 146     int64 GetDebit() const147@@ -808,7 +850,7 @@148         return nDebitCached;149     }150 151-    int64 GetCredit(bool fUseCache=false) const152+    int64 GetCredit(bool fUseCache=true) const153     {154         // Must wait until coinbase is safely deep enough in the chain before valuing it155         if (IsCoinBase() && GetBlocksToMaturity() > 0)156@@ -820,6 +862,46 @@157         nCreditCached = CTransaction::GetCredit();158         fCreditCached = true;159         return nCreditCached;160+    }161+162+    int64 GetChange() const163+    {164+        if (fChangeCached)165+            return nChangeCached;166+        nChangeCached = CTransaction::GetChange();167+        fChangeCached = true;168+        return nChangeCached;169+    }170+171+    void GetAccountAmounts(string strAccount, const set<CScript>& setPubKey,172+                           int64& nGenerated, int64& nReceived, int64& nSent, int64& nFee) const173+    {174+        nGenerated = nReceived = nSent = nFee = 0;175+176+        // Generated blocks count to account ""177+        if (IsCoinBase())178+        {179+            if (strAccount == "" && GetBlocksToMaturity() == 0)180+                nGenerated = GetCredit();181+            return;182+        }183+184+        // Received185+        foreach(const CTxOut& txout, vout)186+            if (setPubKey.count(txout.scriptPubKey))187+                nReceived += txout.nValue;188+189+        // Sent190+        if (strFromAccount == strAccount)191+        {192+            int64 nDebit = GetDebit();193+            if (nDebit > 0)194+            {195+                int64 nValueOut = GetValueOut();196+                nFee = nDebit - nValueOut;197+                nSent = nValueOut - GetChange();198+            }199+        }200     }201 202     bool IsFromMe() const203@@ -1084,14 +1166,12 @@204     }205 206 207-    bool WriteToDisk(bool fWriteTransactions, unsigned int& nFileRet, unsigned int& nBlockPosRet)208+    bool WriteToDisk(unsigned int& nFileRet, unsigned int& nBlockPosRet)209     {210         // Open history file to append211         CAutoFile fileout = AppendBlockFile(nFileRet);212         if (!fileout)213             return error("CBlock::WriteToDisk() : AppendBlockFile failed");214-        if (!fWriteTransactions)215-            fileout.nType |= SER_BLOCKHEADERONLY;216 217         // Write index header218         unsigned int nSize = fileout.GetSerializeSize(*this);219@@ -1236,6 +1316,19 @@220         nNonce         = block.nNonce;221     }222 223+    CBlock GetBlockHeader() const224+    {225+        CBlock block;226+        block.nVersion       = nVersion;227+        if (pprev)228+            block.hashPrevBlock = pprev->GetBlockHash();229+        block.hashMerkleRoot = hashMerkleRoot;230+        block.nTime          = nTime;231+        block.nBits          = nBits;232+        block.nNonce         = nNonce;233+        return block;234+    }235+236     uint256 GetBlockHash() const237     {238         return *phashBlock;239@@ -1436,6 +1529,16 @@240             READWRITE(nVersion);241         READWRITE(vHave);242     )243+244+    void SetNull()245+    {246+        vHave.clear();247+    }248+249+    bool IsNull()250+    {251+        return vHave.empty();252+    }253 254     void Set(const CBlockIndex* pindex)255     {

rpc.cpp (modified)

1--- v0.3.17/rpc.cpp2+++ v0.3.18/rpc.cpp3@@ -71,6 +71,18 @@4     return nAmount;5 }6 7+Value ValueFromAmount(int64 amount)8+{9+    return (double)amount / (double)COIN;10+}11+12+void WalletTxToJSON(const CWalletTx& wtx, Object& entry)13+{14+    entry.push_back(Pair("confirmations", wtx.GetDepthInMainChain()));15+    entry.push_back(Pair("txid", wtx.GetHash().GetHex()));16+    foreach(const PAIRTYPE(string,string)& item, wtx.mapValue)17+        entry.push_back(Pair(item.first, item.second));18+}19 20 21 22@@ -435,27 +447,6 @@23 }24 25 26-Value listtransactions(const Array& params, bool fHelp)27-{28-    if (fHelp || params.size() > 2)29-        throw runtime_error(30-            "listtransactions [count=10] [includegenerated=false]\n"31-            "Returns up to [count] most recent transactions.");32-33-    int64 nCount = 10;34-    if (params.size() > 0)35-        nCount = params[0].get_int64();36-    bool fGenerated = false;37-    if (params.size() > 1)38-        fGenerated = params[1].get_bool();39-40-    Array ret;41-    //// not finished42-    ret.push_back("not implemented yet");43-    return ret;44-}45-46-47 Value getreceivedbyaddress(const Array& params, bool fHelp)48 {49     if (fHelp || params.size() < 1 || params.size() > 2)50@@ -497,21 +488,8 @@51 }52 53 54-Value getreceivedbyaccount(const Array& params, bool fHelp)55-{56-    if (fHelp || params.size() < 1 || params.size() > 2)57-        throw runtime_error(58-            "getreceivedbyaccount <account> [minconf=1]\n"59-            "Returns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations.");60-61-    // Minimum confirmations62-    int nMinDepth = 1;63-    if (params.size() > 1)64-        nMinDepth = params[1].get_int();65-66-    // Get the set of pub keys that have the label67-    string strAccount = params[0].get_str();68-    set<CScript> setPubKey;69+void GetAccountPubKeys(string strAccount, set<CScript>& setPubKey)70+{71     CRITICAL_BLOCK(cs_mapAddressBook)72     {73         foreach(const PAIRTYPE(string, string)& item, mapAddressBook)74@@ -528,6 +506,25 @@75             }76         }77     }78+}79+80+81+Value getreceivedbyaccount(const Array& params, bool fHelp)82+{83+    if (fHelp || params.size() < 1 || params.size() > 2)84+        throw runtime_error(85+            "getreceivedbyaccount <account> [minconf=1]\n"86+            "Returns the total amount received by addresses with <account> in transactions with at least [minconf] confirmations.");87+88+    // Minimum confirmations89+    int nMinDepth = 1;90+    if (params.size() > 1)91+        nMinDepth = params[1].get_int();92+93+    // Get the set of pub keys that have the label94+    string strAccount = params[0].get_str();95+    set<CScript> setPubKey;96+    GetAccountPubKeys(strAccount, setPubKey);97 98     // Tally99     int64 nAmount = 0;100@@ -552,24 +549,8 @@101 102 int64 GetAccountBalance(CWalletDB& walletdb, const string& strAccount, int nMinDepth)103 {104-    // Get the set of pub keys that have the account105     set<CScript> setPubKey;106-    CRITICAL_BLOCK(cs_mapAddressBook)107-    {108-        foreach(const PAIRTYPE(string, string)& item, mapAddressBook)109-        {110-            const string& strAddress = item.first;111-            const string& strName = item.second;112-            if (strName == strAccount)113-            {114-                // We're only counting our own valid bitcoin addresses and not ip addresses115-                CScript scriptPubKey;116-                if (scriptPubKey.SetBitcoinAddress(strAddress))117-                    if (IsMine(scriptPubKey))118-                        setPubKey.insert(scriptPubKey);119-            }120-        }121-    }122+    GetAccountPubKeys(strAccount, setPubKey);123 124     int64 nBalance = 0;125     CRITICAL_BLOCK(cs_mapWallet)126@@ -581,26 +562,12 @@127             if (!wtx.IsFinal())128                 continue;129 130-            // Count generated blocks to account ""131-            if (wtx.IsCoinBase() && strAccount == "" && wtx.GetBlocksToMaturity() == 0)132-            {133-                nBalance += wtx.GetCredit();134-                continue;135-            }136-137-            // Tally received138-            foreach(const CTxOut& txout, wtx.vout)139-                if (setPubKey.count(txout.scriptPubKey))140-                    if (wtx.GetDepthInMainChain() >= nMinDepth)141-                        nBalance += txout.nValue;142-143-            // Tally sent144-            if (wtx.strFromAccount == strAccount)145-            {146-                int64 nNet = wtx.GetCredit() - wtx.GetDebit();147-                if (nNet < 0)148-                    nBalance += nNet;149-            }150+            int64 nGenerated, nReceived, nSent, nFee;151+            wtx.GetAccountAmounts(strAccount, setPubKey, nGenerated, nReceived, nSent, nFee);152+153+            if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)154+                nBalance += nReceived;155+            nBalance += nGenerated - nSent - nFee;156         }157 158         // Tally internal accounting entries159@@ -627,8 +594,6 @@160 161     if (params.size() == 0)162         return ((double)GetBalance() / (double)COIN);163-164-    throw runtime_error("under construction"); //// to be released soon165 166     string strAccount = params[0].get_str();167     int nMinDepth = 1;168@@ -647,8 +612,6 @@169         throw runtime_error(170             "move <fromaccount> <toaccount> <amount> [minconf=1] [comment]\n"171             "Move from one account in your wallet to another.");172-173-    throw runtime_error("under construction");174 175     string strFrom = params[0].get_str();176     string strTo = params[1].get_str();177@@ -710,8 +673,6 @@178         throw runtime_error(179             "sendfrom <fromaccount> <tobitcoinaddress> <amount> [minconf=1] [comment] [comment-to]\n"180             "<amount> is a real and is rounded to the nearest 0.01");181-182-    throw runtime_error("under construction");183 184     string strAccount = params[0].get_str();185     string strAddress = params[1].get_str();186@@ -886,6 +847,131 @@187             "  \"confirmations\" : number of confirmations of the most recent transaction included");188 189     return ListReceived(params, true);190+}191+192+void ListAccountTransactions(CWalletDB& walletdb, const string& strAccount, int nMinDepth, multimap<int64, Object>& ret)193+{194+    set<CScript> setPubKey;195+    GetAccountPubKeys(strAccount, setPubKey);196+197+    CRITICAL_BLOCK(cs_mapWallet)198+    {199+        // Wallet: generate/send/receive transactions200+        for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)201+        {202+            const CWalletTx& wtx = (*it).second;203+            if (!wtx.IsFinal())204+                continue;205+206+            int64 nGenerated, nReceived, nSent, nFee;207+            wtx.GetAccountAmounts(strAccount, setPubKey, nGenerated, nReceived, nSent, nFee);208+209+            // Generated blocks count to account ""210+            if (nGenerated != 0)211+            {212+                Object entry;213+                entry.push_back(Pair("category", "generate"));214+                entry.push_back(Pair("amount", ValueFromAmount(nGenerated)));215+                WalletTxToJSON(wtx, entry);216+                ret.insert(make_pair(wtx.GetTxTime(), entry));217+            }218+219+            // Sent220+            if (nSent != 0 || nFee != 0)221+            {222+                Object entry;223+                entry.push_back(Pair("category", "send"));224+                entry.push_back(Pair("amount", ValueFromAmount(-nSent)));225+                entry.push_back(Pair("fee", ValueFromAmount(-nFee)));226+                WalletTxToJSON(wtx, entry);227+                ret.insert(make_pair(wtx.GetTxTime(), entry));228+            }229+230+            // Received231+            if (nReceived != 0 && wtx.GetDepthInMainChain() >= nMinDepth)232+            {233+                Object entry;234+                entry.push_back(Pair("category", "receive"));235+                entry.push_back(Pair("amount", ValueFromAmount(nReceived)));236+                WalletTxToJSON(wtx, entry);237+                ret.insert(make_pair(wtx.GetTxTime(), entry));238+            }239+        }240+241+        // Internal accounting entries242+        list<CAccountingEntry> acentries;243+        walletdb.ListAccountCreditDebit(strAccount, acentries);244+        foreach (const CAccountingEntry& acentry, acentries)245+        {246+            Object entry;247+            entry.push_back(Pair("category", "move"));248+            entry.push_back(Pair("amount", ValueFromAmount(acentry.nCreditDebit)));249+            entry.push_back(Pair("otheraccount", acentry.strOtherAccount));250+            ret.insert(make_pair(acentry.nTime, entry));251+        }252+    }253+}254+255+Value listtransactions(const Array& params, bool fHelp)256+{257+    if (fHelp || params.size() < 1 || params.size() > 2)258+        throw runtime_error(259+            "listtransactions <account> [count=10]\n"260+            "Returns up to [count] most recent transactions for account <account>.");261+262+    string strAccount = params[0].get_str();263+    int nCount = 10;264+    if (params.size() > 1)265+        nCount = params[1].get_int();266+267+    CWalletDB walletdb;268+    multimap<int64, Object> mapByTime;  // keys are transaction time269+    ListAccountTransactions(walletdb, strAccount, 0, mapByTime);270+271+    // Return only last nCount items:272+    int nToErase = mapByTime.size()-nCount;273+    if (nToErase > 0)274+    {275+        multimap<int64, Object>::iterator end = mapByTime.begin();276+        std::advance(end, nToErase);277+        mapByTime.erase(mapByTime.begin(), end);278+    }279+280+    Array ret;281+    foreach(const PAIRTYPE(int64, Object)& item, mapByTime)282+        ret.push_back(item.second);283+    return ret;284+}285+286+Value gettransaction(const Array& params, bool fHelp)287+{288+    if (fHelp || params.size() != 1)289+        throw runtime_error(290+            "gettransaction <txid>\n"291+            "Get detailed information about <txid>");292+293+    uint256 hash;294+    hash.SetHex(params[0].get_str());295+296+    Object entry;297+    CRITICAL_BLOCK(cs_mapWallet)298+    {299+        if (!mapWallet.count(hash))300+            throw JSONRPCError(-5, "Invalid transaction id");301+        const CWalletTx& wtx = mapWallet[hash];302+303+        int64 nCredit = wtx.GetCredit();304+        int64 nDebit = wtx.GetDebit();305+        int64 nNet = nCredit - nDebit;306+        int64 nFee = (wtx.IsFromMe() ? wtx.GetValueOut() - nDebit : 0);307+308+        entry.push_back(Pair("amount", ValueFromAmount(nNet - nFee)));309+        if (wtx.IsFromMe())310+            entry.push_back(Pair("fee", ValueFromAmount(nFee)));311+        WalletTxToJSON(mapWallet[hash], entry);312+    }313+314+    return entry;315 }316 317 318@@ -1086,6 +1172,8 @@319     make_pair("getbalance",            &getbalance),320     make_pair("move",                  &movecmd),321     make_pair("sendfrom",              &sendfrom),322+    make_pair("gettransaction",        &gettransaction),323+    make_pair("listtransactions",      &listtransactions),324     make_pair("getwork",               &getwork),325 };326 map<string, rpcfn_type> mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0]));327@@ -1437,7 +1525,7 @@328         return;329     }330 331-    bool fUseSSL = (mapArgs.count("-rpcssl") > 0);332+    bool fUseSSL = GetBoolArg("-rpcssl");333     asio::ip::address bindAddress = mapArgs.count("-rpcallowip") ? asio::ip::address_v4::any() : asio::ip::address_v4::loopback();334 335     asio::io_service io_service;336@@ -1464,7 +1552,7 @@337     }338 #else339     if (fUseSSL)340-        throw runtime_error("-rpcssl=true, but bitcoin compiled without full openssl libraries.");341+        throw runtime_error("-rpcssl=1, but bitcoin compiled without full openssl libraries.");342 #endif343 344     loop345@@ -1554,7 +1642,7 @@346 347             // Observe safe mode348             string strWarning = GetWarnings("rpc");349-            if (strWarning != "" && !mapArgs.count("-disablesafemode") && !setAllowInSafeMode.count(strMethod))350+            if (strWarning != "" && !GetBoolArg("-disablesafemode") && !setAllowInSafeMode.count(strMethod))351                 throw JSONRPCError(-2, string("Safe mode: ") + strWarning);352 353             try354@@ -1604,7 +1692,7 @@355                 GetConfigFile().c_str()));356 357     // Connect to localhost358-    bool fUseSSL = (mapArgs.count("-rpcssl") > 0);359+    bool fUseSSL = GetBoolArg("-rpcssl");360 #ifdef USE_SSL361     asio::io_service io_service;362     ssl::context context(io_service, ssl::context::sslv23);363@@ -1616,7 +1704,7 @@364         throw runtime_error("couldn't connect to server");365 #else366     if (fUseSSL)367-        throw runtime_error("-rpcssl=true, but bitcoin compiled without full openssl libraries.");368+        throw runtime_error("-rpcssl=1, but bitcoin compiled without full openssl libraries.");369 370     ip::tcp::iostream stream(GetArg("-rpcconnect", "127.0.0.1"), GetArg("-rpcport", "8332"));371     if (stream.fail())372@@ -1706,8 +1794,6 @@373         if (strMethod == "setgenerate"            && n > 0) ConvertTo<bool>(params[0]);374         if (strMethod == "setgenerate"            && n > 1) ConvertTo<boost::int64_t>(params[1]);375         if (strMethod == "sendtoaddress"          && n > 1) ConvertTo<double>(params[1]);376-        if (strMethod == "listtransactions"       && n > 0) ConvertTo<boost::int64_t>(params[0]);377-        if (strMethod == "listtransactions"       && n > 1) ConvertTo<bool>(params[1]);378         if (strMethod == "getamountreceived"      && n > 1) ConvertTo<boost::int64_t>(params[1]); // deprecated379         if (strMethod == "getreceivedbyaddress"   && n > 1) ConvertTo<boost::int64_t>(params[1]);380         if (strMethod == "getreceivedbyaccount"   && n > 1) ConvertTo<boost::int64_t>(params[1]);381@@ -1725,6 +1811,7 @@382         if (strMethod == "move"                   && n > 3) ConvertTo<boost::int64_t>(params[3]);383         if (strMethod == "sendfrom"               && n > 2) ConvertTo<double>(params[2]);384         if (strMethod == "sendfrom"               && n > 3) ConvertTo<boost::int64_t>(params[3]);385+        if (strMethod == "listtransactions"       && n > 1) ConvertTo<boost::int64_t>(params[1]);386 387         // Execute388         Object reply = CallRPC(strMethod, params);

script.cpp (modified)

1--- v0.3.17/script.cpp2+++ v0.3.18/script.cpp3@@ -997,7 +997,7 @@4                 break;5             if (opcode2 == OP_PUBKEY)6             {7-                if (vch1.size() < 33)8+                if (vch1.size() < 33 || vch1.size() > 120)9                     break;10                 vSolutionRet.push_back(make_pair(opcode2, vch1));11             }12@@ -1073,6 +1073,13 @@13     }14 15     return true;16+}17+18+19+bool IsStandard(const CScript& scriptPubKey)20+{21+    vector<pair<opcodetype, valtype> > vSolution;22+    return Solver(scriptPubKey, vSolution);23 }24 25 

script.h (modified)

1--- v0.3.17/script.h2+++ v0.3.18/script.h3@@ -597,6 +597,23 @@4     }5 6 7+    bool IsPushOnly() const8+    {9+        if (size() > 200)10+            return false;11+        const_iterator pc = begin();12+        while (pc < end())13+        {14+            opcodetype opcode;15+            if (!GetOp(pc, opcode))16+                return false;17+            if (opcode > OP_16)18+                return false;19+        }20+        return true;21+    }22+23+24     uint160 GetBitcoinAddressHash160() const25     {26         opcodetype opcode;27@@ -684,6 +701,7 @@28 29 30 uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType);31+bool IsStandard(const CScript& scriptPubKey);32 bool IsMine(const CScript& scriptPubKey);33 bool ExtractPubKey(const CScript& scriptPubKey, bool fMineOnly, vector<unsigned char>& vchPubKeyRet);34 bool ExtractHash160(const CScript& scriptPubKey, uint160& hash160Ret);

serialize.h (modified)

1--- v0.3.17/serialize.h2+++ v0.3.18/serialize.h3@@ -7,6 +7,9 @@4 #include <map>5 #include <set>6 #include <boost/type_traits/is_fundamental.hpp>7+#include <boost/tuple/tuple.hpp>8+#include <boost/tuple/tuple_comparison.hpp>9+#include <boost/tuple/tuple_io.hpp>10 #if defined(_MSC_VER) || defined(__BORLANDC__)11 typedef __int64  int64;12 typedef unsigned __int64  uint64;13@@ -22,7 +25,7 @@14 class CAutoFile;15 static const unsigned int MAX_SIZE = 0x02000000;16 17-static const int VERSION = 31700;18+static const int VERSION = 31800;19 static const char* pszSubVer = "";20 21 22@@ -338,6 +341,16 @@23 template<typename Stream, typename K, typename T> void Serialize(Stream& os, const std::pair<K, T>& item, int nType, int nVersion=VERSION);24 template<typename Stream, typename K, typename T> void Unserialize(Stream& is, std::pair<K, T>& item, int nType, int nVersion=VERSION);25 26+// 3 tuple27+template<typename T0, typename T1, typename T2> unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2>& item, int nType, int nVersion=VERSION);28+template<typename Stream, typename T0, typename T1, typename T2> void Serialize(Stream& os, const boost::tuple<T0, T1, T2>& item, int nType, int nVersion=VERSION);29+template<typename Stream, typename T0, typename T1, typename T2> void Unserialize(Stream& is, boost::tuple<T0, T1, T2>& item, int nType, int nVersion=VERSION);30+31+// 4 tuple32+template<typename T0, typename T1, typename T2, typename T3> unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion=VERSION);33+template<typename Stream, typename T0, typename T1, typename T2, typename T3> void Serialize(Stream& os, const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion=VERSION);34+template<typename Stream, typename T0, typename T1, typename T2, typename T3> void Unserialize(Stream& is, boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion=VERSION);35+36 // map37 template<typename K, typename T, typename Pred, typename A> unsigned int GetSerializeSize(const std::map<K, T, Pred, A>& m, int nType, int nVersion=VERSION);38 template<typename Stream, typename K, typename T, typename Pred, typename A> void Serialize(Stream& os, const std::map<K, T, Pred, A>& m, int nType, int nVersion=VERSION);39@@ -550,6 +563,71 @@40 {41     Unserialize(is, item.first, nType, nVersion);42     Unserialize(is, item.second, nType, nVersion);43+}44+45+46+47+//48+// 3 tuple49+//50+template<typename T0, typename T1, typename T2>51+unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2>& item, int nType, int nVersion)52+{53+    unsigned int nSize = 0;54+    nSize += GetSerializeSize(get<0>(item), nType, nVersion);55+    nSize += GetSerializeSize(get<1>(item), nType, nVersion);56+    nSize += GetSerializeSize(get<2>(item), nType, nVersion);57+    return nSize;58+}59+60+template<typename Stream, typename T0, typename T1, typename T2>61+void Serialize(Stream& os, const boost::tuple<T0, T1, T2>& item, int nType, int nVersion)62+{63+    Serialize(os, get<0>(item), nType, nVersion);64+    Serialize(os, get<1>(item), nType, nVersion);65+    Serialize(os, get<2>(item), nType, nVersion);66+}67+68+template<typename Stream, typename T0, typename T1, typename T2>69+void Unserialize(Stream& is, boost::tuple<T0, T1, T2>& item, int nType, int nVersion)70+{71+    Unserialize(is, get<0>(item), nType, nVersion);72+    Unserialize(is, get<1>(item), nType, nVersion);73+    Unserialize(is, get<2>(item), nType, nVersion);74+}75+76+77+78+//79+// 4 tuple80+//81+template<typename T0, typename T1, typename T2, typename T3>82+unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion)83+{84+    unsigned int nSize = 0;85+    nSize += GetSerializeSize(get<0>(item), nType, nVersion);86+    nSize += GetSerializeSize(get<1>(item), nType, nVersion);87+    nSize += GetSerializeSize(get<2>(item), nType, nVersion);88+    nSize += GetSerializeSize(get<3>(item), nType, nVersion);89+    return nSize;90+}91+92+template<typename Stream, typename T0, typename T1, typename T2, typename T3>93+void Serialize(Stream& os, const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion)94+{95+    Serialize(os, get<0>(item), nType, nVersion);96+    Serialize(os, get<1>(item), nType, nVersion);97+    Serialize(os, get<2>(item), nType, nVersion);98+    Serialize(os, get<3>(item), nType, nVersion);99+}100+101+template<typename Stream, typename T0, typename T1, typename T2, typename T3>102+void Unserialize(Stream& is, boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion)103+{104+    Unserialize(is, get<0>(item), nType, nVersion);105+    Unserialize(is, get<1>(item), nType, nVersion);106+    Unserialize(is, get<2>(item), nType, nVersion);107+    Unserialize(is, get<3>(item), nType, nVersion);108 }109 110 

setup.nsi (modified)

1--- v0.3.17/setup.nsi2+++ v0.3.18/setup.nsi3@@ -7,7 +7,7 @@4 5 # General Symbol Definitions6 !define REGKEY "SOFTWARE\$(^Name)"7-!define VERSION 0.3.178+!define VERSION 0.3.189 !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.17-win32-setup.exe17+OutFile bitcoin-0.3.18-win32-setup.exe18 InstallDir $PROGRAMFILES\Bitcoin19 CRCCheck on20 XPStyle on21 ShowInstDetails show22-VIProductVersion 0.3.17.023+VIProductVersion 0.3.18.024 VIAddVersionKey ProductName Bitcoin25 VIAddVersionKey ProductVersion "${VERSION}"26 VIAddVersionKey CompanyName "${COMPANY}"

sha256.cpp (modified)

1--- v0.3.17/sha256.cpp2+++ v0.3.18/sha256.cpp3@@ -1,8 +1,8 @@4-// Copyright (c) 2010 Satoshi Nakamoto5+// Copyright (c) 2010 Nils Schneider6 // Distributed under the MIT/X11 software license, see the accompanying7 // file license.txt or http://www.opensource.org/licenses/mit-license.php.8 9-// tcatm's 4-way 128-bit SSE2 SHA-25610+// 4-way 128-bit SSE2 SHA-25611 12 #ifdef FOURWAYSSE213 

ui.cpp (modified)

1--- v0.3.17/ui.cpp2+++ v0.3.18/ui.cpp3@@ -391,7 +391,7 @@4     if (!event.Iconized())5         fClosedToTray = false;6 #if defined(__WXGTK__) || defined(__WXMAC_OSX__)7-    if (mapArgs.count("-minimizetotray")) {8+    if (GetBoolArg("-minimizetotray")) {9 #endif10     // The tray icon sometimes disappears on ubuntu karmic11     // Hiding the taskbar button doesn't work cleanly on ubuntu lucid12@@ -697,16 +697,13 @@13         if (fAllFromMe && fAllToMe)14         {15             // Payment to self16-            int64 nValue = wtx.vout[0].nValue;17+            int64 nChange = wtx.GetChange();18             InsertLine(fNew, nIndex, hash, strSort, colour,19                        strStatus,20                        nTime ? DateTimeStr(nTime) : "",21                        _("Payment to yourself"),22-                       "",23-                       "");24-            /// issue: can't tell which is the payment and which is the change anymore25-            //           FormatMoney(nNet - nValue, true),26-            //           FormatMoney(nValue, true));27+                       FormatMoney(-(nDebit - nChange), true),28+                       FormatMoney(nCredit - nChange, true));29         }30         else if (fAllFromMe)31         {32@@ -1376,10 +1373,10 @@33                 if (fAllToMe)34                 {35                     // Payment to self36-                    /// issue: can't tell which is the payment and which is the change anymore37-                    //int64 nValue = wtx.vout[0].nValue;38-                    //strHTML += _("<b>Debit:</b> ") + FormatMoney(-nValue) + "<br>";39-                    //strHTML += _("<b>Credit:</b> ") + FormatMoney(nValue) + "<br>";40+                    int64 nChange = wtx.GetChange();41+                    int64 nValue = nCredit - nChange;42+                    strHTML += _("<b>Debit:</b> ") + FormatMoney(-nValue) + "<br>";43+                    strHTML += _("<b>Credit:</b> ") + FormatMoney(nValue) + "<br>";44                 }45 46                 int64 nTxFee = nDebit - wtx.GetValueOut();47@@ -1636,7 +1633,7 @@48 #endif49 #if defined(__WXGTK__) || defined(__WXMAC_OSX__)50     m_checkBoxStartOnSystemStartup->SetLabel(_("&Start Bitcoin on window system startup"));51-    if (!mapArgs.count("-minimizetotray"))52+    if (!GetBoolArg("-minimizetotray"))53     {54         // Minimize to tray is just too buggy on Linux55         fMinimizeToTray = false;56@@ -2744,10 +2741,10 @@57 void CreateMainWindow()58 {59     pframeMain = new CMainFrame(NULL);60-    if (mapArgs.count("-min"))61+    if (GetBoolArg("-min"))62         pframeMain->Iconize(true);63 #if defined(__WXGTK__) || defined(__WXMAC_OSX__)64-    if (!mapArgs.count("-minimizetotray"))65+    if (!GetBoolArg("-minimizetotray"))66         fMinimizeToTray = false;67 #endif68     pframeMain->Show(true);  // have to show first to get taskbar button to hide

util.cpp (modified)

1--- v0.3.17/util.cpp2+++ v0.3.18/util.cpp3@@ -175,7 +175,6 @@4             va_start(arg_ptr, pszFormat);5             ret = vfprintf(fileout, pszFormat, arg_ptr);6             va_end(arg_ptr);7-            fflush(fileout);8         }9     }10 11@@ -406,11 +405,11 @@12         while (isspace(*psz))13             psz++;14         char c = phexdigit[(unsigned char)*psz++];15-        if (c == -1)16+        if (c == (char)-1)17             break;18         unsigned char n = (c << 4);19         c = phexdigit[(unsigned char)*psz++];20-        if (c == -1)21+        if (c == (char)-1)22             break;23         n |= c;24         vch.push_back(n);

util.h (modified)

1--- v0.3.17/util.h2+++ v0.3.18/util.h3@@ -417,6 +417,17 @@4     return nDefault;5 }6 7+inline bool GetBoolArg(const string& strArg)8+{9+    if (mapArgs.count(strArg))10+    {11+        if (mapArgs[strArg].empty())12+            return true;13+        return (atoi(mapArgs[strArg]) != 0);14+    }15+    return false;16+}17+18 inline string FormatVersion(int nVersion)19 {20     if (nVersion%100 == 0)
0:000:00