]> Git Repo - VerusCoin.git/commitdiff
Merge pull request #5969
authorWladimir J. van der Laan <[email protected]>
Wed, 8 Apr 2015 07:40:44 +0000 (09:40 +0200)
committerWladimir J. van der Laan <[email protected]>
Wed, 8 Apr 2015 07:41:14 +0000 (09:41 +0200)
f14e687 Chainparams: Decouple CAlert from CChainParams (Jorge Timón)

src/alert.cpp
src/alert.h
src/main.cpp
src/test/alert_tests.cpp

index 323939913b7389b1ec823ec14940c9c6f9d3a5a0..aa7ac748dad6ac124578d107feb960dda14f3b40 100644 (file)
@@ -5,7 +5,6 @@
 
 #include "alert.h"
 
-#include "chainparams.h"
 #include "clientversion.h"
 #include "net.h"
 #include "pubkey.h"
@@ -145,9 +144,9 @@ bool CAlert::RelayTo(CNode* pnode) const
     return false;
 }
 
-bool CAlert::CheckSignature() const
+bool CAlert::CheckSignature(const std::vector<unsigned char>& alertKey) const
 {
-    CPubKey key(Params().AlertKey());
+    CPubKey key(alertKey);
     if (!key.Verify(Hash(vchMsg.begin(), vchMsg.end()), vchSig))
         return error("CAlert::CheckSignature(): verify signature failed");
 
@@ -169,9 +168,9 @@ CAlert CAlert::getAlertByHash(const uint256 &hash)
     return retval;
 }
 
-bool CAlert::ProcessAlert(bool fThread)
+bool CAlert::ProcessAlert(const std::vector<unsigned char>& alertKey, bool fThread)
 {
-    if (!CheckSignature())
+    if (!CheckSignature(alertKey))
         return false;
     if (!IsInEffect())
         return false;
index af42171af5b3a416bf421b67e17ce15275510565..746967c4aff3699a5ddff1eda589e1ebdd58d0ac 100644 (file)
@@ -100,8 +100,8 @@ public:
     bool AppliesTo(int nVersion, std::string strSubVerIn) const;
     bool AppliesToMe() const;
     bool RelayTo(CNode* pnode) const;
-    bool CheckSignature() const;
-    bool ProcessAlert(bool fThread = true); // fThread means run -alertnotify in a free-running thread
+    bool CheckSignature(const std::vector<unsigned char>& alertKey) const;
+    bool ProcessAlert(const std::vector<unsigned char>& alertKey, bool fThread = true); // fThread means run -alertnotify in a free-running thread
     static void Notify(const std::string& strMessage, bool fThread);
 
     /*
index 7da190bdf03a2bc34e77f2519c25b7ccb985b820..8fb6766301e5384c0e8db60c4cad565ade99e8ab 100644 (file)
@@ -4270,7 +4270,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
         uint256 alertHash = alert.GetHash();
         if (pfrom->setKnown.count(alertHash) == 0)
         {
-            if (alert.ProcessAlert())
+            if (alert.ProcessAlert(Params().AlertKey()))
             {
                 // Relay
                 pfrom->setKnown.insert(alertHash);
index 5e1f5f0294e2feebd4f54c03d040ad5d32fe3806..6b6df5199a04bd07216111333c4d66904aada235 100644 (file)
@@ -10,6 +10,7 @@
 #include "clientversion.h"
 #include "data/alertTests.raw.h"
 
+#include "chainparams.h"
 #include "serialize.h"
 #include "streams.h"
 #include "util.h"
@@ -119,10 +120,11 @@ BOOST_FIXTURE_TEST_SUITE(Alert_tests, ReadAlerts)
 BOOST_AUTO_TEST_CASE(AlertApplies)
 {
     SetMockTime(11);
+    const std::vector<unsigned char>& alertKey = Params(CBaseChainParams::MAIN).AlertKey();
 
     BOOST_FOREACH(const CAlert& alert, alerts)
     {
-        BOOST_CHECK(alert.CheckSignature());
+        BOOST_CHECK(alert.CheckSignature(alertKey));
     }
 
     BOOST_CHECK(alerts.size() >= 3);
@@ -159,6 +161,7 @@ BOOST_AUTO_TEST_CASE(AlertApplies)
 BOOST_AUTO_TEST_CASE(AlertNotify)
 {
     SetMockTime(11);
+    const std::vector<unsigned char>& alertKey = Params(CBaseChainParams::MAIN).AlertKey();
 
     boost::filesystem::path temp = GetTempPath() / "alertnotify.txt";
     boost::filesystem::remove(temp);
@@ -166,7 +169,7 @@ BOOST_AUTO_TEST_CASE(AlertNotify)
     mapArgs["-alertnotify"] = std::string("echo %s >> ") + temp.string();
 
     BOOST_FOREACH(CAlert alert, alerts)
-        alert.ProcessAlert(false);
+        alert.ProcessAlert(alertKey, false);
 
     std::vector<std::string> r = read_lines(temp);
     BOOST_CHECK_EQUAL(r.size(), 4u);
This page took 0.034477 seconds and 4 git commands to generate.