PPCoin: Move CSyncCheckpoint class outside of Checkpoints namespace
authorSunny King <sunnyking9999@gmail.com>
Sun, 10 Jun 2012 23:55:01 +0000 (00:55 +0100)
committerSunny King <sunnyking9999@gmail.com>
Sun, 10 Jun 2012 23:55:01 +0000 (00:55 +0100)
src/checkpoints.cpp
src/checkpoints.h
src/main.cpp

index aeb0be7..8ea198c 100644 (file)
@@ -83,31 +83,6 @@ namespace Checkpoints
         return true;
     }
 
-    bool CSyncCheckpoint::ProcessSyncCheckpoint(CNode* pfrom)
-    {
-        if (!CheckSignature())
-            return false;
-
-        CRITICAL_BLOCK(cs_hashSyncCheckpoint)
-        {
-            if (!mapBlockIndex.count(hashCheckpoint))
-            {
-                // We haven't accepted this block, keep the checkpoint as pending
-                checkpointMessagePending = *this;
-                // Ask this guy to fill in what we're missing
-                if (pfrom)
-                    pfrom->PushGetBlocks(pindexBest, hashCheckpoint);
-                return false;
-            }
-            if (!ValidateSyncCheckpoint(hashCheckpoint))
-                return false;
-            hashSyncCheckpoint = this->hashCheckpoint;
-            checkpointMessage = *this;
-            checkpointMessagePending.SetNull();
-        }
-        return true;
-    }
-
     bool AcceptPendingSyncCheckpoint(uint256 hashAcceptedBlock)
     {
         if (!mapBlockIndex.count(hashAcceptedBlock))
@@ -247,3 +222,29 @@ namespace Checkpoints
         return true;
     }
 }
+
+// ppcoin: process synchronized checkpoint
+bool CSyncCheckpoint::ProcessSyncCheckpoint(CNode* pfrom)
+{
+    if (!CheckSignature())
+        return false;
+
+    CRITICAL_BLOCK(Checkpoints::cs_hashSyncCheckpoint)
+    {
+        if (!mapBlockIndex.count(hashCheckpoint))
+        {
+            // We haven't accepted this block, keep the checkpoint as pending
+            Checkpoints::checkpointMessagePending = *this;
+            // Ask this guy to fill in what we're missing
+            if (pfrom)
+                pfrom->PushGetBlocks(pindexBest, hashCheckpoint);
+            return false;
+        }
+        if (!Checkpoints::ValidateSyncCheckpoint(hashCheckpoint))
+            return false;
+        Checkpoints::hashSyncCheckpoint = this->hashCheckpoint;
+        Checkpoints::checkpointMessage = *this;
+        Checkpoints::checkpointMessagePending.SetNull();
+    }
+    return true;
+}
index 92c14b7..d193a2a 100644 (file)
 class uint256;
 class CBlockIndex;
 
-//
-// Block-chain checkpoints are compiled-in sanity checks.
-// They are updated every release or three.
-//
-namespace Checkpoints
+// ppcoin: synchronized checkpoint
+class CUnsignedSyncCheckpoint
 {
-    // Returns true if block passes checkpoint checks
-    bool CheckHardened(int nHeight, const uint256& hash);
+public:
+    int nVersion;
+    uint256 hashCheckpoint;      // checkpoint block
+
+    IMPLEMENT_SERIALIZE
+    (
+        READWRITE(this->nVersion);
+        nVersion = this->nVersion;
+        READWRITE(hashCheckpoint);
+    )
+
+    void SetNull()
+    {
+        nVersion = 1;
+        hashCheckpoint = 0;
+    }
 
-    // Return conservative estimate of total number of blocks, 0 if unknown
-    int GetTotalBlocksEstimate();
+    std::string ToString() const
+    {
+        return strprintf(
+                "CSyncCheckpoint(\n"
+                "    nVersion       = %d\n"
+                "    hashCheckpoint = %s\n"
+                ")\n",
+            nVersion,
+            hashCheckpoint.ToString().c_str());
+    }
+
+    void print() const
+    {
+        printf("%s", ToString().c_str());
+    }
+};
 
-    // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
-    CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
+class CSyncCheckpoint : public CUnsignedSyncCheckpoint
+{
+public:
+    std::vector<unsigned char> vchMsg;
+    std::vector<unsigned char> vchSig;
 
-    // ppcoin: synchronized checkpoint
-    class CUnsignedSyncCheckpoint
+    CSyncCheckpoint()
     {
-    public:
-        int nVersion;
-        uint256 hashCheckpoint;      // checkpoint block
-
-        IMPLEMENT_SERIALIZE
-        (
-            READWRITE(this->nVersion);
-            nVersion = this->nVersion;
-            READWRITE(hashCheckpoint);
-        )
-
-        void SetNull()
-        {
-            nVersion = 1;
-            hashCheckpoint = 0;
-        }
+        SetNull();
+    }
 
-        std::string ToString() const
-        {
-            return strprintf(
-                    "CSyncCheckpoint(\n"
-                    "    nVersion       = %d\n"
-                    "    hashCheckpoint = %s\n"
-                    ")\n",
-                nVersion,
-                hashCheckpoint.ToString().c_str());
-        }
+    IMPLEMENT_SERIALIZE
+    (
+        READWRITE(vchMsg);
+        READWRITE(vchSig);
+    )
 
-        void print() const
-        {
-            printf("%s", ToString().c_str());
-        }
-    };
-
-    class CSyncCheckpoint : public CUnsignedSyncCheckpoint
+    void SetNull()
     {
-    public:
-        std::vector<unsigned char> vchMsg;
-        std::vector<unsigned char> vchSig;
+        CUnsignedSyncCheckpoint::SetNull();
+        vchMsg.clear();
+        vchSig.clear();
+    }
 
-        CSyncCheckpoint()
-        {
-            SetNull();
-        }
+    bool IsNull() const
+    {
+        return (hashCheckpoint == 0);
+    }
 
-        IMPLEMENT_SERIALIZE
-        (
-            READWRITE(vchMsg);
-            READWRITE(vchSig);
-        )
+    uint256 GetHash() const
+    {
+        return SerializeHash(*this);
+    }
 
-        void SetNull()
+    bool RelayTo(CNode* pnode) const
+    {
+        // returns true if wasn't already sent
+        if (pnode->hashCheckpointKnown != hashCheckpoint)
         {
-            CUnsignedSyncCheckpoint::SetNull();
-            vchMsg.clear();
-            vchSig.clear();
+            pnode->hashCheckpointKnown = hashCheckpoint;
+            pnode->PushMessage("checkpoint", *this);
+            return true;
         }
+        return false;
+    }
 
-        bool IsNull() const
-        {
-            return (hashCheckpoint == 0);
-        }
+    bool CheckSignature()
+    {
+        CKey key;
+        if (!key.SetPubKey(ParseHex("0487ca85b6ae9d311f996c7616d20d0c88a5b4f07d25e78f419019f35cce6522acf978b2d99f0e7a58db1f120439e5c1889266927854aa57c93956c2569188a539")))
+            return error("CSyncCheckpoint::CheckSignature() : SetPubKey failed");
+        if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
+            return error("CSyncCheckpoint::CheckSignature() : verify signature failed");
 
-        uint256 GetHash() const
-        {
-            return SerializeHash(*this);
-        }
+        // Now unserialize the data
+        CDataStream sMsg(vchMsg);
+        sMsg >> *(CUnsignedSyncCheckpoint*)this;
+        return true;
+    }
 
-        bool RelayTo(CNode* pnode) const
-        {
-            // returns true if wasn't already sent
-            if (pnode->hashCheckpointKnown != hashCheckpoint)
-            {
-                pnode->hashCheckpointKnown = hashCheckpoint;
-                pnode->PushMessage("checkpoint", *this);
-                return true;
-            }
-            return false;
-        }
+    bool ProcessSyncCheckpoint(CNode* pfrom);
+};
 
-        bool CheckSignature()
-        {
-            CKey key;
-            if (!key.SetPubKey(ParseHex("0487ca85b6ae9d311f996c7616d20d0c88a5b4f07d25e78f419019f35cce6522acf978b2d99f0e7a58db1f120439e5c1889266927854aa57c93956c2569188a539")))
-                return error("CSyncCheckpoint::CheckSignature() : SetPubKey failed");
-            if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
-                return error("CSyncCheckpoint::CheckSignature() : verify signature failed");
-
-            // Now unserialize the data
-            CDataStream sMsg(vchMsg);
-            sMsg >> *(CUnsignedSyncCheckpoint*)this;
-            return true;
-        }
+//
+// Block-chain checkpoints are compiled-in sanity checks.
+// They are updated every release or three.
+//
+namespace Checkpoints
+{
+    // Returns true if block passes checkpoint checks
+    bool CheckHardened(int nHeight, const uint256& hash);
+
+    // Return conservative estimate of total number of blocks, 0 if unknown
+    int GetTotalBlocksEstimate();
 
-        bool ProcessSyncCheckpoint(CNode* pfrom);
-    };
+    // Returns last CBlockIndex* in mapBlockIndex that is a checkpoint
+    CBlockIndex* GetLastCheckpoint(const std::map<uint256, CBlockIndex*>& mapBlockIndex);
 
     extern uint256 hashSyncCheckpoint;
     extern CSyncCheckpoint checkpointMessage;
index d6c10a4..f1b2694 100644 (file)
@@ -2588,7 +2588,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
 
     else if (strCommand == "checkpoint")
     {
-        Checkpoints::CSyncCheckpoint checkpoint;
+        CSyncCheckpoint checkpoint;
         vRecv >> checkpoint;
 
         if (checkpoint.ProcessSyncCheckpoint(pfrom))