Update CMakeLists.txt - play with openssl
[novacoin.git] / src / alert.h
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6 #ifndef _BITCOINALERT_H_
7 #define _BITCOINALERT_H_ 1
8
9 #include "serialize.h"
10 #include "uint256.h"
11 #include "util.h"
12
13 #include <set>
14 #include <string>
15
16 class CNode;
17
18 /** Alerts are for notifying old versions if they become too obsolete and
19  * need to upgrade.  The message is displayed in the status bar.
20  * Alert messages are broadcast as a vector of signed data.  Unserializing may
21  * not read the entire buffer if the alert is for a newer version, but older
22  * versions can still relay the original data.
23  */
24 class CUnsignedAlert
25 {
26 public:
27     int nVersion;
28     int64_t nRelayUntil;      // when newer nodes stop relaying to newer nodes
29     int64_t nExpiration;
30     int nID;
31     int nCancel;
32     std::set<int> setCancel;
33     int nMinVer;            // lowest version inclusive
34     int nMaxVer;            // highest version inclusive
35     std::set<std::string> setSubVer;  // empty matches all
36     int nPriority;
37
38     // Actions
39     std::string strComment;
40     std::string strStatusBar;
41     std::string strReserved;
42
43     IMPLEMENT_SERIALIZE
44     (
45         READWRITE(this->nVersion);
46         nVersion = this->nVersion;
47         READWRITE(nRelayUntil);
48         READWRITE(nExpiration);
49         READWRITE(nID);
50         READWRITE(nCancel);
51         READWRITE(setCancel);
52         READWRITE(nMinVer);
53         READWRITE(nMaxVer);
54         READWRITE(setSubVer);
55         READWRITE(nPriority);
56
57         READWRITE(strComment);
58         READWRITE(strStatusBar);
59         READWRITE(strReserved);
60     )
61
62     void SetNull();
63
64     std::string ToString() const;
65 };
66
67 /** An alert is a combination of a serialized CUnsignedAlert and a signature. */
68 class CAlert : public CUnsignedAlert
69 {
70 public:
71     std::vector<unsigned char> vchMsg;
72     std::vector<unsigned char> vchSig;
73
74     CAlert()
75     {
76         SetNull();
77     }
78
79     IMPLEMENT_SERIALIZE
80     (
81         READWRITE(vchMsg);
82         READWRITE(vchSig);
83     )
84
85     void SetNull();
86     bool IsNull() const;
87     uint256 GetHash() const;
88     bool IsInEffect() const;
89     bool Cancels(const CAlert& alert) const;
90     bool AppliesTo(int nVersion, const std::string& strSubVerIn) const;
91     bool AppliesToMe() const;
92     bool RelayTo(CNode* pnode) const;
93     bool CheckSignature() const;
94     bool ProcessAlert();
95
96     /*
97      * Get copy of (active) alert object by hash. Returns a null alert if it is not found.
98      */
99     static CAlert getAlertByHash(const uint256 &hash);
100 };
101
102 #endif