Check setsockopt for error
[novacoin.git] / src / main.h
index 3d6bfa1..b8e6cb7 100644 (file)
@@ -13,6 +13,7 @@
 #include "net.h"
 #include "script.h"
 #include "scrypt.h"
+#include "ui_interface.h"
 
 #include <limits>
 #include <list>
@@ -84,7 +85,7 @@ extern const string strMessageMagic;
 extern int64_t nTimeBestReceived;
 extern CCriticalSection cs_setpwalletRegistered;
 extern set<CWallet*> setpwalletRegistered;
-extern unsigned char pchMessageStart[4];
+extern uint32_t nNetworkID;
 extern map<uint256, CBlock*> mapOrphanBlocks;
 
 // Settings
@@ -116,7 +117,7 @@ void PrintBlockTree();
 CBlockIndex* FindBlockByHeight(int nHeight);
 bool ProcessMessages(CNode* pfrom);
 bool SendMessages(CNode* pto);
-bool LoadExternalBlockFile(FILE* fileIn);
+bool LoadExternalBlockFile(FILE* fileIn, CClientUIInterface& uiInterface);
 
 // Run an instance of the script checking thread
 void ThreadScriptCheck(void* parg);
@@ -189,7 +190,7 @@ public:
         if (IsNull())
             return "null";
         else
-            return strprintf("(nFile=%u, nBlockPos=%u, nTxPos=%u)", nFile, nBlockPos, nTxPos);
+            return strprintf("(nFile=%" PRIu32 ", nBlockPos=%" PRIu32 ", nTxPos=%" PRIu32 ")", nFile, nBlockPos, nTxPos);
     }
 
     void print() const
@@ -245,7 +246,7 @@ public:
 
     string ToString() const
     {
-        return strprintf("COutPoint(%s, %u)", hash.ToString().substr(0,10).c_str(), n);
+        return strprintf("COutPoint(%s, %" PRIu32 ")", hash.ToString().substr(0,10).c_str(), n);
     }
 
     void print() const
@@ -326,7 +327,7 @@ public:
         else
             str += strprintf(", scriptSig=%s", scriptSig.ToString().substr(0,24).c_str());
         if (nSequence != numeric_limits<unsigned int>::max())
-            str += strprintf(", nSequence=%u", nSequence);
+            str += strprintf(", nSequence=%" PRIu32, nSequence);
         str += ")";
         return str;
     }
@@ -731,10 +732,10 @@ class CScriptCheck
 {
 private:
     CScript scriptPubKey;
-    const CTransaction *ptxTo;
-    unsigned int nIn;
-    unsigned int nFlags;
-    int nHashType;
+    const CTransaction *ptxTo = nullptr;
+    unsigned int nIn = 0;
+    unsigned int nFlags = 0;
+    int nHashType = 0;
 
 public:
     CScriptCheck() {}
@@ -964,9 +965,9 @@ public:
         if (nHeight >= 9689 || fTestNet)
         {
             // Take last bit of block hash as entropy bit
-            unsigned int nEntropyBit = (GetHash().Get64()) & (uint64_t)1;
+            auto nEntropyBit = (GetHash().Get32()) & (uint32_t)1;
             if (fDebug && GetBoolArg("-printstakemodifier"))
-                printf("GetStakeEntropyBit: nTime=%u hashBlock=%s nEntropyBit=%u\n", nTime, GetHash().ToString().c_str(), nEntropyBit);
+                printf("GetStakeEntropyBit: nTime=%" PRIu32 " hashBlock=%s nEntropyBit=%" PRIu32 "\n", nTime, GetHash().ToString().c_str(), nEntropyBit);
             return nEntropyBit;
         }
 
@@ -974,9 +975,9 @@ public:
         int nBitNum = nHeight & 0xFF;
         int nItemNum = nHeight / 0xFF;
 
-        unsigned int nEntropyBit = (unsigned int) ((entropyStore[nItemNum] & (uint256(1) << nBitNum)) >> nBitNum).Get64();
+        auto nEntropyBit = ((entropyStore[nItemNum] & (uint256(1) << nBitNum)) >> nBitNum).Get32();
         if (fDebug && GetBoolArg("-printstakemodifier"))
-            printf("GetStakeEntropyBit: from pregenerated table, nHeight=%d nEntropyBit=%u\n", nHeight, nEntropyBit);
+            printf("GetStakeEntropyBit: from pregenerated table, nHeight=%" PRIu32 " nEntropyBit=%" PRIu32 "\n", nHeight, nEntropyBit);
         return nEntropyBit;
     }
 
@@ -995,7 +996,6 @@ public:
     {
         if (IsProofOfStake())
             return { vtx[1].vin[0].prevout, vtx[1].nTime };
-
         return { COutPoint(), (unsigned int)0 };
     }
 
@@ -1003,7 +1003,7 @@ public:
     int64_t GetMaxTransactionTime() const
     {
         int64_t maxTransactionTime = 0;
-        for(const auto& tx :  vtx)
+        for(const auto& tx : vtx)
             maxTransactionTime = max(maxTransactionTime, (int64_t)tx.nTime);
         return maxTransactionTime;
     }
@@ -1019,8 +1019,8 @@ public:
             for (int i = 0; i < nSize; i += 2)
             {
                 int i2 = min(i+1, nSize-1);
-                vMerkleTree.push_back(Hash(BEGIN(vMerkleTree[j+i]),  END(vMerkleTree[j+i]),
-                                           BEGIN(vMerkleTree[j+i2]), END(vMerkleTree[j+i2])));
+                vMerkleTree.push_back(Hash(vMerkleTree[j+i].begin(),  vMerkleTree[j+i].end(),
+                                           vMerkleTree[j+i2].begin(), vMerkleTree[j+i2].end()));
             }
             j += nSize;
         }
@@ -1050,9 +1050,9 @@ public:
         for(const uint256& otherside :  vMerkleBranch)
         {
             if (nIndex & 1)
-                hash = Hash(BEGIN(otherside), END(otherside), BEGIN(hash), END(hash));
+                hash = Hash(otherside.begin(), otherside.end(), hash.begin(), hash.end());
             else
-                hash = Hash(BEGIN(hash), END(hash), BEGIN(otherside), END(otherside));
+                hash = Hash(hash.begin(), hash.end(), otherside.begin(), otherside.end());
             nIndex >>= 1;
         }
         return hash;
@@ -1068,7 +1068,7 @@ public:
 
         // Write index header
         unsigned int nSize = fileout.GetSerializeSize(*this);
-        fileout << FLATDATA(pchMessageStart) << nSize;
+        fileout << nNetworkID << nSize;
 
         // Write block
         long fileOutPos = ftell(fileout);
@@ -1115,7 +1115,7 @@ public:
 
     void print() const
     {
-        printf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%" PRIszu ", vchBlockSig=%s)\n",
+        printf("CBlock(hash=%s, ver=%" PRId32 ", hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%" PRIu32 ", nBits=%08x, nNonce=%" PRIu32 ", vtx=%" PRIszu ", vchBlockSig=%s)\n",
             GetHash().ToString().c_str(),
             nVersion,
             hashPrevBlock.ToString().c_str(),
@@ -1450,7 +1450,7 @@ public:
 
     uint256 GetBlockHash() const
     {
-        if (fUseFastIndex && (nTime < GetAdjustedTime() - nOneDay) && blockHash != 0)
+        if (fUseFastIndex && blockHash != 0)
             return blockHash;
 
         CBlock block;
@@ -1644,12 +1644,12 @@ public:
         return mapTx.size();
     }
 
-    bool exists(uint256 hash)
+    bool exists(const uint256 &hash)
     {
         return (mapTx.count(hash) != 0);
     }
 
-    CTransaction& lookup(uint256 hash)
+    CTransaction& lookup(const uint256 &hash)
     {
         return mapTx[hash];
     }