Bitcoin ABC 0.30.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
9#include <protocol.h> // for CInv
10#include <serialize.h>
11#include <uint256.h>
12
13#include <cstdint>
14#include <vector>
15
16namespace avalanche {
17
18class Vote {
19 uint32_t error;
21
22public:
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
33class Response {
34 uint64_t round;
35 uint32_t cooldown;
36 std::vector<Vote> votes;
37
38public:
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
53class Poll {
54 uint64_t round;
55 std::vector<CInv> invs;
56
57public:
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
68class Hello {
71
72public:
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
Delegation delegation
Definition: protocol.h:69
Hello(Delegation delegationIn, SchnorrSig sigIn)
Definition: protocol.h:73
SchnorrSig sig
Definition: protocol.h:70
SERIALIZE_METHODS(Hello, obj)
Definition: protocol.h:79
SchnorrSig GetSig()
Definition: protocol.h:76
std::vector< CInv > invs
Definition: protocol.h:55
uint64_t GetRound()
Definition: protocol.h:61
uint64_t round
Definition: protocol.h:54
const std::vector< CInv > & GetInvs() const
Definition: protocol.h:62
Poll(uint64_t roundIn, std::vector< CInv > invsIn)
Definition: protocol.h:58
SERIALIZE_METHODS(Poll, obj)
Definition: protocol.h:65
uint32_t getCooldown() const
Definition: protocol.h:44
const std::vector< Vote > & GetVotes() const
Definition: protocol.h:45
SERIALIZE_METHODS(Response, obj)
Definition: protocol.h:48
Response(uint64_t roundIn, uint32_t cooldownIn, std::vector< Vote > votesIn)
Definition: protocol.h:40
uint64_t getRound() const
Definition: protocol.h:43
uint64_t round
Definition: protocol.h:34
std::vector< Vote > votes
Definition: protocol.h:36
uint32_t cooldown
Definition: protocol.h:35
SERIALIZE_METHODS(Vote, obj)
Definition: protocol.h:30
uint256 hash
Definition: protocol.h:20
Vote(uint32_t errorIn, uint256 hashIn)
Definition: protocol.h:24
uint32_t GetError() const
Definition: protocol.h:27
const uint256 & GetHash() const
Definition: protocol.h:26
uint32_t error
Definition: protocol.h:19
256-bit opaque blob.
Definition: uint256.h:129
std::array< uint8_t, CPubKey::SCHNORR_SIZE > SchnorrSig
a Schnorr signature
Definition: key.h:25
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:259
#define READWRITE(...)
Definition: serialize.h:166