Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proof.cpp
// 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. | ||||
#include <avalanche/proof.h> | #include <avalanche/proof.h> | ||||
#include <avalanche/validation.h> | #include <avalanche/validation.h> | ||||
#include <coins.h> | #include <coins.h> | ||||
#include <hash.h> | #include <hash.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <script/standard.h> | #include <script/standard.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/system.h> | |||||
#include <util/translation.h> | |||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <unordered_set> | #include <unordered_set> | ||||
namespace avalanche { | namespace avalanche { | ||||
void Stake::computeStakeId() { | void Stake::computeStakeId() { | ||||
CHashWriter ss(SER_GETHASH, 0); | CHashWriter ss(SER_GETHASH, 0); | ||||
ss << *this; | ss << *this; | ||||
stakeid = StakeId(ss.GetHash()); | stakeid = StakeId(ss.GetHash()); | ||||
} | } | ||||
uint256 Stake::getHash(const StakeCommitment &commitment) const { | uint256 Stake::getHash(const StakeCommitment &commitment) const { | ||||
CHashWriter ss(SER_GETHASH, 0); | CHashWriter ss(SER_GETHASH, 0); | ||||
ss << commitment; | ss << commitment; | ||||
ss << *this; | ss << *this; | ||||
return ss.GetHash(); | return ss.GetHash(); | ||||
} | } | ||||
bool SignedStake::verify(const StakeCommitment &commitment) const { | bool SignedStake::verify(const StakeCommitment &commitment) const { | ||||
return stake.getPubkey().VerifySchnorr(stake.getHash(commitment), sig); | return stake.getPubkey().VerifySchnorr(stake.getHash(commitment), sig); | ||||
} | } | ||||
bool Proof::useLegacy() { | |||||
return useLegacy(gArgs); | |||||
} | |||||
bool Proof::useLegacy(const ArgsManager &argsman) { | |||||
return argsman.GetBoolArg("-legacyavaproof", | |||||
AVALANCHE_DEFAULT_LEGACY_PROOF); | |||||
} | |||||
bool Proof::FromHex(Proof &proof, const std::string &hexProof, | bool Proof::FromHex(Proof &proof, const std::string &hexProof, | ||||
bilingual_str &errorOut) { | bilingual_str &errorOut) { | ||||
if (!IsHex(hexProof)) { | if (!IsHex(hexProof)) { | ||||
errorOut = _("Proof must be an hexadecimal string."); | errorOut = _("Proof must be an hexadecimal string."); | ||||
return false; | return false; | ||||
} | } | ||||
CDataStream ss(ParseHex(hexProof), SER_NETWORK, PROTOCOL_VERSION); | CDataStream ss(ParseHex(hexProof), SER_NETWORK, PROTOCOL_VERSION); | ||||
▲ Show 20 Lines • Show All 158 Lines • Show Last 20 Lines |