Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proof.h
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | class Proof { | ||||
std::vector<SignedStake> stakes; | std::vector<SignedStake> stakes; | ||||
CScript payoutScriptPubKey; | CScript payoutScriptPubKey; | ||||
SchnorrSig signature; | SchnorrSig signature; | ||||
LimitedProofId limitedProofId; | LimitedProofId limitedProofId; | ||||
ProofId proofid; | ProofId proofid; | ||||
void computeProofId(); | void computeProofId(); | ||||
uint32_t score; | |||||
void computeScore(); | |||||
public: | public: | ||||
Proof() | Proof() | ||||
: sequence(0), expirationTime(0), master(), stakes(), | : sequence(0), expirationTime(0), master(), stakes(), | ||||
payoutScriptPubKey(CScript()), limitedProofId(), proofid() {} | payoutScriptPubKey(CScript()), limitedProofId(), proofid() {} | ||||
Proof(uint64_t sequence_, int64_t expirationTime_, CPubKey master_, | Proof(uint64_t sequence_, int64_t expirationTime_, CPubKey master_, | ||||
std::vector<SignedStake> stakes_, const CScript &payoutScriptPubKey_, | std::vector<SignedStake> stakes_, const CScript &payoutScriptPubKey_, | ||||
SchnorrSig signature_) | SchnorrSig signature_) | ||||
: sequence(sequence_), expirationTime(expirationTime_), | : sequence(sequence_), expirationTime(expirationTime_), | ||||
master(std::move(master_)), stakes(std::move(stakes_)), | master(std::move(master_)), stakes(std::move(stakes_)), | ||||
payoutScriptPubKey(payoutScriptPubKey_), | payoutScriptPubKey(payoutScriptPubKey_), | ||||
signature(std::move(signature_)) { | signature(std::move(signature_)) { | ||||
computeProofId(); | computeProofId(); | ||||
computeScore(); | |||||
} | } | ||||
SERIALIZE_METHODS(Proof, obj) { | SERIALIZE_METHODS(Proof, obj) { | ||||
READWRITE(obj.sequence, obj.expirationTime, obj.master, obj.stakes); | READWRITE(obj.sequence, obj.expirationTime, obj.master, obj.stakes); | ||||
if (!useLegacy()) { | if (!useLegacy()) { | ||||
READWRITE(obj.payoutScriptPubKey, obj.signature); | READWRITE(obj.payoutScriptPubKey, obj.signature); | ||||
} | } | ||||
SER_READ(obj, obj.computeProofId()); | SER_READ(obj, obj.computeProofId()); | ||||
SER_READ(obj, obj.computeScore()); | |||||
} | } | ||||
static bool useLegacy(); | static bool useLegacy(); | ||||
static bool useLegacy(const ArgsManager &argsman); | static bool useLegacy(const ArgsManager &argsman); | ||||
static bool FromHex(Proof &proof, const std::string &hexProof, | static bool FromHex(Proof &proof, const std::string &hexProof, | ||||
bilingual_str &errorOut); | bilingual_str &errorOut); | ||||
uint64_t getSequence() const { return sequence; } | uint64_t getSequence() const { return sequence; } | ||||
int64_t getExpirationTime() const { return expirationTime; } | int64_t getExpirationTime() const { return expirationTime; } | ||||
const CPubKey &getMaster() const { return master; } | const CPubKey &getMaster() const { return master; } | ||||
const std::vector<SignedStake> &getStakes() const { return stakes; } | const std::vector<SignedStake> &getStakes() const { return stakes; } | ||||
const CScript &getPayoutScript() const { return payoutScriptPubKey; } | const CScript &getPayoutScript() const { return payoutScriptPubKey; } | ||||
std::optional<const SchnorrSig> getSignature() const { | std::optional<const SchnorrSig> getSignature() const { | ||||
return useLegacy() ? std::nullopt : std::make_optional(signature); | return useLegacy() ? std::nullopt : std::make_optional(signature); | ||||
} | } | ||||
const ProofId &getId() const { return proofid; } | const ProofId &getId() const { return proofid; } | ||||
const LimitedProofId &getLimitedId() const { return limitedProofId; } | const LimitedProofId &getLimitedId() const { return limitedProofId; } | ||||
const StakeCommitment getStakeCommitment() const { | const StakeCommitment getStakeCommitment() const { | ||||
return StakeCommitment(proofid, expirationTime, master); | return StakeCommitment(proofid, expirationTime, master); | ||||
}; | }; | ||||
uint32_t getScore() const; | uint32_t getScore() const { return score; } | ||||
bool verify(ProofValidationState &state) const; | bool verify(ProofValidationState &state) const; | ||||
bool verify(ProofValidationState &state, const CCoinsView &view) const; | bool verify(ProofValidationState &state, const CCoinsView &view) const; | ||||
}; | }; | ||||
using ProofRef = std::shared_ptr<const Proof>; | using ProofRef = std::shared_ptr<const Proof>; | ||||
} // namespace avalanche | } // namespace avalanche | ||||
#endif // BITCOIN_AVALANCHE_PROOF_H | #endif // BITCOIN_AVALANCHE_PROOF_H |