Bitcoin ABC 0.30.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
16struct bilingual_str;
17
18namespace avalanche {
19
26constexpr size_t MAX_DELEGATION_LEVELS{20};
27
28class DelegationState;
29class Proof;
30
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
54public:
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; }
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
An encapsulated public key.
Definition: pubkey.h:31
ProofId getProofId() const
Definition: delegation.cpp:56
DelegationId dgid
Definition: delegation.h:35
const std::vector< Level > & getLevels() const
Definition: delegation.h:64
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:62
std::vector< Level > levels
Definition: delegation.h:45
LimitedProofId limitedProofid
Definition: delegation.h:32
Delegation(const LimitedProofId &limitedProofid_, const CPubKey &proofMaster_, const DelegationId &dgid_, std::vector< Level > levels_)
Definition: delegation.h:48
const DelegationId & getId() const
Definition: delegation.h:60
const CPubKey & getDelegatedPubkey() const
Definition: delegation.cpp:60
SERIALIZE_METHODS(Delegation, obj)
Definition: delegation.h:68
const LimitedProofId & getLimitedProofId() const
Definition: delegation.h:61
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:169
#define READWRITE(...)
Definition: serialize.h:166
Bilingual messages:
Definition: translation.h:17