Bitcoin ABC  0.24.7
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 
20 class DelegationState;
21 class Proof;
22 
23 class Delegation {
26 
29 
30  struct Level {
33 
34  SERIALIZE_METHODS(Level, obj) { READWRITE(obj.pubkey, obj.sig); }
35  };
36 
37  std::vector<Level> levels;
38 
39  friend class DelegationBuilder;
40  Delegation(const LimitedProofId &limitedProofid_,
41  const CPubKey &proofMaster_, const DelegationId &dgid_,
42  std::vector<Level> levels_)
43  : limitedProofid(limitedProofid_), proofMaster(proofMaster_),
44  dgid(dgid_), levels(std::move(levels_)) {}
45 
46 public:
47  explicit Delegation() {}
48 
49  static bool FromHex(Delegation &dg, const std::string &dgHex,
50  bilingual_str &errorOut);
51 
52  const DelegationId &getId() const { return dgid; }
53  const LimitedProofId &getLimitedProofId() const { return limitedProofid; }
54  const CPubKey &getProofMaster() const { return proofMaster; }
55  const CPubKey &getDelegatedPubkey() const;
56 
57  ProofId getProofId() const;
58 
60  READWRITE(obj.limitedProofid, obj.proofMaster, obj.levels);
61  SER_READ(obj, obj.dgid = obj.computeDelegationId());
62  }
63 
64  bool verify(DelegationState &state, CPubKey &auth) const;
65 };
66 
67 } // namespace avalanche
68 
69 #endif // BITCOIN_AVALANCHE_DELEGATION_H
avalanche::Delegation::dgid
DelegationId dgid
Definition: delegation.h:27
avalanche::Delegation
Definition: delegation.h:23
avalanche::DelegationId
Definition: delegationid.h:14
proofid.h
avalanche::Delegation::computeDelegationId
DelegationId computeDelegationId() const
Definition: delegation.cpp:67
avalanche
Definition: avalanche.h:11
avalanche::Delegation::Level
Definition: delegation.h:30
avalanche::Delegation::limitedProofid
LimitedProofId limitedProofid
Definition: delegation.h:24
bilingual_str
Bilingual messages:
Definition: translation.h:17
avalanche::Delegation::Level::SERIALIZE_METHODS
SERIALIZE_METHODS(Level, obj)
Definition: delegation.h:34
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:53
avalanche::DelegationState
Definition: validation.h:40
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:25
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:32
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:54
avalanche::Delegation::Level::pubkey
CPubKey pubkey
Definition: delegation.h:31
READWRITE
#define READWRITE(...)
Definition: serialize.h:179
avalanche::LimitedProofId
Definition: proofid.h:28
avalanche::Delegation::SERIALIZE_METHODS
SERIALIZE_METHODS(Delegation, obj)
Definition: delegation.h:59
avalanche::Delegation::Delegation
Delegation()
Definition: delegation.h:47
avalanche::Delegation::Delegation
Delegation(const LimitedProofId &limitedProofid_, const CPubKey &proofMaster_, const DelegationId &dgid_, std::vector< Level > levels_)
Definition: delegation.h:40
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:52
serialize.h
avalanche::Delegation::levels
std::vector< Level > levels
Definition: delegation.h:37
SER_READ
#define SER_READ(obj, code)
Definition: serialize.h:182