Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
checkpointsync.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2013 PPCoin developers
2 // Copyright (c) 2013 Primecoin developers
3 // Distributed under conditional MIT/X11 open source software license
4 // see the accompanying file COPYING
5 #ifndef PRIMECOIN_CHECKPOINTSYNC_H
6 #define PRIMECOIN_CHECKPOINTSYNC_H
7 
8 #include "net.h"
9 #include "util.h"
10 
11 #define CHECKPOINT_MAX_SPAN (60 * 60 * 4) // max 4 hours before latest block
12 
13 class uint256;
14 class CBlock;
15 class CBlockIndex;
16 class CSyncCheckpoint;
17 
22 extern std::string strCheckpointWarning;
23 
29 bool CheckSyncCheckpoint(const uint256& hashBlock, const CBlockIndex* pindexPrev);
31 bool ResetSyncCheckpoint();
34 bool SetCheckpointPrivKey(std::string strPrivKey);
37 bool IsSyncCheckpointTooOld(unsigned int nSeconds);
38 uint256 WantedByOrphan(const CBlock* pblockOrphan);
39 
40 // Synchronized checkpoint (introduced first in ppcoin)
42 {
43 public:
44  int nVersion;
45  uint256 hashCheckpoint; // checkpoint block
46 
48  (
49  READWRITE(this->nVersion);
50  nVersion = this->nVersion;
51  READWRITE(hashCheckpoint);
52  )
53 
54  void SetNull()
55  {
56  nVersion = 1;
57  hashCheckpoint = 0;
58  }
59 
60  std::string ToString() const
61  {
62  return strprintf(
63  "CSyncCheckpoint(\n"
64  " nVersion = %d\n"
65  " hashCheckpoint = %s\n"
66  ")\n",
67  nVersion,
68  hashCheckpoint.ToString().c_str());
69  }
70 
71  void print() const
72  {
73  printf("%s", ToString().c_str());
74  }
75 };
76 
78 {
79 public:
80  static const std::string strMainPubKey;
81  static const std::string strTestPubKey;
82  static std::string strMasterPrivKey;
83 
84  std::vector<unsigned char> vchMsg;
85  std::vector<unsigned char> vchSig;
86 
88  {
89  SetNull();
90  }
91 
93  (
94  READWRITE(vchMsg);
95  READWRITE(vchSig);
96  )
97 
98  void SetNull()
99  {
100  CUnsignedSyncCheckpoint::SetNull();
101  vchMsg.clear();
102  vchSig.clear();
103  }
104 
105  bool IsNull() const
106  {
107  return (hashCheckpoint == 0);
108  }
109 
110  uint256 GetHash() const
111  {
112  return Hash(this->vchMsg.begin(), this->vchMsg.end());
113  }
114 
115  bool RelayTo(CNode* pnode) const
116  {
117  // returns true if wasn't already sent
118  if (pnode->hashCheckpointKnown != hashCheckpoint)
119  {
121  pnode->PushMessage("checkpoint", *this);
122  return true;
123  }
124  return false;
125  }
126 
127  bool CheckSignature();
128  bool ProcessSyncCheckpoint(CNode* pfrom);
129 };
130 
131 #endif
uint256 GetHash() const
void PushMessage(const char *pszCommand)
Definition: net.h:454
bool SetCheckpointPrivKey(std::string strPrivKey)
#define strprintf(format,...)
Definition: util.h:169
bool CheckCheckpointPubKey()
uint256 hashInvalidCheckpoint
std::vector< unsigned char > vchSig
bool IsMatureSyncCheckpoint()
#define READWRITE(obj)
Definition: serialize.h:93
bool SendSyncCheckpoint(uint256 hashCheckpoint)
bool IsSyncCheckpointTooOld(unsigned int nSeconds)
Definition: main.h:1334
IMPLEMENT_SERIALIZE(READWRITE(this->nVersion);nVersion=this->nVersion;READWRITE(hashCheckpoint);) void SetNull()
bool ResetSyncCheckpoint()
bool RelayTo(CNode *pnode) const
CCriticalSection cs_hashSyncCheckpoint
bool IsSyncCheckpointEnforced()
CBlockIndex * GetLastSyncCheckpoint()
bool ProcessSyncCheckpoint(CNode *pfrom)
static std::string strMasterPrivKey
std::vector< unsigned char > vchMsg
CSyncCheckpoint checkpointMessage
bool CheckSyncCheckpoint(const uint256 &hashBlock, const CBlockIndex *pindexPrev)
#define printf
Definition: rpcdump.cpp:12
bool WantedByPendingSyncCheckpoint(uint256 hashBlock)
static const std::string strTestPubKey
void AskForPendingSyncCheckpoint(CNode *pfrom)
uint256 WantedByOrphan(const CBlock *pblockOrphan)
std::string ToString() const
uint256 Hash(const T1 pbegin, const T1 pend)
Definition: hash.h:16
uint256 hashSyncCheckpoint
bool AcceptPendingSyncCheckpoint()
bool WriteSyncCheckpoint(const uint256 &hashCheckpoint)
256-bit unsigned integer
Definition: uint256.h:537
static const std::string strMainPubKey
std::string strCheckpointWarning
bool IsNull() const
uint256 AutoSelectSyncCheckpoint()
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: main.h:1626
std::string ToString() const
Definition: uint256.h:343
IMPLEMENT_SERIALIZE(READWRITE(vchMsg);READWRITE(vchSig);) void SetNull()
Information about a peer.
Definition: net.h:154
uint256 hashCheckpointKnown
Definition: net.h:222