diff --git a/src/avalanche/proofbuilder.h b/src/avalanche/proofbuilder.h --- a/src/avalanche/proofbuilder.h +++ b/src/avalanche/proofbuilder.h @@ -50,8 +50,7 @@ Proof build(); private: - LimitedProofId getLimitedProofId() const; - ProofId getProofId() const; + Proof getProofTemplate() const; friend struct TestProofBuilder; }; diff --git a/src/avalanche/proofbuilder.cpp b/src/avalanche/proofbuilder.cpp --- a/src/avalanche/proofbuilder.cpp +++ b/src/avalanche/proofbuilder.cpp @@ -32,14 +32,27 @@ .second; } +Proof ProofBuilder::getProofTemplate() const { + std::vector signedStakes; + signedStakes.reserve(stakes.size()); + + for (auto &s : stakes) { + signedStakes.push_back({s.stake, SchnorrSig()}); + } + + return Proof(sequence, expirationTime, masterKey.GetPubKey(), + std::move(signedStakes), payoutScriptPubKey, SchnorrSig()); +} + Proof ProofBuilder::build() { + const Proof proofTemplate = getProofTemplate(); + SchnorrSig proofSignature; - const LimitedProofId limitedProofId = getLimitedProofId(); - if (!masterKey.SignSchnorr(limitedProofId, proofSignature)) { + if (!masterKey.SignSchnorr(proofTemplate.getLimitedId(), proofSignature)) { proofSignature.fill(0); } - const ProofId proofid = getProofId(); + const ProofId &proofid = proofTemplate.getId(); std::vector signedStakes; signedStakes.reserve(stakes.size()); @@ -54,29 +67,4 @@ std::move(proofSignature)); } -LimitedProofId ProofBuilder::getLimitedProofId() const { - CHashWriter ss(SER_GETHASH, 0); - ss << sequence; - ss << expirationTime; - - if (!Proof::useLegacy(gArgs)) { - ss << payoutScriptPubKey; - } - - WriteCompactSize(ss, stakes.size()); - for (const auto &s : stakes) { - ss << s.stake; - } - - return LimitedProofId(ss.GetHash()); -} - -ProofId ProofBuilder::getProofId() const { - CHashWriter ss(SER_GETHASH, 0); - ss << getLimitedProofId(); - ss << masterKey.GetPubKey(); - - return ProofId(ss.GetHash()); -} - } // namespace avalanche