diff --git a/src/avalanche/proofbuilder.cpp b/src/avalanche/proofbuilder.cpp index f5d1d48bd..f848ffd70 100644 --- a/src/avalanche/proofbuilder.cpp +++ b/src/avalanche/proofbuilder.cpp @@ -1,73 +1,66 @@ // Copyright (c) 2020 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 namespace avalanche { SignedStake ProofBuilder::StakeSigner::sign(const ProofId &proofid) { const uint256 h = stake.getHash(proofid); SchnorrSig sig; if (!key.SignSchnorr(h, sig)) { sig.fill(0); } return SignedStake(std::move(stake), std::move(sig)); } bool ProofBuilder::addUTXO(COutPoint utxo, Amount amount, uint32_t height, bool is_coinbase, CKey key) { if (!key.IsValid()) { return false; } stakes.emplace_back( Stake(std::move(utxo), amount, height, is_coinbase, key.GetPubKey()), std::move(key)); return true; } Proof ProofBuilder::build() { const ProofId proofid = getProofId(); std::vector signedStakes; signedStakes.reserve(stakes.size()); for (auto &s : stakes) { signedStakes.push_back(s.sign(proofid)); } stakes.clear(); return Proof(sequence, expirationTime, std::move(master), std::move(signedStakes)); } ProofId ProofBuilder::getProofId() const { CHashWriter ss(SER_GETHASH, 0); ss << sequence; ss << expirationTime; WriteCompactSize(ss, stakes.size()); for (const auto &s : stakes) { ss << s.stake; } CHashWriter ss2(SER_GETHASH, 0); ss2 << ss.GetHash(); ss2 << master; return ProofId(ss2.GetHash()); } -Proof ProofBuilder::buildRandom(uint32_t score) { - ProofBuilder pb(0, std::numeric_limits::max(), CPubKey()); - pb.addUTXO(COutPoint(TxId(GetRandHash()), 0), (int64_t(score) * COIN) / 100, - 0, false, CKey::MakeCompressedKey()); - return pb.build(); -} - } // namespace avalanche diff --git a/src/avalanche/proofbuilder.h b/src/avalanche/proofbuilder.h index 655ea8f5e..fc500cc72 100644 --- a/src/avalanche/proofbuilder.h +++ b/src/avalanche/proofbuilder.h @@ -1,54 +1,48 @@ // Copyright (c) 2020 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_AVALANCHE_PROOFBUILDER_H #define BITCOIN_AVALANCHE_PROOFBUILDER_H #include #include #include namespace avalanche { class ProofBuilder { uint64_t sequence; int64_t expirationTime; CPubKey master; struct StakeSigner { Stake stake; CKey key; StakeSigner(Stake stake_, CKey key_) : stake(std::move(stake_)), key(std::move(key_)) {} SignedStake sign(const ProofId &proofid); }; std::vector stakes; public: ProofBuilder(uint64_t sequence_, int64_t expirationTime_, CPubKey master_) : sequence(sequence_), expirationTime(expirationTime_), master(std::move(master_)) {} bool addUTXO(COutPoint utxo, Amount amount, uint32_t height, bool is_coinbase, CKey key); Proof build(); - /** - * Builds a randomized (and therefore invalid) Proof. - * Useful for tests. - */ - static Proof buildRandom(uint32_t score); - private: ProofId getProofId() const; }; } // namespace avalanche #endif // BITCOIN_AVALANCHE_PROOFBUILDER_H