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.5 → v0.2.6

7 files · +208 · −48 · cb420a1df · 2010-02-23 · s_nakamoto

Release commit message: run as daemon without GUI, hooked wxApp::Initialize to ignore gtk-init-check failure if no GUI, fork to daemonize, rpc getinfo, getconnectioncount, getbalance, getgenerate, setgenerate, -- version 0.2.6

Previous diff: v0.2.4 → v0.2.5. Next: v0.2.6 → v0.2.7.

main.cpp (modified)

1--- v0.2.5/main.cpp2+++ v0.2.6/main.cpp3@@ -1315,11 +1315,10 @@4     if (nTime <= pindexPrev->GetMedianTimePast())5         return error("AcceptBlock() : block's timestamp is too early");6 7-    // Check that all transactions are finalized (starting around Mar 2010)8-    if (nBestHeight > 36000)9-        foreach(const CTransaction& tx, vtx)10-            if (!tx.IsFinal(nTime))11-                return error("AcceptBlock() : contains a non-final transaction");12+    // Check that all transactions are finalized13+    foreach(const CTransaction& tx, vtx)14+        if (!tx.IsFinal(nTime))15+            return error("AcceptBlock() : contains a non-final transaction");16 17     // Check proof of work18     if (nBits != GetNextWorkRequired(pindexPrev))19@@ -1336,7 +1335,7 @@20         return error("AcceptBlock() : AddToBlockIndex failed");21 22     // Don't relay old inventory during initial block download.23-    // Please keep this constant updated to a few thousand below current block count.24+    // Please keep this number updated to a few thousand below current block count.25     if (hashBestChain == hash && nBestHeight > 40000)26         RelayInventory(CInv(MSG_BLOCK, hash));27 28@@ -1556,8 +1555,8 @@29         CTransaction txNew;30         txNew.vin.resize(1);31         txNew.vout.resize(1);32-        txNew.vin[0].scriptSig     = CScript() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));33-        txNew.vout[0].nValue       = 50 * COIN;34+        txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(4) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));35+        txNew.vout[0].nValue = 50 * COIN;36         CBigNum bnPubKey;37         bnPubKey.SetHex("0x5F1DF16B2B704C8A578D0BBAF74D385CDE12C11EE50455F3C438EF4C3FBCF649B6DE611FEAE06279A60939E028A8D65C10B73071A6F16719274855FEB0FD8A6704");38         txNew.vout[0].scriptPubKey = CScript() << bnPubKey << OP_CHECKSIG;

main.h (modified)

1--- v0.2.5/main.h2+++ v0.2.6/main.h3@@ -1384,6 +1384,9 @@4     CPrivKey vchPrivKey;5     int64 nTimeCreated;6     int64 nTimeExpires;7+    string strComment;8+    //// todo: add something to note what created it (user, getnewaddress, change)9+    ////   maybe should have a map<string, string> property map10 11     CWalletKey(int64 nTimeExpiresIn=0)12     {13@@ -1398,6 +1401,7 @@14         READWRITE(vchPrivKey);15         READWRITE(nTimeCreated);16         READWRITE(nTimeExpires);17+        READWRITE(strComment);18     )19 };20 

rpc.cpp (modified)

1--- v0.2.5/rpc.cpp2+++ v0.2.6/rpc.cpp3@@ -66,6 +66,17 @@4 }5 6 7+Value getconnectioncount(const Array& params)8+{9+    if (params.size() != 0)10+        throw runtime_error(11+            "getconnectioncount (no parameters)\n"12+            "Returns the number of connections to other nodes.");13+14+    return (int)vNodes.size();15+}16+17+18 Value getdifficulty(const Array& params)19 {20     if (params.size() != 0)21@@ -85,6 +96,71 @@22 }23 24 25+Value getbalance(const Array& params)26+{27+    if (params.size() != 0)28+        throw runtime_error(29+            "getbalance (no parameters)\n"30+            "Returns the server's available balance.");31+32+    return ((double)GetBalance() / (double)COIN);33+}34+35+36+Value getgenerate(const Array& params)37+{38+    if (params.size() != 0)39+        throw runtime_error(40+            "getgenerate (no parameters)\n"41+            "Returns true or false.");42+43+    return (bool)fGenerateBitcoins;44+}45+46+47+Value setgenerate(const Array& params)48+{49+    if (params.size() < 1 || params.size() > 2)50+        throw runtime_error(51+            "setgenerate <generate> [genproclimit]\n"52+            "<generate> is true or false to turn generation on or off.\n"53+            "Generation is limited to [genproclimit] processors, -1 is unlimited.");54+55+    bool fGenerate = true;56+    if (params.size() > 0)57+        fGenerate = params[0].get_bool();58+59+    if (params.size() > 1)60+    {61+        int nGenProcLimit = params[1].get_int();62+        fLimitProcessors = (nGenProcLimit != -1);63+        CWalletDB().WriteSetting("fLimitProcessors", fLimitProcessors);64+        if (nGenProcLimit != -1)65+            CWalletDB().WriteSetting("nLimitProcessors", nLimitProcessors = nGenProcLimit);66+    }67+68+    GenerateBitcoins(fGenerate);69+    return Value::null;70+}71+72+73+Value getinfo(const Array& params)74+{75+    if (params.size() != 0)76+        throw runtime_error(77+            "getinfo (no parameters)");78+79+    Object obj;80+    obj.push_back(Pair("balance",       (double)GetBalance() / (double)COIN));81+    obj.push_back(Pair("blocks",        (int)nBestHeight + 1));82+    obj.push_back(Pair("connections",   (int)vNodes.size()));83+    obj.push_back(Pair("proxy",         (fUseProxy ? addrProxy.ToStringIPPort() : string())));84+    obj.push_back(Pair("generate",      (bool)fGenerateBitcoins));85+    obj.push_back(Pair("genproclimit",  (int)(fLimitProcessors ? nLimitProcessors : -1)));86+    return obj;87+}88+89+90 Value getnewaddress(const Array& params)91 {92     if (params.size() > 1)93@@ -102,8 +178,7 @@94     // Generate a new key that is added to wallet95     string strAddress = PubKeyToAddress(GenerateNewKey());96 97-    if (params.size() > 0)98-        SetAddressBookName(strAddress, strLabel);99+    SetAddressBookName(strAddress, strLabel);100     return strAddress;101 }102 103@@ -214,10 +289,10 @@104             "getallreceived [minconf=1]\n"105             "[minconf] is the minimum number of confirmations before payments are included.\n"106             "Returns an array of objects containing:\n"107-            "  \"address\" : bitcoin address\n"108+            "  \"address\" : receiving address\n"109             "  \"amount\" : total amount received by the address\n"110-            "  \"conf\" : number of confirmations\n"111-            "  \"label\" : the label set for this address when it was created by getnewaddress");112+            "  \"confirmations\" : number of confirmations of the most recent transaction included\n"113+            "  \"label\" : the label of the receiving address");114 115     // Minimum confirmations116     int nMinDepth = 1;117@@ -235,18 +310,26 @@118                 continue;119 120             int nDepth = wtx.GetDepthInMainChain();121-            if (nDepth >= nMinDepth)122+            if (nDepth < nMinDepth)123+                continue;124+125+            // Filter out debits and payments to self, which may have change return126+            // we don't want to count.127+            int64 nCredit = wtx.GetCredit(true);128+            int64 nDebit = wtx.GetDebit();129+            int64 nNet = nCredit - nDebit;130+            if (nNet <= 0)131+                continue;132+133+            foreach(const CTxOut& txout, wtx.vout)134             {135-                foreach(const CTxOut& txout, wtx.vout)136-                {137-                    uint160 hash160 = txout.scriptPubKey.GetBitcoinAddressHash160();138-                    if (hash160 == 0 || !mapPubKeys.count(hash160))139-                        continue;140-141-                    tallyitem& item = mapTally[hash160];142-                    item.nAmount += txout.nValue;143-                    item.nConf = min(item.nConf, nDepth);144-                }145+                uint160 hash160 = txout.scriptPubKey.GetBitcoinAddressHash160();146+                if (hash160 == 0 || !mapPubKeys.count(hash160))147+                    continue;148+149+                tallyitem& item = mapTally[hash160];150+                item.nAmount += txout.nValue;151+                item.nConf = min(item.nConf, nDepth);152             }153         }154     }155@@ -264,10 +347,10 @@156                 strLabel = (*mi).second;157 158             Object obj;159-            obj.push_back(Pair("address", strAddress));160-            obj.push_back(Pair("amount",  (double)(*it).second.nAmount / (double)COIN));161-            obj.push_back(Pair("conf",    (*it).second.nConf));162-            obj.push_back(Pair("label",   strLabel));163+            obj.push_back(Pair("address",       strAddress));164+            obj.push_back(Pair("amount",        (double)(*it).second.nAmount / (double)COIN));165+            obj.push_back(Pair("confirmations", (*it).second.nConf));166+            obj.push_back(Pair("label",         strLabel));167             ret.push_back(obj);168         }169     }170@@ -290,7 +373,12 @@171     make_pair("stop",               &stop),172     make_pair("getblockcount",      &getblockcount),173     make_pair("getblocknumber",     &getblocknumber),174+    make_pair("getconnectioncount", &getconnectioncount),175     make_pair("getdifficulty",      &getdifficulty),176+    make_pair("getbalance",         &getbalance),177+    make_pair("getgenerate",        &getgenerate),178+    make_pair("setgenerate",        &setgenerate),179+    make_pair("getinfo",            &getinfo),180     make_pair("getnewaddress",      &getnewaddress),181     make_pair("sendtoaddress",      &sendtoaddress),182     make_pair("listtransactions",   &listtransactions),183@@ -568,9 +656,13 @@184         Array params;185         for (int i = 2; i < argc; i++)186             params.push_back(argv[i]);187-188+        int n = params.size();189+190+        //191         // Special case other types192-        int n = params.size();193+        //194+        if (strMethod == "setgenerate"       && n > 0) ConvertTo<bool>(params[0]);195+        if (strMethod == "setgenerate"       && n > 1) ConvertTo<boost::int64_t>(params[1]);196         if (strMethod == "sendtoaddress"     && n > 1) ConvertTo<double>(params[1]);197         if (strMethod == "listtransactions"  && n > 0) ConvertTo<boost::int64_t>(params[0]);198         if (strMethod == "listtransactions"  && n > 1) ConvertTo<bool>(params[1]);

serialize.h (modified)

1--- v0.2.5/serialize.h2+++ v0.2.6/serialize.h3@@ -19,7 +19,7 @@4 class CDataStream;5 class CAutoFile;6 7-static const int VERSION = 205;8+static const int VERSION = 206;9 static const char* pszSubVer = ".0";10 11 

ui.cpp (modified)

1--- v0.2.5/ui.cpp2+++ v0.2.6/ui.cpp3@@ -23,6 +23,20 @@4 int fMinimizeToTray = true;5 int fMinimizeOnClose = true;6 7+8+9+10+int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)11+{12+    if (fDaemon)13+    {14+        printf("wxMessageBox %s: %s\n", string(caption).c_str(), string(message).c_str());15+        fprintf(stderr, "%s: %s\n", string(caption).c_str(), string(message).c_str());16+        return wxOK;17+    }18+    return wxMessageBox(message, caption, style, parent, x, y);19+}20+#define wxMessageBox  MyMessageBox21 22 23 24@@ -209,16 +223,10 @@25 26 int ThreadSafeMessageBox(const string& message, const string& caption, int style, wxWindow* parent, int x, int y)27 {28-    if (fDaemon)29-    {30-        printf("wxMessageBox %s: %s\n", caption.c_str(), message.c_str());31-        return wxOK;32-    }33-34 #ifdef __WXMSW__35     return wxMessageBox(message, caption, style, parent, x, y);36 #else37-    if (wxThread::IsMain())38+    if (wxThread::IsMain() || fDaemon)39     {40         return wxMessageBox(message, caption, style, parent, x, y);41     }42@@ -563,7 +571,7 @@43 bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)44 {45     int64 nTime = wtx.nTimeDisplayed = wtx.GetTxTime();46-    int64 nCredit = wtx.GetCredit();47+    int64 nCredit = wtx.GetCredit(true);48     int64 nDebit = wtx.GetDebit();49     int64 nNet = nCredit - nDebit;50     uint256 hash = wtx.GetHash();51@@ -2571,6 +2579,9 @@52     bool OnInit2();53     int OnExit();54 55+    // Hook Initialize so we can start without GUI56+    virtual bool Initialize(int& argc, wxChar** argv);57+58     // 2nd-level exception handling: we get all the exceptions occurring in any59     // event handler here60     virtual bool OnExceptionInMainLoop();61@@ -2585,6 +2596,64 @@62 };63 64 IMPLEMENT_APP(CMyApp)65+66+bool CMyApp::Initialize(int& argc, wxChar** argv)67+{68+    if (argc > 1 && argv[1][0] != '-' && (!fWindows || argv[1][0] != '/') &&69+        wxString(argv[1]) != "start")70+    {71+        fCommandLine = true;72+    }73+    else74+    {75+        // wxApp::Initialize will remove environment-specific parameters,76+        // so it's too early to call ParseParameters yet77+        for (int i = 1; i < argc; i++)78+        {79+            wxString str = argv[i];80+            #ifdef __WXMSW__81+            if (str.size() >= 1 && str[0] == '/')82+                str[0] = '-';83+            str = str.MakeLower();84+            #endif85+            // haven't decided which argument to use for this yet86+            if (str == "-daemon" || str == "-d" || str == "start")87+                fDaemon = true;88+        }89+    }90+91+#ifdef __WXGTK__92+    if (fDaemon || fCommandLine)93+    {94+        // Call the original Initialize while suppressing error messages95+        // and ignoring failure.  If unable to initialize GTK, it fails96+        // near the end so hopefully the last few things don't matter.97+        {98+            wxLogNull logNo;99+            wxApp::Initialize(argc, argv);100+        }101+102+        if (fDaemon)103+        {104+            fprintf(stdout, "bitcoin server starting\n");105+106+            // Daemonize107+            pid_t pid = fork();108+            if (pid < 0)109+            {110+                fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);111+                return false;112+            }113+            if (pid > 0)114+                pthread_exit((void*)0);115+        }116+117+        return true;118+    }119+#endif120+121+    return wxApp::Initialize(argc, argv);122+}123 124 bool CMyApp::OnInit()125 {126@@ -2650,7 +2719,7 @@127     //128     // Parameters129     //130-    if (argc > 1 && argv[1][0] != '-' && argv[1][0] != '/')131+    if (fCommandLine)132     {133         int ret = CommandLineRPC(argc, argv);134         exit(ret);135@@ -2695,13 +2764,6 @@136 137     if (mapArgs.count("-printtodebugger"))138         fPrintToDebugger = true;139-140-    if (mapArgs.count("-daemon") || mapArgs.count("-d"))141-    {142-        fDaemon = true;143-        /// todo: need to fork144-        ///  should it fork after the bind/single instance stuff?145-    }146 147     if (!fDebug && !pszSetDataDir[0])148         ShrinkDebugFile();

util.cpp (modified)

1--- v0.2.5/util.cpp2+++ v0.2.6/util.cpp3@@ -13,6 +13,7 @@4 char pszSetDataDir[MAX_PATH] = "";5 bool fShutdown = false;6 bool fDaemon = false;7+bool fCommandLine = false;8 9 10 11@@ -500,7 +501,8 @@12     char pszMessage[1000];13     FormatException(pszMessage, pex, pszThread);14     printf("\n\n************************\n%s\n", pszMessage);15-    if (wxTheApp)16+    fprintf(stderr, "\n\n************************\n%s\n", pszMessage);17+    if (wxTheApp && !fDaemon)18         wxMessageBox(pszMessage, "Error", wxOK | wxICON_ERROR);19     throw;20     //DebugBreak();

util.h (modified)

1--- v0.2.5/util.h2+++ v0.2.6/util.h3@@ -121,6 +121,7 @@4 extern char pszSetDataDir[MAX_PATH];5 extern bool fShutdown;6 extern bool fDaemon;7+extern bool fCommandLine;8 9 void RandAddSeed();10 void RandAddSeedPerfmon();
0:000:00