Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proof.h
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(pubkey); | READWRITE(pubkey); | ||||
} | } | ||||
const COutPoint &getUTXO() const { return utxo; } | const COutPoint &getUTXO() const { return utxo; } | ||||
Amount getAmount() const { return amount; } | Amount getAmount() const { return amount; } | ||||
uint32_t getHeight() const { return height >> 1; } | uint32_t getHeight() const { return height >> 1; } | ||||
bool isCoinbase() const { return height & 1; } | bool isCoinbase() const { return height & 1; } | ||||
const CPubKey &getPubkey() const { return pubkey; } | const CPubKey &getPubkey() const { return pubkey; } | ||||
uint256 getHash(const ProofId &proofid) const; | |||||
}; | }; | ||||
class SignedStake { | class SignedStake { | ||||
Stake stake; | Stake stake; | ||||
std::array<uint8_t, 64> sig; | std::array<uint8_t, 64> sig; | ||||
public: | public: | ||||
explicit SignedStake() = default; | explicit SignedStake() = default; | ||||
SignedStake(Stake stake_, std::array<uint8_t, 64> sig_) | SignedStake(Stake stake_, std::array<uint8_t, 64> sig_) | ||||
: stake(std::move(stake_)), sig(std::move(sig_)) {} | : stake(std::move(stake_)), sig(std::move(sig_)) {} | ||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(stake); | READWRITE(stake); | ||||
READWRITE(sig); | READWRITE(sig); | ||||
} | } | ||||
const Stake &getStake() const { return stake; } | const Stake &getStake() const { return stake; } | ||||
const std::array<uint8_t, 64> &getSignature() const { return sig; } | const std::array<uint8_t, 64> &getSignature() const { return sig; } | ||||
bool verify(const ProofId &proofid) const; | |||||
}; | }; | ||||
class Proof { | class Proof { | ||||
uint64_t sequence; | uint64_t sequence; | ||||
int64_t expirationTime; | int64_t expirationTime; | ||||
CPubKey master; | CPubKey master; | ||||
std::vector<SignedStake> stakes; | std::vector<SignedStake> stakes; | ||||
ProofId proofid; | ProofId proofid; | ||||
ProofId computeProofId() const; | ProofId computeProofId() const; | ||||
public: | public: | ||||
Proof() : sequence(0), expirationTime(0), master(), stakes(), proofid() {} | Proof() : sequence(0), expirationTime(0), master(), stakes(), proofid() {} | ||||
Proof(uint64_t sequence_, int64_t expirationTime_, CPubKey master_, | Proof(uint64_t sequence_, int64_t expirationTime_, CPubKey master_, | ||||
std::vector<SignedStake> stakes_); | std::vector<SignedStake> stakes_) | ||||
: sequence(sequence_), expirationTime(expirationTime_), | |||||
master(std::move(master_)), stakes(std::move(stakes_)), | |||||
proofid(computeProofId()) {} | |||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
READWRITE(sequence); | READWRITE(sequence); | ||||
READWRITE(expirationTime); | READWRITE(expirationTime); | ||||
READWRITE(master); | READWRITE(master); | ||||
READWRITE(stakes); | READWRITE(stakes); | ||||
if (ser_action.ForRead()) { | if (ser_action.ForRead()) { | ||||
proofid = computeProofId(); | proofid = computeProofId(); | ||||
} | } | ||||
} | } | ||||
uint64_t getSequence() const { return sequence; } | |||||
int64_t getExpirationTime() const { return expirationTime; } | |||||
const CPubKey &getMaster() const { return master; } | |||||
const ProofId &getId() const { return proofid; } | const ProofId &getId() const { return proofid; } | ||||
uint32_t getScore() const; | uint32_t getScore() const; | ||||
bool verify() const; | |||||
/** | /** | ||||
* Builds a randomized (and therefore invalid) Proof. | * Builds a randomized (and therefore invalid) Proof. | ||||
* Useful for tests. | * Useful for tests. | ||||
*/ | */ | ||||
static Proof makeRandom(uint32_t score); | static Proof makeRandom(uint32_t score); | ||||
}; | }; | ||||
} // namespace avalanche | } // namespace avalanche | ||||
#endif // BITCOIN_AVALANCHE_PROOF_H | #endif // BITCOIN_AVALANCHE_PROOF_H |