1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2013 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or https://www.opensource.org/licenses/mit-license.php .
6 #ifndef BITCOIN_ALERT_H
7 #define BITCOIN_ALERT_H
21 extern std::map<uint256, CAlert> mapAlerts;
22 extern CCriticalSection cs_mapAlerts;
24 /** Alerts are for notifying old versions if they become too obsolete and
25 * need to upgrade. The message is displayed in the status bar.
26 * Alert messages are broadcast as a vector of signed data. Unserializing may
27 * not read the entire buffer if the alert is for a newer version, but older
28 * versions can still relay the original data.
34 int64_t nRelayUntil; // when newer nodes stop relaying to newer nodes
38 std::set<int> setCancel;
39 int nMinVer; // lowest version inclusive
40 int nMaxVer; // highest version inclusive
41 std::set<std::string> setSubVer; // empty matches all
45 std::string strComment;
46 std::string strStatusBar;
47 std::string strRPCError;
49 ADD_SERIALIZE_METHODS;
51 template <typename Stream, typename Operation>
52 inline void SerializationOp(Stream& s, Operation ser_action) {
53 READWRITE(this->nVersion);
54 READWRITE(nRelayUntil);
55 READWRITE(nExpiration);
64 READWRITE(LIMITED_STRING(strComment, 65536));
65 READWRITE(LIMITED_STRING(strStatusBar, 256));
66 READWRITE(LIMITED_STRING(strRPCError, 256));
71 std::string ToString() const;
74 /** An alert is a combination of a serialized CUnsignedAlert and a signature. */
75 class CAlert : public CUnsignedAlert
78 std::vector<unsigned char> vchMsg;
79 std::vector<unsigned char> vchSig;
86 ADD_SERIALIZE_METHODS;
88 template <typename Stream, typename Operation>
89 inline void SerializationOp(Stream& s, Operation ser_action) {
96 uint256 GetHash() const;
97 bool IsInEffect() const;
98 bool Cancels(const CAlert& alert) const;
99 bool AppliesTo(int nVersion, const std::string& strSubVerIn) const;
100 bool AppliesToMe() const;
101 bool RelayTo(CNode* pnode) const;
102 bool CheckSignature(const std::vector<unsigned char>& alertKey) const;
103 bool ProcessAlert(const std::vector<unsigned char>& alertKey, bool fThread = true); // fThread means run -alertnotify in a free-running thread
104 static void Notify(const std::string& strMessage, bool fThread);
107 * Get copy of (active) alert object by hash. Returns a null alert if it is not found.
109 static CAlert getAlertByHash(const uint256 &hash);
112 #endif // BITCOIN_ALERT_H