Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proof.h
Show All 29 Lines | |||||
public: | public: | ||||
explicit Stake() = default; | explicit Stake() = default; | ||||
Stake(COutPoint utxo_, Amount amount_, uint32_t height_, bool is_coinbase, | Stake(COutPoint utxo_, Amount amount_, uint32_t height_, bool is_coinbase, | ||||
CPubKey pubkey_) | CPubKey pubkey_) | ||||
: utxo(utxo_), amount(amount_), height(height_ << 1 | is_coinbase), | : utxo(utxo_), amount(amount_), height(height_ << 1 | is_coinbase), | ||||
pubkey(std::move(pubkey_)) {} | pubkey(std::move(pubkey_)) {} | ||||
ADD_SERIALIZE_METHODS; | SERIALIZE_METHODS(Stake, obj) { | ||||
READWRITE(obj.utxo, obj.amount, obj.height, obj.pubkey); | |||||
template <typename Stream, typename Operation> | |||||
inline void SerializationOp(Stream &s, Operation ser_action) { | |||||
READWRITE(utxo); | |||||
READWRITE(amount); | |||||
READWRITE(height); | |||||
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; | 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; | SERIALIZE_METHODS(SignedStake, obj) { READWRITE(obj.stake, obj.sig); } | ||||
template <typename Stream, typename Operation> | |||||
inline void SerializationOp(Stream &s, Operation ser_action) { | |||||
READWRITE(stake); | |||||
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; | 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_), | : sequence(sequence_), expirationTime(expirationTime_), | ||||
master(std::move(master_)), stakes(std::move(stakes_)), | master(std::move(master_)), stakes(std::move(stakes_)), | ||||
proofid(computeProofId()) {} | proofid(computeProofId()) {} | ||||
ADD_SERIALIZE_METHODS; | SERIALIZE_METHODS(Proof, obj) { | ||||
READWRITE(obj.sequence, obj.expirationTime, obj.master, obj.stakes); | |||||
template <typename Stream, typename Operation> | SER_READ(obj, obj.proofid = obj.computeProofId()); | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | |||||
READWRITE(sequence); | |||||
READWRITE(expirationTime); | |||||
READWRITE(master); | |||||
READWRITE(stakes); | |||||
if (ser_action.ForRead()) { | |||||
proofid = computeProofId(); | |||||
} | |||||
} | } | ||||
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 ProofId &getId() const { return proofid; } | const ProofId &getId() const { return proofid; } | ||||
Show All 9 Lines |