Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/delegation.h
Show All 21 Lines | class Delegation { | ||||
DelegationId dgid; | DelegationId dgid; | ||||
DelegationId computeDelegationId() const; | DelegationId computeDelegationId() const; | ||||
struct Level { | struct Level { | ||||
CPubKey pubkey; | CPubKey pubkey; | ||||
std::array<uint8_t, 64> sig; | std::array<uint8_t, 64> sig; | ||||
ADD_SERIALIZE_METHODS; | SERIALIZE_METHODS(Level, obj) { READWRITE(obj.pubkey, obj.sig); } | ||||
template <typename Stream, typename Operation> | |||||
inline void SerializationOp(Stream &s, Operation ser_action) { | |||||
READWRITE(pubkey); | |||||
READWRITE(sig); | |||||
} | |||||
}; | }; | ||||
std::vector<Level> levels; | std::vector<Level> levels; | ||||
friend class DelegationBuilder; | friend class DelegationBuilder; | ||||
Delegation(const ProofId &proofid_, const DelegationId &dgid_, | Delegation(const ProofId &proofid_, const DelegationId &dgid_, | ||||
std::vector<Level> levels_) | std::vector<Level> levels_) | ||||
: proofid(proofid_), dgid(dgid_), levels(std::move(levels_)) {} | : proofid(proofid_), dgid(dgid_), levels(std::move(levels_)) {} | ||||
public: | public: | ||||
explicit Delegation() {} | explicit Delegation() {} | ||||
const DelegationId &getId() const { return dgid; } | const DelegationId &getId() const { return dgid; } | ||||
const ProofId &getProofId() const { return proofid; } | const ProofId &getProofId() const { return proofid; } | ||||
ADD_SERIALIZE_METHODS; | SERIALIZE_METHODS(Delegation, obj) { | ||||
READWRITE(obj.proofid, obj.levels); | |||||
template <typename Stream, typename Operation> | SER_READ(obj, obj.dgid = obj.computeDelegationId()); | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | |||||
READWRITE(proofid); | |||||
READWRITE(levels); | |||||
if (ser_action.ForRead()) { | |||||
dgid = computeDelegationId(); | |||||
} | |||||
} | } | ||||
bool verify(DelegationState &state, const Proof &proof, | bool verify(DelegationState &state, const Proof &proof, | ||||
CPubKey &auth) const; | CPubKey &auth) const; | ||||
}; | }; | ||||
} // namespace avalanche | } // namespace avalanche | ||||
#endif // BITCOIN_AVALANCHE_DELEGATION_H | #endif // BITCOIN_AVALANCHE_DELEGATION_H |