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.2.8 → v0.2.9

14 files · +642 · −105 · 42605ce8b · 2010-05-26 · s_nakamoto

Release commit message: better prevention of inventory relaying during initial download, message checksum between nodes with 0.2.9 or higher, optimization level up from -O0 to -O2, rpc functions: setlabel, getlabel, getaddressesbylabel, getreceivedbyaddress, getreceivedbylabel, listreceivedbyaddress, listreceivedbylabel -- version 0.2.9

Previous diff: v0.2.7 → v0.2.8. Next: v0.2.9 → v0.2.10.

build-osx.txt (added)

1--- /dev/null2+++ v0.2.9/build-osx.txt3@@ -1 +1,210 @@4-5+Mac OS X build instructions6+Laszlo Hanyecz (solar@heliacal.net)7+8+9+Tested on 10.5 and 10.6 intel.  PPC is not supported because it's big-endian.10+11+All of the commands should be executed in Terminal.app.. it's in12+/Applications/Utilities13+14+You need to install XCode with all the options checked so that the compiler15+and everything is available in /usr not just /Developer16+I think it comes on the DVD but you can get the current version from17+http://developer.apple.com18+19+20+1.  Pick a directory to work inside.. something like ~/bitcoin works.  The21+structure I use looks like this:22+(~ is your home directory)23+24+~/bitcoin25+~/bitcoin/trunk         # source code26+~/bitcoin/deps          # dependencies.. like libraries and headers needed to compile27+~/bitcoin/Bitcoin.app   # the application bundle where you can run the app28+29+Just execute: mkdir ~/bitcoin30+This will create the top dir for you..31+32+WARNING: do not use the ~ notation with the configure scripts.. use the full33+name of the directory, for example /Users/james/bitcoin/deps for a user named34+'james'.  In my examples I am using 'macosuser' so make sure you change that.35+36+2.  Check out the trunk version of the bitcoin code from subversion:37+38+cd ~/bitcoin39+svn checkout https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk40+41+This will make ~/bitcoin/trunk for you with all the files from subversion. 42+43+3.  Get and build the dependencies44+45+46+Boost47+-----48+49+Download from http://www.boost.org/users/download/50+I'm assuming it ended up in ~/Downloads..51+52+mkdir ~/bitcoin/deps53+cd ~/bitcoin/deps54+tar xvjf ~/Downloads/boost_1_42_0.tar.bz255+cd boost_1_42_056+./bootstrap.sh57+./bjam architecture=combined address-model=32_64 macosx-version=10.6 macosx-version-min=10.5 link=static runtime-link=static --toolset=darwin --prefix=/Users/macosuser/bitcoin/deps install58+59+This part takes a while.. use your judgement and fix it if something doesn't60+build for some reason.61+62+Change the prefix to whatever your directory is (my username in this example63+is macosuser).  I'm also running on 10.6 so i have macosx-version=10.6  change64+to 10.5 if you're using leopard.65+66+This is what my output looked like at the end:67+...failed updating 2 targets...68+...skipped 144 targets...69+...updated 8074 targets...70+71+72+OpenSSL73+-------74+75+Download from http://www.openssl.org/source/76+77+We would like to build this as a 32 bit/64 bit library so we actually build it78+2 times and join it together here..  If you downloaded with safari it already79+uncompressed it so it will just be a tar not a tar.gz80+81+cd ~/bitcoin/deps82+tar xvf ~/Downloads/openssl-1.0.0.tar83+mv openssl-1.0.0 openssl-1.0.0-i38684+tar xvf ~/Downloads/openssl-1.0.0.tar85+mv openssl-1.0.0 openssl-1.0.0-x86_6486+# build i386 (32 bit intel) binary87+cd openssl-1.0.0-i38688+./Configure --prefix=/Users/macosuser/bitcoin/deps --openssldir=/Users/macosuser/deps/openssl darwin-i386-cc && make89+make install # only do this on one of the architectures, to install the headers90+cd ..91+# build x86_64 (64 bit intel) binary92+cd openssl-1.0.0-x86_6493+./Configure --prefix=/Users/macosuser/bitcoin/deps --openssldir=/Users/macosuser/deps/openssl darwin64-x86_64-cc && make94+cd ..95+96+# combine the libs97+cd ~/bitcoin/deps98+lipo -arch i386 openssl-1.0.0-i386/libcrypto.a -arch x86_64 openssl-1.0.0-x86_64/libcrypto.a -o lib/libcrypto.a -create99+lipo -arch i386 openssl-1.0.0-i386/libssl.a -arch x86_64 openssl-1.0.0-x86_64/libssl.a -o lib/libssl.a -create100+101+Verify your binaries102+103+file lib/libcrypto.a104+105+output should look like this:106+107+ib/libcrypto.a: Mach-O universal binary with 2 architectures108+lib/libcrypto.a (for architecture i386):	current ar archive random library109+lib/libcrypto.a (for architecture x86_64):	current ar archive random library110+111+112+Berkeley DB113+-----------114+115+Download from http://freshmeat.net/projects/berkeleydb/116+117+cd ~/bitcoin/deps118+tar xvf ~/Downloads/db-4.8.26.tar119+cd db-4.8.26/build_unix120+../dist/configure --prefix=/Users/macosuser/bitcoin/deps --enable-cxx && make && make install121+122+123+wxWidgets124+---------125+126+This is the big one..127+128+Check it out from svn129+130+cd ~/bitcoin/deps131+svn checkout http://svn.wxwidgets.org/svn/wx/wxWidgets/trunk wxWidgets-trunk132+133+This will make a wxWidgets-trunk directory in deps.134+135+Use this script snippet, change your prefix to whatever your dir is:136+137+PREFIX=~/bitcoin/deps138+SRCDIR="$PREFIX/wxWidgets-trunk"139+BUILDDIR="$SRCDIR/macbuild"140+141+cd "$PREFIX" &&142+#svn checkout http://svn.wxwidgets.org/svn/wx/wxWidgets/trunk wxWidgets-trunk &&143+cd "$SRCDIR" &&144+145+[ -f include/wx/hashmap.h.orig ] || cp include/wx/hashmap.h include/wx/hashmap.h.orig &&146+sed 's/if wxUSE_STL/if 0 \&\& wxUSE_STL/g' < include/wx/hashmap.h.orig > include/wx/hashmap.h &&147+148+[ -f include/wx/hashset.h.orig ] || cp include/wx/hashset.h include/wx/hashset.h.orig &&149+sed 's/if wxUSE_STL/if 0 \&\& wxUSE_STL/g' < include/wx/hashset.h.orig > include/wx/hashset.h &&150+151+152+153+rm -vrf "$BUILDDIR" &&154+mkdir "$BUILDDIR" &&155+cd "$BUILDDIR" &&156+157+../configure --prefix="$PREFIX" \158+--with-osx_cocoa \159+--disable-shared \160+--disable-debug_flag \161+--with-macosx-version-min=10.5 \162+--enable-stl \163+--enable-utf8 \164+--enable-universal_binary \165+--with-libjpeg=builtin \166+--with-libpng=builtin \167+--with-regex=builtin \168+--with-libtiff=builtin \169+--with-zlib=builtin \170+--with-expat=builtin \171+--with-macosx-sdk=/Developer/SDKs/MacOSX10.5.sdk &&172+173+174+find . -name Makefile | 175+while read i; do 176+  echo $i; 177+  sed 's/-arch i386/-arch i386 -arch x86_64/g' < "$i" > "$i".new && 178+  mv "$i" "$i".old && 179+  mv "$i".new "$i"; 180+done181+182+183+184+make && 185+make install186+187+188+189+Now you should be able to build bitcoin190+191+cd ~/bitcoin/trunk192+make -f makefile.osx bitcoin193+194+Before you can run it, you need to create an application bundle for Mac OS.195+Create the directories in terminal using mkdir and copy the files into place.196+They are available at http://heliacal.net/~solar/bitcoin/mac-build/197+You need the Info.plist and the .ins file.  The Contents/MacOS/bitcoin file is198+the output of the build.199+Your directory structure should look like this:200+201+Bitcoin.app202+Bitcoin.app/Contents203+Bitcoin.app/Contents/Info.plist204+Bitcoin.app/Contents/MacOS205+Bitcoin.app/Contents/MacOS/bitcoin206+Bitcoin.app/Contents/Resources207+Bitcoin.app/Contents/Resources/BitcoinAppIcon.icns208+209+To run it you can just click the Bitcoin.app in Finder, or just do open210+~/bitcoin/Bitcoin.app211+If you want to run it with arguments you can just run it without backgrounding212+by specifying the full name in terminal:213+~/bitcoin/Bitcoin.app/Contents/MacOS/bitcoin -addnode=192.75.207.66214+

db.h (modified)

1--- v0.2.8/db.h2+++ v0.2.9/db.h3@@ -328,6 +328,8 @@4 5     bool EraseName(const string& strAddress)6     {7+        // This should only be used for sending addresses, never for receiving addresses,8+        // receiving addresses must always have an address book entry if they're not change return.9         CRITICAL_BLOCK(cs_mapAddressBook)10             mapAddressBook.erase(strAddress);11         nWalletDBUpdated++;

init.cpp (modified)

1--- v0.2.8/init.cpp2+++ v0.2.9/init.cpp3@@ -224,9 +224,6 @@4         }5     }6 7-    if (fDaemon)8-        fprintf(stdout, "bitcoin server starting\n");9-10 #ifdef __WXGTK__11     if (fDaemon || fCommandLine)12     {13@@ -447,7 +444,8 @@14     //15     // Load data files16     //17-    bool fFirstRun;18+    if (fDaemon)19+        fprintf(stdout, "bitcoin server starting\n");20     strErrors = "";21     int64 nStart;22 23@@ -465,6 +463,7 @@24 25     printf("Loading wallet...\n");26     nStart = GetTimeMillis();27+    bool fFirstRun;28     if (!LoadWallet(fFirstRun))29         strErrors += _("Error loading wallet.dat      \n");30     printf(" wallet      %15"PRI64d"ms\n", GetTimeMillis() - nStart);

main.cpp (modified)

1--- v0.2.8/main.cpp2+++ v0.2.9/main.cpp3@@ -1336,19 +1336,12 @@4     if (!AddToBlockIndex(nFile, nBlockPos))5         return error("AcceptBlock() : AddToBlockIndex failed");6 7-    // Don't relay old inventory during initial block download.8-    // Please keep this number updated to a few thousand below current block count.9-    if (hashBestChain == hash && nBestHeight > 55000)10-        RelayInventory(CInv(MSG_BLOCK, hash));11-12-    // // Add atoms to user reviews for coins created13-    // vector<unsigned char> vchPubKey;14-    // if (ExtractPubKey(vtx[0].vout[0].scriptPubKey, false, vchPubKey))15-    // {16-    //     unsigned short nAtom = GetRand(USHRT_MAX - 100) + 100;17-    //     vector<unsigned short> vAtoms(1, nAtom);18-    //     AddAtomsAndPropagate(Hash(vchPubKey.begin(), vchPubKey.end()), vAtoms, true);19-    // }20+    // Relay inventory, but don't relay old inventory during initial block download21+    if (hashBestChain == hash)22+        CRITICAL_BLOCK(cs_vNodes)23+            foreach(CNode* pnode, vNodes)24+                if (nBestHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 55000))25+                    pnode->PushInventory(CInv(MSG_BLOCK, hash));26 27     return true;28 }29@@ -1721,6 +1714,7 @@30     //  (4) message start31     //  (12) command32     //  (4) size33+    //  (4) checksum34     //  (x) data35     //36 37@@ -1728,12 +1722,13 @@38     {39         // Scan for message start40         CDataStream::iterator pstart = search(vRecv.begin(), vRecv.end(), BEGIN(pchMessageStart), END(pchMessageStart));41-        if (vRecv.end() - pstart < sizeof(CMessageHeader))42-        {43-            if (vRecv.size() > sizeof(CMessageHeader))44+        int nHeaderSize = vRecv.GetSerializeSize(CMessageHeader());45+        if (vRecv.end() - pstart < nHeaderSize)46+        {47+            if (vRecv.size() > nHeaderSize)48             {49                 printf("\n\nPROCESSMESSAGE MESSAGESTART NOT FOUND\n\n");50-                vRecv.erase(vRecv.begin(), vRecv.end() - sizeof(CMessageHeader));51+                vRecv.erase(vRecv.begin(), vRecv.end() - nHeaderSize);52             }53             break;54         }55@@ -1742,6 +1737,7 @@56         vRecv.erase(vRecv.begin(), pstart);57 58         // Read header59+        vector<char> vHeaderSave(vRecv.begin(), vRecv.begin() + nHeaderSize);60         CMessageHeader hdr;61         vRecv >> hdr;62         if (!hdr.IsValid())63@@ -1757,16 +1753,29 @@64         {65             // Rewind and wait for rest of message66             ///// need a mechanism to give up waiting for overlong message size error67-            //if (fDebug)68-            //    printf("message-break\n");69-            vRecv.insert(vRecv.begin(), BEGIN(hdr), END(hdr));70-            Sleep(100);71+            if (fDebug)72+                printf("message-break\n");73+            vRecv.insert(vRecv.begin(), vHeaderSave.begin(), vHeaderSave.end());74             break;75         }76 77         // Copy message to its own buffer78         CDataStream vMsg(vRecv.begin(), vRecv.begin() + nMessageSize, vRecv.nType, vRecv.nVersion);79         vRecv.ignore(nMessageSize);80+81+        // Checksum82+        if (vRecv.GetVersion() >= 209)83+        {84+            uint256 hash = Hash(vMsg.begin(), vMsg.end());85+            unsigned int nChecksum = 0;86+            memcpy(&nChecksum, &hash, sizeof(nChecksum));87+            if (nChecksum != hdr.nChecksum)88+            {89+                printf("ProcessMessage(%s, %d bytes) : CHECKSUM ERROR nChecksum=%08x hdr.nChecksum=%08x\n",90+                       strCommand.c_str(), nMessageSize, nChecksum, hdr.nChecksum);91+                continue;92+            }93+        }94 95         // Process message96         bool fRet = false;97@@ -1844,6 +1853,9 @@98             vRecv >> addrFrom >> nNonce;99         if (pfrom->nVersion >= 106 && !vRecv.empty())100             vRecv >> strSubVer;101+        if (pfrom->nVersion >= 209 && !vRecv.empty())102+            vRecv >> pfrom->nStartingHeight;103+104         if (pfrom->nVersion == 0)105             return false;106 107@@ -1854,9 +1866,6 @@108             return true;109         }110 111-        pfrom->vSend.SetVersion(min(pfrom->nVersion, VERSION));112-        pfrom->vRecv.SetVersion(min(pfrom->nVersion, VERSION));113-114         pfrom->fClient = !(pfrom->nServices & NODE_NETWORK);115         if (pfrom->fClient)116         {117@@ -1865,6 +1874,13 @@118         }119 120         AddTimeData(pfrom->addr.ip, nTime);121+122+        // Change version123+        if (pfrom->nVersion >= 209)124+            pfrom->PushMessage("verack");125+        pfrom->vSend.SetVersion(min(pfrom->nVersion, VERSION));126+        if (pfrom->nVersion < 209)127+            pfrom->vRecv.SetVersion(min(pfrom->nVersion, VERSION));128 129         // Ask the first connected node for block updates130         static bool fAskedForBlocks;131@@ -1876,7 +1892,7 @@132 133         pfrom->fSuccessfullyConnected = true;134 135-        printf("version message: version %d\n", pfrom->nVersion);136+        printf("version message: version %d, blocks=%d\n", pfrom->nVersion, pfrom->nStartingHeight);137     }138 139 140@@ -1884,6 +1900,12 @@141     {142         // Must have a version message before anything else143         return false;144+    }145+146+147+    else if (strCommand == "verack")148+    {149+        pfrom->vRecv.SetVersion(min(pfrom->nVersion, VERSION));150     }151 152 153@@ -2101,9 +2123,8 @@154         vRecv >> *pblock;155 156         //// debug print157-        // printf("received block:\n");158+        printf("received block %s\n", pblock->GetHash().ToString().substr(0,16).c_str());159         // pblock->print();160-        printf("received block %s\n", pblock->GetHash().ToString().substr(0,16).c_str());161 162         CInv inv(MSG_BLOCK, pblock->GetHash());163         pfrom->AddInventoryKnown(inv);164@@ -2388,8 +2409,11 @@165         int nAddThreads = nProcessors - vnThreadsRunning[3];166         printf("Starting %d BitcoinMiner threads\n", nAddThreads);167         for (int i = 0; i < nAddThreads; i++)168+        {169             if (!CreateThread(ThreadBitcoinMiner, NULL))170                 printf("Error: CreateThread(ThreadBitcoinMiner) failed\n");171+            Sleep(10);172+        }173     }174 }175 

makefile.mingw (modified)

1--- v0.2.8/makefile.mingw2+++ v0.2.9/makefile.mingw3@@ -29,7 +29,7 @@4 5 WXDEFS=-DWIN32 -D__WXMSW__ -D_WINDOWS -DNOPCH6 DEBUGFLAGS=-g -D__WXDEBUG__7-CFLAGS=-mthreads -O0 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)8+CFLAGS=-mthreads -O2 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)9 HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \10     script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h11 

makefile.osx (added)

1--- /dev/null2+++ v0.2.9/makefile.osx3@@ -1 +1,66 @@4+# Copyright (c) 2009-2010 Satoshi Nakamoto5+# Distributed under the MIT/X11 software license, see the accompanying6+# file license.txt or http://www.opensource.org/licenses/mit-license.php.7 8+# Mac OS X makefile for bitcoin9+# Laszlo Hanyecz (solar@heliacal.net)10+11+DEPSDIR=/Users/macosuser/bitcoin/deps12+13+INCLUDEPATHS= \14+ -I"$(DEPSDIR)/include"15+16+LIBPATHS= \17+ -L"$(DEPSDIR)/lib"18+19+WXLIBS=$(shell $(DEPSDIR)/bin/wx-config --libs --static)20+21+LIBS= -dead_strip \22+ $(DEPSDIR)/lib/libdb_cxx-4.8.a \23+ $(DEPSDIR)/lib/libboost_system.a \24+ $(DEPSDIR)/lib/libboost_filesystem.a \25+ $(DEPSDIR)/lib/libcrypto.a 26+27+WXDEFS=$(shell $(DEPSDIR)/bin/wx-config --cxxflags) -DNOPCH -DMSG_NOSIGNAL=028+29+DEBUGFLAGS=-g -DwxDEBUG_LEVEL=030+# ppc doesn't work because we don't support big-endian31+CFLAGS=-mmacosx-version-min=10.5 -arch i386 -arch x86_64 -O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)32+HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \33+    script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h34+35+36+all: bitcoin37+38+39+obj/%.o: %.cpp $(HEADERS)40+	g++ -c $(CFLAGS) -o $@ $<41+42+obj/sha.o: sha.cpp sha.h43+	g++ -c $(CFLAGS) -O3 -o $@ $<44+45+OBJS= \46+    obj/util.o \47+    obj/script.o \48+    obj/db.o \49+    obj/net.o \50+    obj/irc.o \51+    obj/main.o \52+    obj/rpc.o \53+    obj/init.o54+	55+bitcoin: $(OBJS) obj/ui.o obj/uibase.o obj/sha.o56+	g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(WXLIBS) $(LIBS)57+58+59+obj/nogui/%.o: %.cpp $(HEADERS)60+	g++ -c $(CFLAGS) -DwxUSE_GUI=0 -o $@ $<61+62+bitcoind: $(OBJS:obj/%=obj/nogui/%) obj/sha.o63+	g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(WXLIBS) $(LIBS)64+65+66+clean:67+	-rm -f obj/*.o68+	-rm -f obj/nogui/*.o69+

makefile.unix (modified)

1--- v0.2.8/makefile.unix2+++ v0.2.9/makefile.unix3@@ -29,7 +29,7 @@4 5 WXDEFS=-D__WXGTK__ -DNOPCH6 DEBUGFLAGS=-g -D__WXDEBUG__7-CFLAGS=-O0 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)8+CFLAGS=-O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)9 HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \10     script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h11 

net.h (modified)

1--- v0.2.8/net.h2+++ v0.2.9/net.h3@@ -8,6 +8,7 @@4 class CRequestTracker;5 class CNode;6 class CBlockIndex;7+extern int nBestHeight;8 9 10 11@@ -59,7 +60,7 @@12     char pchMessageStart[sizeof(::pchMessageStart)];13     char pchCommand[COMMAND_SIZE];14     unsigned int nMessageSize;15-    //unsigned int nChecksum;16+    unsigned int nChecksum;17 18     CMessageHeader()19     {20@@ -67,7 +68,7 @@21         memset(pchCommand, 0, sizeof(pchCommand));22         pchCommand[1] = 1;23         nMessageSize = -1;24-        //nChecksum = 0;25+        nChecksum = 0;26     }27 28     CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn)29@@ -75,6 +76,7 @@30         memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart));31         strncpy(pchCommand, pszCommand, COMMAND_SIZE);32         nMessageSize = nMessageSizeIn;33+        nChecksum = 0;34     }35 36     IMPLEMENT_SERIALIZE37@@ -82,8 +84,8 @@38         READWRITE(FLATDATA(pchMessageStart));39         READWRITE(FLATDATA(pchCommand));40         READWRITE(nMessageSize);41-        //if (nVersion >= 209 && GetCommand() != "version")42-        //    READWRITE(nChecksum);43+        if (nVersion >= 209)44+            READWRITE(nChecksum);45     )46 47     string GetCommand()48@@ -470,6 +472,7 @@49 // Settings50 extern int fUseProxy;51 extern CAddress addrProxy;52+53 54 55 56@@ -507,6 +510,7 @@57     uint256 hashContinue;58     CBlockIndex* pindexLastGetBlocksBegin;59     uint256 hashLastGetBlocksEnd;60+    int nStartingHeight;61 62     // flood63     vector<CAddress> vAddrToSend;64@@ -529,7 +533,9 @@65         nServices = 0;66         hSocket = hSocketIn;67         vSend.SetType(SER_NETWORK);68+        vSend.SetVersion(0);69         vRecv.SetType(SER_NETWORK);70+        vRecv.SetVersion(0);71         nLastSend = 0;72         nLastRecv = 0;73         nLastSendEmpty = GetTime();74@@ -548,6 +554,7 @@75         hashContinue = 0;76         pindexLastGetBlocksBegin = 0;77         hashLastGetBlocksEnd = 0;78+        nStartingHeight = -1;79         fGetAddr = false;80         nNextSendTxInv = 0;81         vfSubscribe.assign(256, false);82@@ -558,7 +565,8 @@83         CAddress addrYou = (fUseProxy ? CAddress("0.0.0.0") : addr);84         CAddress addrMe = (fUseProxy ? CAddress("0.0.0.0") : addrLocalHost);85         RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce));86-        PushMessage("version", VERSION, nLocalServices, nTime, addrYou, addrMe, nLocalHostNonce, string(pszSubVer));87+        PushMessage("version", VERSION, nLocalServices, nTime, addrYou, addrMe,88+                    nLocalHostNonce, string(pszSubVer), nBestHeight);89     }90 91     ~CNode()92@@ -680,9 +688,19 @@93         if (nHeaderStart == -1)94             return;95 96-        // Patch in the size97+        // Set the size98         unsigned int nSize = vSend.size() - nMessageStart;99         memcpy((char*)&vSend[nHeaderStart] + offsetof(CMessageHeader, nMessageSize), &nSize, sizeof(nSize));100+101+        // Set the checksum102+        if (vSend.GetVersion() >= 209)103+        {104+            uint256 hash = Hash(vSend.begin() + nMessageStart, vSend.end());105+            unsigned int nChecksum = 0;106+            memcpy(&nChecksum, &hash, sizeof(nChecksum));107+            assert(nMessageStart - nHeaderStart >= offsetof(CMessageHeader, nChecksum) + sizeof(nChecksum));108+            memcpy((char*)&vSend[nHeaderStart] + offsetof(CMessageHeader, nChecksum), &nChecksum, sizeof(nChecksum));109+        }110 111         printf("(%d bytes) ", nSize);112         printf("\n");

rpc.cpp (modified)

1--- v0.2.8/rpc.cpp2+++ v0.2.9/rpc.cpp3@@ -26,7 +26,7 @@4 5 6 ///7-/// Note: I'm not finished designing this interface, it's still subject to change.8+/// Note: This interface may still be subject to change.9 ///10 11 12@@ -188,6 +188,73 @@13 }14 15 16+Value setlabel(const Array& params)17+{18+    if (params.size() < 1 || params.size() > 2)19+        throw runtime_error(20+            "setlabel <bitcoinaddress> <label>\n"21+            "Sets the label associated with the given address.");22+23+    string strAddress = params[0].get_str();24+    string strLabel;25+    if (params.size() > 1)26+        strLabel = params[1].get_str();27+28+    SetAddressBookName(strAddress, strLabel);29+    return Value::null;30+}31+32+33+Value getlabel(const Array& params)34+{35+    if (params.size() != 1)36+        throw runtime_error(37+            "getlabel <bitcoinaddress>\n"38+            "Returns the label associated with the given address.");39+40+    string strAddress = params[0].get_str();41+42+    string strLabel;43+    CRITICAL_BLOCK(cs_mapAddressBook)44+    {45+        map<string, string>::iterator mi = mapAddressBook.find(strAddress);46+        if (mi != mapAddressBook.end() && !(*mi).second.empty())47+            strLabel = (*mi).second;48+    }49+    return strLabel;50+}51+52+53+Value getaddressesbylabel(const Array& params)54+{55+    if (params.size() != 1)56+        throw runtime_error(57+            "getaddressesbylabel <label>\n"58+            "Returns the list of addresses with the given label.");59+60+    string strLabel = params[0].get_str();61+62+    // Find all addresses that have the given label63+    Array ret;64+    CRITICAL_BLOCK(cs_mapAddressBook)65+    {66+        foreach(const PAIRTYPE(string, string)& item, mapAddressBook)67+        {68+            const string& strAddress = item.first;69+            const string& strName = item.second;70+            if (strName == strLabel)71+            {72+                // We're only adding valid bitcoin addresses and not ip addresses73+                CScript scriptPubKey;74+                if (scriptPubKey.SetBitcoinAddress(strAddress))75+                    ret.push_back(strAddress);76+            }77+        }78+    }79+    return ret;80+}81+82+83 Value sendtoaddress(const Array& params)84 {85     if (params.size() < 2 || params.size() > 4)86@@ -237,11 +304,11 @@87 }88 89 90-Value getamountreceived(const Array& params)91+Value getreceivedbyaddress(const Array& params)92 {93     if (params.size() < 1 || params.size() > 2)94         throw runtime_error(95-            "getamountreceived <bitcoinaddress> [minconf=1]\n"96+            "getreceivedbyaddress <bitcoinaddress> [minconf=1]\n"97             "Returns the total amount received by <bitcoinaddress> in transactions with at least [minconf] confirmations.");98 99     // Bitcoin address100@@ -249,6 +316,8 @@101     CScript scriptPubKey;102     if (!scriptPubKey.SetBitcoinAddress(strAddress))103         throw runtime_error("Invalid bitcoin address");104+    if (!IsMine(scriptPubKey))105+        return (double)0.0;106 107     // Minimum confirmations108     int nMinDepth = 1;109@@ -276,6 +345,59 @@110 }111 112 113+Value getreceivedbylabel(const Array& params)114+{115+    if (params.size() < 1 || params.size() > 2)116+        throw runtime_error(117+            "getreceivedbylabel <label> [minconf=1]\n"118+            "Returns the total amount received by addresses with <label> in transactions with at least [minconf] confirmations.");119+120+    // Get the set of pub keys that have the label121+    string strLabel = params[0].get_str();122+    set<CScript> setPubKey;123+    CRITICAL_BLOCK(cs_mapAddressBook)124+    {125+        foreach(const PAIRTYPE(string, string)& item, mapAddressBook)126+        {127+            const string& strAddress = item.first;128+            const string& strName = item.second;129+            if (strName == strLabel)130+            {131+                // We're only counting our own valid bitcoin addresses and not ip addresses132+                CScript scriptPubKey;133+                if (scriptPubKey.SetBitcoinAddress(strAddress))134+                    if (IsMine(scriptPubKey))135+                        setPubKey.insert(scriptPubKey);136+            }137+        }138+    }139+140+    // Minimum confirmations141+    int nMinDepth = 1;142+    if (params.size() > 1)143+        nMinDepth = params[1].get_int();144+145+    // Tally146+    int64 nAmount = 0;147+    CRITICAL_BLOCK(cs_mapWallet)148+    {149+        for (map<uint256, CWalletTx>::iterator it = mapWallet.begin(); it != mapWallet.end(); ++it)150+        {151+            const CWalletTx& wtx = (*it).second;152+            if (wtx.IsCoinBase() || !wtx.IsFinal())153+                continue;154+155+            foreach(const CTxOut& txout, wtx.vout)156+                if (setPubKey.count(txout.scriptPubKey))157+                    if (wtx.GetDepthInMainChain() >= nMinDepth)158+                        nAmount += txout.nValue;159+        }160+    }161+162+    return (double)nAmount / (double)COIN;163+}164+165+166 struct tallyitem167 {168     int64 nAmount;169@@ -287,23 +409,18 @@170     }171 };172 173-Value getallreceived(const Array& params)174-{175-    if (params.size() > 1)176-        throw runtime_error(177-            "getallreceived [minconf=1]\n"178-            "[minconf] is the minimum number of confirmations before payments are included.\n"179-            "Returns an array of objects containing:\n"180-            "  \"address\" : receiving address\n"181-            "  \"amount\" : total amount received by the address\n"182-            "  \"confirmations\" : number of confirmations of the most recent transaction included\n"183-            "  \"label\" : the label of the receiving address");184-185+Value ListReceived(const Array& params, bool fByLabels)186+{187     // Minimum confirmations188     int nMinDepth = 1;189     if (params.size() > 0)190         nMinDepth = params[0].get_int();191 192+    // Whether to include empty accounts193+    bool fIncludeEmpty = false;194+    if (params.size() > 1)195+        fIncludeEmpty = params[1].get_bool();196+197     // Tally198     map<uint160, tallyitem> mapTally;199     CRITICAL_BLOCK(cs_mapWallet)200@@ -318,18 +435,11 @@201             if (nDepth < nMinDepth)202                 continue;203 204-            // Filter out debits and payments to self, which may have change return205-            // we don't want to count.206-            int64 nCredit = wtx.GetCredit(true);207-            int64 nDebit = wtx.GetDebit();208-            int64 nNet = nCredit - nDebit;209-            if (nNet <= 0)210-                continue;211-212             foreach(const CTxOut& txout, wtx.vout)213             {214+                // Only counting our own bitcoin addresses and not ip addresses215                 uint160 hash160 = txout.scriptPubKey.GetBitcoinAddressHash160();216-                if (hash160 == 0 || !mapPubKeys.count(hash160))217+                if (hash160 == 0 || !mapPubKeys.count(hash160)) // IsMine218                     continue;219 220                 tallyitem& item = mapTally[hash160];221@@ -341,26 +451,99 @@222 223     // Reply224     Array ret;225+    map<string, tallyitem> mapLabelTally;226     CRITICAL_BLOCK(cs_mapAddressBook)227     {228-        for (map<uint160, tallyitem>::iterator it = mapTally.begin(); it != mapTally.end(); ++it)229-        {230-            string strAddress = Hash160ToAddress((*it).first);231-            string strLabel;232-            map<string, string>::iterator mi = mapAddressBook.find(strAddress);233-            if (mi != mapAddressBook.end())234-                strLabel = (*mi).second;235-236+        foreach(const PAIRTYPE(string, string)& item, mapAddressBook)237+        {238+            const string& strAddress = item.first;239+            const string& strLabel = item.second;240+            uint160 hash160;241+            if (!AddressToHash160(strAddress, hash160))242+                continue;243+            map<uint160, tallyitem>::iterator it = mapTally.find(hash160);244+            if (it == mapTally.end() && !fIncludeEmpty)245+                continue;246+247+            int64 nAmount = 0;248+            int nConf = INT_MAX;249+            if (it != mapTally.end())250+            {251+                nAmount = (*it).second.nAmount;252+                nConf = (*it).second.nConf;253+            }254+255+            if (fByLabels)256+            {257+                tallyitem& item = mapLabelTally[strLabel];258+                item.nAmount += nAmount;259+                item.nConf = min(item.nConf, nConf);260+            }261+            else262+            {263+                Object obj;264+                obj.push_back(Pair("address",       strAddress));265+                obj.push_back(Pair("label",         strLabel));266+                obj.push_back(Pair("amount",        (double)nAmount / (double)COIN));267+                obj.push_back(Pair("confirmations", (nConf == INT_MAX ? 0 : nConf)));268+                ret.push_back(obj);269+            }270+        }271+    }272+273+    if (fByLabels)274+    {275+        for (map<string, tallyitem>::iterator it = mapLabelTally.begin(); it != mapLabelTally.end(); ++it)276+        {277+            int64 nAmount = (*it).second.nAmount;278+            int nConf = (*it).second.nConf;279             Object obj;280-            obj.push_back(Pair("address",       strAddress));281-            obj.push_back(Pair("amount",        (double)(*it).second.nAmount / (double)COIN));282-            obj.push_back(Pair("confirmations", (*it).second.nConf));283-            obj.push_back(Pair("label",         strLabel));284+            obj.push_back(Pair("label",         (*it).first));285+            obj.push_back(Pair("amount",        (double)nAmount / (double)COIN));286+            obj.push_back(Pair("confirmations", (nConf == INT_MAX ? 0 : nConf)));287             ret.push_back(obj);288         }289     }290+291     return ret;292 }293+294+Value listreceivedbyaddress(const Array& params)295+{296+    if (params.size() > 2)297+        throw runtime_error(298+            "listreceivedbyaddress [minconf=1] [includeempty=false]\n"299+            "[minconf] is the minimum number of confirmations before payments are included.\n"300+            "[includeempty] whether to include addresses that haven't received any payments.\n"301+            "Returns an array of objects containing:\n"302+            "  \"address\" : receiving address\n"303+            "  \"label\" : the label of the receiving address\n"304+            "  \"amount\" : total amount received by the address\n"305+            "  \"confirmations\" : number of confirmations of the most recent transaction included");306+307+    return ListReceived(params, false);308+}309+310+Value listreceivedbylabel(const Array& params)311+{312+    if (params.size() > 2)313+        throw runtime_error(314+            "listreceivedbylabel [minconf=1] [includeempty=false]\n"315+            "[minconf] is the minimum number of confirmations before payments are included.\n"316+            "[includeempty] whether to include labels that haven't received any payments.\n"317+            "Returns an array of objects containing:\n"318+            "  \"label\" : the label of the receiving addresses\n"319+            "  \"amount\" : total amount received by addresses with this label\n"320+            "  \"confirmations\" : number of confirmations of the most recent transaction included");321+322+    return ListReceived(params, true);323+}324+325+326+327+328+329+330 331 332 333@@ -375,20 +558,27 @@334 typedef Value(*rpcfn_type)(const Array& params);335 pair<string, rpcfn_type> pCallTable[] =336 {337-    make_pair("stop",               &stop),338-    make_pair("getblockcount",      &getblockcount),339-    make_pair("getblocknumber",     &getblocknumber),340-    make_pair("getconnectioncount", &getconnectioncount),341-    make_pair("getdifficulty",      &getdifficulty),342-    make_pair("getbalance",         &getbalance),343-    make_pair("getgenerate",        &getgenerate),344-    make_pair("setgenerate",        &setgenerate),345-    make_pair("getinfo",            &getinfo),346-    make_pair("getnewaddress",      &getnewaddress),347-    make_pair("sendtoaddress",      &sendtoaddress),348-    make_pair("listtransactions",   &listtransactions),349-    make_pair("getamountreceived",  &getamountreceived),350-    make_pair("getallreceived",     &getallreceived),351+    make_pair("stop",                  &stop),352+    make_pair("getblockcount",         &getblockcount),353+    make_pair("getblocknumber",        &getblocknumber),354+    make_pair("getconnectioncount",    &getconnectioncount),355+    make_pair("getdifficulty",         &getdifficulty),356+    make_pair("getbalance",            &getbalance),357+    make_pair("getgenerate",           &getgenerate),358+    make_pair("setgenerate",           &setgenerate),359+    make_pair("getinfo",               &getinfo),360+    make_pair("getnewaddress",         &getnewaddress),361+    make_pair("setlabel",              &setlabel),362+    make_pair("getlabel",              &getlabel),363+    make_pair("getaddressesbylabel",   &getaddressesbylabel),364+    make_pair("sendtoaddress",         &sendtoaddress),365+    make_pair("listtransactions",      &listtransactions),366+    make_pair("getamountreceived",     &getreceivedbyaddress), // deprecated, renamed to getreceivedbyaddress367+    make_pair("getallreceived",        &listreceivedbyaddress), // deprecated, renamed to listreceivedbyaddress368+    make_pair("getreceivedbyaddress",  &getreceivedbyaddress),369+    make_pair("getreceivedbylabel",    &getreceivedbylabel),370+    make_pair("listreceivedbyaddress", &listreceivedbyaddress),371+    make_pair("listreceivedbylabel",   &listreceivedbylabel),372 };373 map<string, rpcfn_type> mapCallTable(pCallTable, pCallTable + sizeof(pCallTable)/sizeof(pCallTable[0]));374 375@@ -666,13 +856,20 @@376         //377         // Special case other types378         //379-        if (strMethod == "setgenerate"       && n > 0) ConvertTo<bool>(params[0]);380-        if (strMethod == "setgenerate"       && n > 1) ConvertTo<boost::int64_t>(params[1]);381-        if (strMethod == "sendtoaddress"     && n > 1) ConvertTo<double>(params[1]);382-        if (strMethod == "listtransactions"  && n > 0) ConvertTo<boost::int64_t>(params[0]);383-        if (strMethod == "listtransactions"  && n > 1) ConvertTo<bool>(params[1]);384-        if (strMethod == "getamountreceived" && n > 1) ConvertTo<boost::int64_t>(params[1]);385-        if (strMethod == "getallreceived"    && n > 0) ConvertTo<boost::int64_t>(params[0]);386+        if (strMethod == "setgenerate"            && n > 0) ConvertTo<bool>(params[0]);387+        if (strMethod == "setgenerate"            && n > 1) ConvertTo<boost::int64_t>(params[1]);388+        if (strMethod == "sendtoaddress"          && n > 1) ConvertTo<double>(params[1]);389+        if (strMethod == "listtransactions"       && n > 0) ConvertTo<boost::int64_t>(params[0]);390+        if (strMethod == "listtransactions"       && n > 1) ConvertTo<bool>(params[1]);391+        if (strMethod == "getamountreceived"      && n > 1) ConvertTo<boost::int64_t>(params[1]); // deprecated392+        if (strMethod == "getreceivedbyaddress"   && n > 1) ConvertTo<boost::int64_t>(params[1]);393+        if (strMethod == "getreceivedbylabel"     && n > 1) ConvertTo<boost::int64_t>(params[1]);394+        if (strMethod == "getallreceived"         && n > 0) ConvertTo<boost::int64_t>(params[0]); // deprecated395+        if (strMethod == "getallreceived"         && n > 1) ConvertTo<bool>(params[1]);396+        if (strMethod == "listreceivedbyaddress"  && n > 0) ConvertTo<boost::int64_t>(params[0]);397+        if (strMethod == "listreceivedbyaddress"  && n > 1) ConvertTo<bool>(params[1]);398+        if (strMethod == "listreceivedbylabel"    && n > 0) ConvertTo<boost::int64_t>(params[0]);399+        if (strMethod == "listreceivedbylabel"    && n > 1) ConvertTo<bool>(params[1]);400 401         // Execute402         Value result = CallRPC(strMethod, params);

serialize.h (modified)

1--- v0.2.8/serialize.h2+++ v0.2.9/serialize.h3@@ -19,7 +19,7 @@4 class CDataStream;5 class CAutoFile;6 7-static const int VERSION = 208;8+static const int VERSION = 209;9 static const char* pszSubVer = ".0";10 11 12@@ -809,6 +809,18 @@13             vch.insert(it, first, last);14     }15 16+    void insert(iterator it, vector<char>::const_iterator first, vector<char>::const_iterator last)17+    {18+        if (it == vch.begin() + nReadPos && last - first <= nReadPos)19+        {20+            // special case for inserting at the front when there's room21+            nReadPos -= (last - first);22+            memcpy(&vch[nReadPos], &first[0], last - first);23+        }24+        else25+            vch.insert(it, first, last);26+    }27+28 #if !defined(_MSC_VER) || _MSC_VER >= 130029     void insert(iterator it, const char* first, const char* last)30     {

ui.cpp (modified)

1--- v0.2.8/ui.cpp2+++ v0.2.9/ui.cpp3@@ -191,6 +191,12 @@4           "Do you want to pay the fee?"),5         FormatMoney(nFeeRequired).c_str());6     return (ThreadSafeMessageBox(strMessage, strCaption, wxYES_NO, parent) == wxYES);7+}8+9+void CalledSetStatusBar(const string& strText, int nField)10+{11+    if (pframeMain && pframeMain->m_statusBar)12+        pframeMain->m_statusBar->SetStatusText(strText, nField);13 }14 15 void SetDefaultReceivingAddress(const string& strAddress)16@@ -268,7 +274,8 @@17     if (!strstr(DateTimeStr(1229413914).c_str(), "2008"))18         nDateWidth += 12;19 #ifdef __WXMAC__20-    nDateWidth += 2;21+    nDateWidth += 5;22+    dResize -= 0.01;23 #endif24     wxListCtrl* pplistCtrl[] = {m_listCtrlAll, m_listCtrlSentReceived, m_listCtrlSent, m_listCtrlReceived};25     foreach(wxListCtrl* p, pplistCtrl)

ui.h (modified)

1--- v0.2.8/ui.h2+++ v0.2.9/ui.h3@@ -30,6 +30,7 @@4 void UIThreadCall(boost::function0<void>);5 int ThreadSafeMessageBox(const string& message, const string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);6 bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent);7+void CalledSetStatusBar(const string& strText, int nField);8 void MainFrameRepaint();9 void CreateMainWindow();10 11@@ -46,6 +47,14 @@12 inline bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent)13 {14     return true;15+}16+17+inline void CalledSetStatusBar(const string& strText, int nField)18+{19+}20+21+inline void UIThreadCall(boost::function0<void> fn)22+{23 }24 25 inline void MainFrameRepaint()

uibase.h (modified)

1--- v0.2.8/uibase.h2+++ v0.2.9/uibase.h3@@ -77,7 +77,6 @@4 		wxMenu* m_menuFile;5 		wxMenu* m_menuHelp;6 		wxToolBar* m_toolBar;7-		wxStatusBar* m_statusBar;8 		9 		wxStaticText* m_staticText32;10 		wxButton* m_buttonNew;11@@ -121,6 +120,7 @@12 	13 	public:14 		wxMenu* m_menuOptions;15+		wxStatusBar* m_statusBar;16 		wxTextCtrl* m_textCtrlAddress;17 		wxListCtrl* m_listCtrlAll;18 		wxListCtrl* m_listCtrlSentReceived;

util.cpp (modified)

1--- v0.2.8/util.cpp2+++ v0.2.9/util.cpp3@@ -250,11 +250,6 @@4         if (p == NULL)5             throw std::bad_alloc();6     }7-#ifdef _MSC_VER8-    // msvc optimisation9-    if (p == buffer)10-        return string(p, p+ret);11-#endif12     string str(p, p+ret);13     if (p != buffer)14         delete p;
0:000:00