Bitcoin ABC  0.22.15
P2P Digital Currency
delegation.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_DELEGATION_H
6 #define BITCOIN_AVALANCHE_DELEGATION_H
7 
9 #include <avalanche/proofid.h>
10 #include <key.h>
11 #include <pubkey.h>
12 #include <serialize.h>
13 
14 #include <vector>
15 
16 namespace avalanche {
17 
18 class DelegationState;
19 class Proof;
20 
21 class Delegation {
23 
26 
27  struct Level {
30 
31  SERIALIZE_METHODS(Level, obj) { READWRITE(obj.pubkey, obj.sig); }
32  };
33 
34  std::vector<Level> levels;
35 
36  friend class DelegationBuilder;
37  Delegation(const ProofId &proofid_, const DelegationId &dgid_,
38  std::vector<Level> levels_)
39  : proofid(proofid_), dgid(dgid_), levels(std::move(levels_)) {}
40 
41 public:
42  explicit Delegation() {}
43 
44  const DelegationId &getId() const { return dgid; }
45  const ProofId &getProofId() const { return proofid; }
46 
48  READWRITE(obj.proofid, obj.levels);
49  SER_READ(obj, obj.dgid = obj.computeDelegationId());
50  }
51 
52  bool verify(DelegationState &state, const Proof &proof,
53  CPubKey &auth) const;
54 };
55 
56 } // namespace avalanche
57 
58 #endif // BITCOIN_AVALANCHE_DELEGATION_H
std::vector< Level > levels
Definition: delegation.h:34
bool verify(DelegationState &state, const Proof &proof, CPubKey &auth) const
Definition: delegation.cpp:40
std::array< uint8_t, CPubKey::SCHNORR_SIZE > SchnorrSig
a Schnorr signature
Definition: key.h:25
SERIALIZE_METHODS(Delegation, obj)
Definition: delegation.h:47
DelegationId dgid
Definition: delegation.h:24
An encapsulated public key.
Definition: pubkey.h:31
DelegationId computeDelegationId() const
Definition: delegation.cpp:34
const ProofId & getProofId() const
Definition: delegation.h:45
const DelegationId & getId() const
Definition: delegation.h:44
Delegation(const ProofId &proofid_, const DelegationId &dgid_, std::vector< Level > levels_)
Definition: delegation.h:37
#define SER_READ(obj, code)
Definition: serialize.h:182
#define READWRITE(...)
Definition: serialize.h:179