Bitcoin ABC  0.25.8
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 struct bilingual_str;
17 
18 namespace avalanche {
19 
26 constexpr size_t MAX_DELEGATION_LEVELS{20};
27 
28 class DelegationState;
29 class Proof;
30 
31 class Delegation {
34 
37 
38  struct Level {
41 
42  SERIALIZE_METHODS(Level, obj) { READWRITE(obj.pubkey, obj.sig); }
43  };
44 
45  std::vector<Level> levels;
46 
47  friend class DelegationBuilder;
48  Delegation(const LimitedProofId &limitedProofid_,
49  const CPubKey &proofMaster_, const DelegationId &dgid_,
50  std::vector<Level> levels_)
51  : limitedProofid(limitedProofid_), proofMaster(proofMaster_),
52  dgid(dgid_), levels(std::move(levels_)) {}
53 
54 public:
55  explicit Delegation() {}
56 
57  static bool FromHex(Delegation &dg, const std::string &dgHex,
58  bilingual_str &errorOut);
59 
60  const DelegationId &getId() const { return dgid; }
61  const LimitedProofId &getLimitedProofId() const { return limitedProofid; }
62  const CPubKey &getProofMaster() const { return proofMaster; }
63  const CPubKey &getDelegatedPubkey() const;
64  const std::vector<Level> &getLevels() const { return levels; }
65 
66  ProofId getProofId() const;
67 
69  READWRITE(obj.limitedProofid, obj.proofMaster, obj.levels);
70  SER_READ(obj, obj.dgid = obj.computeDelegationId());
71  }
72 
73  bool verify(DelegationState &state, CPubKey &auth) const;
74 };
75 
76 } // namespace avalanche
77 
78 #endif // BITCOIN_AVALANCHE_DELEGATION_H
avalanche::Delegation::dgid
DelegationId dgid
Definition: delegation.h:35
avalanche::Delegation
Definition: delegation.h:31
avalanche::DelegationId
Definition: delegationid.h:14
proofid.h
avalanche::Delegation::computeDelegationId
DelegationId computeDelegationId() const
Definition: delegation.cpp:67
avalanche
Definition: avalanche.h:13
avalanche::Delegation::Level
Definition: delegation.h:38
avalanche::Delegation::limitedProofid
LimitedProofId limitedProofid
Definition: delegation.h:32
bilingual_str
Bilingual messages:
Definition: translation.h:17
avalanche::Delegation::Level::SERIALIZE_METHODS
SERIALIZE_METHODS(Level, obj)
Definition: delegation.h:42
avalanche::Delegation::getProofId
ProofId getProofId() const
Definition: delegation.cpp:56
avalanche::ProofId
Definition: proofid.h:17
pubkey.h
avalanche::Delegation::getLimitedProofId
const LimitedProofId & getLimitedProofId() const
Definition: delegation.h:61
avalanche::DelegationState
Definition: validation.h:42
avalanche::Delegation::getLevels
const std::vector< Level > & getLevels() const
Definition: delegation.h:64
avalanche::Delegation::FromHex
static bool FromHex(Delegation &dg, const std::string &dgHex, bilingual_str &errorOut)
Definition: delegation.cpp:16
avalanche::Delegation::proofMaster
CPubKey proofMaster
Definition: delegation.h:33
SchnorrSig
std::array< uint8_t, CPubKey::SCHNORR_SIZE > SchnorrSig
a Schnorr signature
Definition: key.h:25
avalanche::Delegation::Level::sig
SchnorrSig sig
Definition: delegation.h:40
avalanche::Delegation::verify
bool verify(DelegationState &state, CPubKey &auth) const
Definition: delegation.cpp:73
avalanche::DelegationBuilder
Definition: delegationbuilder.h:20
delegationid.h
avalanche::Delegation::getProofMaster
const CPubKey & getProofMaster() const
Definition: delegation.h:62
avalanche::Delegation::Level::pubkey
CPubKey pubkey
Definition: delegation.h:39
READWRITE
#define READWRITE(...)
Definition: serialize.h:180
avalanche::LimitedProofId
Definition: proofid.h:28
avalanche::Delegation::SERIALIZE_METHODS
SERIALIZE_METHODS(Delegation, obj)
Definition: delegation.h:68
avalanche::Delegation::Delegation
Delegation()
Definition: delegation.h:55
avalanche::Delegation::Delegation
Delegation(const LimitedProofId &limitedProofid_, const CPubKey &proofMaster_, const DelegationId &dgid_, std::vector< Level > levels_)
Definition: delegation.h:48
avalanche::Delegation::getDelegatedPubkey
const CPubKey & getDelegatedPubkey() const
Definition: delegation.cpp:60
key.h
CPubKey
An encapsulated public key.
Definition: pubkey.h:31
avalanche::Delegation::getId
const DelegationId & getId() const
Definition: delegation.h:60
serialize.h
avalanche::Delegation::levels
std::vector< Level > levels
Definition: delegation.h:45
SER_READ
#define SER_READ(obj, code)
Definition: serialize.h:183
avalanche::MAX_DELEGATION_LEVELS
constexpr size_t MAX_DELEGATION_LEVELS
The maximum number of delegation levels we are willing to verify.
Definition: delegation.h:26