]> Git Repo - VerusCoin.git/blame - src/alert.h
PBaaS refund fix to fund refund transactions with gateway deposits
[VerusCoin.git] / src / alert.h
CommitLineData
f35c6c4f 1// Copyright (c) 2010 Satoshi Nakamoto
f914f1a7 2// Copyright (c) 2009-2013 The Bitcoin Core developers
78253fcb 3// Distributed under the MIT software license, see the accompanying
bc909a7a 4// file COPYING or https://www.opensource.org/licenses/mit-license.php .
f35c6c4f 5
84738627
PJ
6#ifndef BITCOIN_ALERT_H
7#define BITCOIN_ALERT_H
f35c6c4f 8
51ed9ec9
BD
9#include "serialize.h"
10#include "sync.h"
11
12#include <map>
f35c6c4f 13#include <set>
51ed9ec9 14#include <stdint.h>
f35c6c4f
GA
15#include <string>
16
51ed9ec9 17class CAlert;
f35c6c4f 18class CNode;
51ed9ec9
BD
19class uint256;
20
21extern std::map<uint256, CAlert> mapAlerts;
22extern CCriticalSection cs_mapAlerts;
f35c6c4f
GA
23
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.
29 */
30class CUnsignedAlert
31{
32public:
33 int nVersion;
51ed9ec9
BD
34 int64_t nRelayUntil; // when newer nodes stop relaying to newer nodes
35 int64_t nExpiration;
f35c6c4f
GA
36 int nID;
37 int nCancel;
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
42 int nPriority;
43
44 // Actions
45 std::string strComment;
46 std::string strStatusBar;
a40034f7 47 std::string strRPCError;
f35c6c4f 48
3f6540ad 49 ADD_SERIALIZE_METHODS;
3d796f89 50
84881f8c 51 template <typename Stream, typename Operation>
68a1a592 52 inline void SerializationOp(Stream& s, Operation ser_action) {
f35c6c4f 53 READWRITE(this->nVersion);
f35c6c4f
GA
54 READWRITE(nRelayUntil);
55 READWRITE(nExpiration);
56 READWRITE(nID);
57 READWRITE(nCancel);
58 READWRITE(setCancel);
59 READWRITE(nMinVer);
60 READWRITE(nMaxVer);
61 READWRITE(setSubVer);
62 READWRITE(nPriority);
63
216e9a44
PW
64 READWRITE(LIMITED_STRING(strComment, 65536));
65 READWRITE(LIMITED_STRING(strStatusBar, 256));
a40034f7 66 READWRITE(LIMITED_STRING(strRPCError, 256));
3d796f89 67 }
f35c6c4f
GA
68
69 void SetNull();
70
71 std::string ToString() const;
f35c6c4f
GA
72};
73
74/** An alert is a combination of a serialized CUnsignedAlert and a signature. */
75class CAlert : public CUnsignedAlert
76{
77public:
78 std::vector<unsigned char> vchMsg;
79 std::vector<unsigned char> vchSig;
80
81 CAlert()
82 {
83 SetNull();
84 }
85
3f6540ad 86 ADD_SERIALIZE_METHODS;
3d796f89 87
84881f8c 88 template <typename Stream, typename Operation>
68a1a592 89 inline void SerializationOp(Stream& s, Operation ser_action) {
f35c6c4f
GA
90 READWRITE(vchMsg);
91 READWRITE(vchSig);
3d796f89 92 }
f35c6c4f
GA
93
94 void SetNull();
95 bool IsNull() const;
96 uint256 GetHash() const;
97 bool IsInEffect() const;
98 bool Cancels(const CAlert& alert) const;
db954a65 99 bool AppliesTo(int nVersion, const std::string& strSubVerIn) const;
f35c6c4f
GA
100 bool AppliesToMe() const;
101 bool RelayTo(CNode* pnode) const;
f14e687f
JT
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
e01a7939 104 static void Notify(const std::string& strMessage, bool fThread);
f35c6c4f
GA
105
106 /*
107 * Get copy of (active) alert object by hash. Returns a null alert if it is not found.
108 */
109 static CAlert getAlertByHash(const uint256 &hash);
110};
111
84738627 112#endif // BITCOIN_ALERT_H
This page took 0.169477 seconds and 4 git commands to generate.