Bitcoin ABC  0.22.13
P2P Digital Currency
protocol.h
Go to the documentation of this file.
1 // Copyright (c) 2020 The Bitcoin developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef BITCOIN_AVALANCHE_PROTOCOL_H
6 #define BITCOIN_AVALANCHE_PROTOCOL_H
7 
8 #include <avalanche/delegation.h>
9 #include <protocol.h> // for CInv
10 #include <serialize.h>
11 #include <uint256.h>
12 
13 #include <cstdint>
14 #include <vector>
15 
16 namespace avalanche {
17 
18 class Vote {
19  uint32_t error;
21 
22 public:
23  Vote() : error(-1), hash() {}
24  Vote(uint32_t errorIn, uint256 hashIn) : error(errorIn), hash(hashIn) {}
25 
26  const uint256 &GetHash() const { return hash; }
27  uint32_t GetError() const { return error; }
28 
29  // serialization support
31 
32  template <typename Stream, typename Operation>
33  inline void SerializationOp(Stream &s, Operation ser_action) {
34  READWRITE(error);
35  READWRITE(hash);
36  }
37 };
38 
39 class Response {
40  uint64_t round;
41  uint32_t cooldown;
42  std::vector<Vote> votes;
43 
44 public:
45  Response() : round(-1), cooldown(-1) {}
46  Response(uint64_t roundIn, uint32_t cooldownIn, std::vector<Vote> votesIn)
47  : round(roundIn), cooldown(cooldownIn), votes(votesIn) {}
48 
49  uint64_t getRound() const { return round; }
50  uint32_t getCooldown() const { return cooldown; }
51  const std::vector<Vote> &GetVotes() const { return votes; }
52 
53  // serialization support
55 
56  template <typename Stream, typename Operation>
57  inline void SerializationOp(Stream &s, Operation ser_action) {
58  READWRITE(round);
59  READWRITE(cooldown);
60  READWRITE(votes);
61  }
62 };
63 
64 class Poll {
65  uint64_t round;
66  std::vector<CInv> invs;
67 
68 public:
69  Poll(uint64_t roundIn, std::vector<CInv> invsIn)
70  : round(roundIn), invs(invsIn) {}
71 
72  const std::vector<CInv> &GetInvs() const { return invs; }
73 
74  // serialization support
76 
77  template <typename Stream, typename Operation>
78  inline void SerializationOp(Stream &s, Operation ser_action) {
79  READWRITE(round);
80  READWRITE(invs);
81  }
82 };
83 
84 class Hello {
86  std::array<uint8_t, 64> sig;
87 
88 public:
89  Hello(Delegation delegationIn, std::array<uint8_t, 64> sigIn)
90  : delegation(std::move(delegationIn)), sig(sigIn) {}
91 
92  // serialization support
94 
95  template <typename Stream, typename Operation>
96  inline void SerializationOp(Stream &s, Operation ser_action) {
97  READWRITE(delegation);
98  READWRITE(sig);
99  }
100 };
101 
102 } // namespace avalanche
103 
104 #endif // BITCOIN_AVALANCHE_PROTOCOL_H
uint32_t getCooldown() const
Definition: protocol.h:50
void SerializationOp(Stream &s, Operation ser_action)
Definition: protocol.h:33
Response(uint64_t roundIn, uint32_t cooldownIn, std::vector< Vote > votesIn)
Definition: protocol.h:46
std::vector< CInv > invs
Definition: protocol.h:66
Poll(uint64_t roundIn, std::vector< CInv > invsIn)
Definition: protocol.h:69
const std::vector< Vote > & GetVotes() const
Definition: protocol.h:51
Vote(uint32_t errorIn, uint256 hashIn)
Definition: protocol.h:24
Hello(Delegation delegationIn, std::array< uint8_t, 64 > sigIn)
Definition: protocol.h:89
const std::vector< CInv > & GetInvs() const
Definition: protocol.h:72
void SerializationOp(Stream &s, Operation ser_action)
Definition: protocol.h:57
Delegation delegation
Definition: protocol.h:85
uint256 hash
Definition: protocol.h:20
uint64_t round
Definition: protocol.h:65
void SerializationOp(Stream &s, Operation ser_action)
Definition: protocol.h:96
const uint256 & GetHash() const
Definition: protocol.h:26
uint32_t GetError() const
Definition: protocol.h:27
uint32_t cooldown
Definition: protocol.h:41
256-bit opaque blob.
Definition: uint256.h:120
std::array< uint8_t, 64 > sig
Definition: protocol.h:86
uint64_t getRound() const
Definition: protocol.h:49
void SerializationOp(Stream &s, Operation ser_action)
Definition: protocol.h:78
#define READWRITE(...)
Definition: serialize.h:191
uint64_t round
Definition: protocol.h:40
std::vector< Vote > votes
Definition: protocol.h:42
uint32_t error
Definition: protocol.h:19