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