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 <serialize.h> | #include <serialize.h> | ||||
#include <util/system.h> | |||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <array> | #include <array> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <vector> | #include <vector> | ||||
class CCoinsView; | class CCoinsView; | ||||
/** | /** | ||||
* How many UTXOs can be used for a single proof. | * How many UTXOs can be used for a single proof. | ||||
*/ | */ | ||||
static constexpr int AVALANCHE_MAX_PROOF_STAKES = 1000; | static constexpr int AVALANCHE_MAX_PROOF_STAKES = 1000; | ||||
/** | |||||
* Whether the legacy proof format should be used by default. | |||||
*/ | |||||
static constexpr bool AVALANCHE_DEFAULT_LEGACY_PROOF = true; | |||||
namespace avalanche { | namespace avalanche { | ||||
/** Minimum amount per utxo */ | /** Minimum amount per utxo */ | ||||
static constexpr Amount PROOF_DUST_THRESHOLD = 1 * COIN; | static constexpr Amount PROOF_DUST_THRESHOLD = 1 * COIN; | ||||
class ProofValidationState; | class ProofValidationState; | ||||
using StakeId = uint256; | using StakeId = uint256; | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | public: | ||||
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; | ||||
CScript payoutScriptPubKey; | |||||
LimitedProofId limitedProofId; | LimitedProofId limitedProofId; | ||||
ProofId proofid; | ProofId proofid; | ||||
void computeProofId(); | void computeProofId(); | ||||
public: | public: | ||||
Proof() : sequence(0), expirationTime(0), master(), stakes(), proofid() {} | Proof() | ||||
: sequence(0), expirationTime(0), master(), stakes(), | |||||
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_) | std::vector<SignedStake> stakes_, const CScript &payoutScriptPubKey_) | ||||
: 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_) { | |||||
computeProofId(); | computeProofId(); | ||||
} | } | ||||
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(gArgs)) { | |||||
READWRITE(obj.payoutScriptPubKey); | |||||
} | |||||
SER_READ(obj, obj.computeProofId()); | SER_READ(obj, obj.computeProofId()); | ||||
} | } | ||||
static bool useLegacy(const ArgsManager &argsman) { | |||||
return argsman.GetBoolArg("-legacyavaproof", | |||||
AVALANCHE_DEFAULT_LEGACY_PROOF); | |||||
} | |||||
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; } | ||||
Show All 11 Lines |