Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proof.h
// Copyright (c) 2020 The Bitcoin developers | // Copyright (c) 2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_AVALANCHE_PROOF_H | #ifndef BITCOIN_AVALANCHE_PROOF_H | ||||
#define BITCOIN_AVALANCHE_PROOF_H | #define BITCOIN_AVALANCHE_PROOF_H | ||||
#include <amount.h> | #include <amount.h> | ||||
#include <avalanche/proofid.h> | #include <avalanche/proofid.h> | ||||
#include <key.h> | #include <key.h> | ||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <pubkey.h> | #include <pubkey.h> | ||||
#include <rcu.h> | |||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <array> | #include <array> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <optional> | #include <optional> | ||||
#include <vector> | #include <vector> | ||||
class ArgsManager; | class ArgsManager; | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | class Proof { | ||||
LimitedProofId limitedProofId; | LimitedProofId limitedProofId; | ||||
ProofId proofid; | ProofId proofid; | ||||
void computeProofId(); | void computeProofId(); | ||||
uint32_t score; | uint32_t score; | ||||
void computeScore(); | void computeScore(); | ||||
IMPLEMENT_RCU_REFCOUNT(uint64_t); | |||||
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(); | computeScore(); | ||||
} | } | ||||
Proof(Proof &&other) | |||||
: sequence(other.sequence), expirationTime(other.expirationTime), | |||||
master(std::move(other.master)), stakes(std::move(other.stakes)), | |||||
payoutScriptPubKey(std::move(other.payoutScriptPubKey)), | |||||
signature(std::move(other.signature)), | |||||
limitedProofId(std::move(other.limitedProofId)), | |||||
proofid(std::move(other.proofid)), score(other.score) {} | |||||
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()); | SER_READ(obj, obj.computeScore()); | ||||
Show All 24 Lines | public: | ||||
}; | }; | ||||
uint32_t getScore() const { return score; } | uint32_t getScore() const { return score; } | ||||
Amount getStakedAmount() const; | Amount getStakedAmount() const; | ||||
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 = RCUPtr<const Proof>; | ||||
} // namespace avalanche | } // namespace avalanche | ||||
#endif // BITCOIN_AVALANCHE_PROOF_H | #endif // BITCOIN_AVALANCHE_PROOF_H |