Bitcoin ABC  0.24.7
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
30  SERIALIZE_METHODS(Vote, obj) { READWRITE(obj.error, obj.hash); }
31 };
32 
33 class Response {
34  uint64_t round;
35  uint32_t cooldown;
36  std::vector<Vote> votes;
37 
38 public:
39  Response() : round(-1), cooldown(-1) {}
40  Response(uint64_t roundIn, uint32_t cooldownIn, std::vector<Vote> votesIn)
41  : round(roundIn), cooldown(cooldownIn), votes(votesIn) {}
42 
43  uint64_t getRound() const { return round; }
44  uint32_t getCooldown() const { return cooldown; }
45  const std::vector<Vote> &GetVotes() const { return votes; }
46 
47  // serialization support
49  READWRITE(obj.round, obj.cooldown, obj.votes);
50  }
51 };
52 
53 class Poll {
54  uint64_t round;
55  std::vector<CInv> invs;
56 
57 public:
58  Poll(uint64_t roundIn, std::vector<CInv> invsIn)
59  : round(roundIn), invs(invsIn) {}
60 
61  uint64_t GetRound() { return round; }
62  const std::vector<CInv> &GetInvs() const { return invs; }
63 
64  // serialization support
65  SERIALIZE_METHODS(Poll, obj) { READWRITE(obj.round, obj.invs); }
66 };
67 
68 class Hello {
71 
72 public:
73  Hello(Delegation delegationIn, SchnorrSig sigIn)
74  : delegation(std::move(delegationIn)), sig(sigIn) {}
75 
76  SchnorrSig GetSig() { return sig; }
77 
78  // serialization support
79  SERIALIZE_METHODS(Hello, obj) { READWRITE(obj.delegation, obj.sig); }
80 };
81 
82 } // namespace avalanche
83 
84 #endif // BITCOIN_AVALANCHE_PROTOCOL_H
avalanche::Hello::SERIALIZE_METHODS
SERIALIZE_METHODS(Hello, obj)
Definition: protocol.h:79
avalanche::Delegation
Definition: delegation.h:23
protocol.h
delegation.h
avalanche::Response::cooldown
uint32_t cooldown
Definition: protocol.h:35
avalanche::Hello::sig
SchnorrSig sig
Definition: protocol.h:70
avalanche
Definition: avalanche.h:11
uint256.h
avalanche::Response::votes
std::vector< Vote > votes
Definition: protocol.h:36
avalanche::Poll::Poll
Poll(uint64_t roundIn, std::vector< CInv > invsIn)
Definition: protocol.h:58
avalanche::Response::getRound
uint64_t getRound() const
Definition: protocol.h:43
avalanche::Vote::GetError
uint32_t GetError() const
Definition: protocol.h:27
avalanche::Poll
Definition: protocol.h:53
avalanche::Poll::round
uint64_t round
Definition: protocol.h:54
avalanche::Response
Definition: protocol.h:33
avalanche::Response::round
uint64_t round
Definition: protocol.h:34
avalanche::Vote::Vote
Vote(uint32_t errorIn, uint256 hashIn)
Definition: protocol.h:24
avalanche::Poll::GetInvs
const std::vector< CInv > & GetInvs() const
Definition: protocol.h:62
SchnorrSig
std::array< uint8_t, CPubKey::SCHNORR_SIZE > SchnorrSig
a Schnorr signature
Definition: key.h:25
avalanche::Response::Response
Response(uint64_t roundIn, uint32_t cooldownIn, std::vector< Vote > votesIn)
Definition: protocol.h:40
avalanche::Hello::delegation
Delegation delegation
Definition: protocol.h:69
avalanche::Vote::SERIALIZE_METHODS
SERIALIZE_METHODS(Vote, obj)
Definition: protocol.h:30
uint256
256-bit opaque blob.
Definition: uint256.h:127
READWRITE
#define READWRITE(...)
Definition: serialize.h:179
avalanche::Hello::Hello
Hello(Delegation delegationIn, SchnorrSig sigIn)
Definition: protocol.h:73
avalanche::Vote
Definition: protocol.h:18
avalanche::Poll::invs
std::vector< CInv > invs
Definition: protocol.h:55
avalanche::Response::getCooldown
uint32_t getCooldown() const
Definition: protocol.h:44
avalanche::Vote::Vote
Vote()
Definition: protocol.h:23
avalanche::Vote::hash
uint256 hash
Definition: protocol.h:20
avalanche::Vote::GetHash
const uint256 & GetHash() const
Definition: protocol.h:26
serialize.h
avalanche::Response::GetVotes
const std::vector< Vote > & GetVotes() const
Definition: protocol.h:45
avalanche::Response::Response
Response()
Definition: protocol.h:39
avalanche::Poll::GetRound
uint64_t GetRound()
Definition: protocol.h:61
avalanche::Vote::error
uint32_t error
Definition: protocol.h:19
avalanche::Response::SERIALIZE_METHODS
SERIALIZE_METHODS(Response, obj)
Definition: protocol.h:48
avalanche::Hello::GetSig
SchnorrSig GetSig()
Definition: protocol.h:76
avalanche::Hello
Definition: protocol.h:68
avalanche::Poll::SERIALIZE_METHODS
SERIALIZE_METHODS(Poll, obj)
Definition: protocol.h:65