diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -543,6 +543,7 @@ avalanche/peermanager.cpp avalanche/processor.cpp avalanche/proof.cpp + avalanche/proofid.cpp avalanche/proofbuilder.cpp banman.cpp blockencodings.cpp diff --git a/src/avalanche/proof.cpp b/src/avalanche/proof.cpp --- a/src/avalanche/proof.cpp +++ b/src/avalanche/proof.cpp @@ -58,12 +58,7 @@ } limitedProofId = LimitedProofId(ss.GetHash()); - - CHashWriter ss2(SER_GETHASH, 0); - ss2 << limitedProofId; - ss2 << master; - - proofid = ProofId(ss2.GetHash()); + proofid = ProofId::fromLimitedId(limitedProofId, master); } uint32_t Proof::getScore() const { diff --git a/src/avalanche/proofid.h b/src/avalanche/proofid.h --- a/src/avalanche/proofid.h +++ b/src/avalanche/proofid.h @@ -10,6 +10,8 @@ #include +class CPubKey; + namespace avalanche { struct LimitedProofId : public uint256 { @@ -27,6 +29,9 @@ explicit ProofId() : uint256() {} explicit ProofId(const uint256 &b) : uint256(b) {} + static ProofId fromLimitedId(const LimitedProofId &limitedId, + const CPubKey &proofMaster); + static ProofId fromHex(const std::string &str) { ProofId r; r.SetHex(str); diff --git a/src/avalanche/proofid.cpp b/src/avalanche/proofid.cpp new file mode 100644 --- /dev/null +++ b/src/avalanche/proofid.cpp @@ -0,0 +1,20 @@ +// Copyright (c) 2021 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include +#include + +namespace avalanche { + +ProofId ProofId::fromLimitedId(const LimitedProofId &limitedId, + const CPubKey &proofMaster) { + CHashWriter ss(SER_GETHASH, 0); + ss << limitedId; + ss << proofMaster; + return ProofId(ss.GetHash()); +} + +} // namespace avalanche \ No newline at end of file