Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proofbuilder.cpp
Show All 40 Lines | for (auto &s : stakes) { | ||||
signedStakes.push_back(s.sign(proofid)); | signedStakes.push_back(s.sign(proofid)); | ||||
} | } | ||||
stakes.clear(); | stakes.clear(); | ||||
return Proof(sequence, expirationTime, std::move(master), | return Proof(sequence, expirationTime, std::move(master), | ||||
std::move(signedStakes)); | std::move(signedStakes)); | ||||
} | } | ||||
ProofId ProofBuilder::getProofId() const { | ProofId ProofBuilder::getProofId() { | ||||
CHashWriter ss(SER_GETHASH, 0); | CHashWriter ss(SER_GETHASH, 0); | ||||
ss << sequence; | ss << sequence; | ||||
ss << expirationTime; | ss << expirationTime; | ||||
// TODO This can be avoided by using a sorted container instead of a vector | |||||
// for the stakes. | |||||
std::sort(stakes.begin(), stakes.end(), | |||||
[](const StakeSigner &lhs, const StakeSigner &rhs) { | |||||
return lhs.stake.getId() < rhs.stake.getId(); | |||||
}); | |||||
WriteCompactSize(ss, stakes.size()); | WriteCompactSize(ss, stakes.size()); | ||||
for (const auto &s : stakes) { | for (const auto &s : stakes) { | ||||
ss << s.stake; | ss << s.stake; | ||||
} | } | ||||
CHashWriter ss2(SER_GETHASH, 0); | CHashWriter ss2(SER_GETHASH, 0); | ||||
ss2 << ss.GetHash(); | ss2 << ss.GetHash(); | ||||
ss2 << master; | ss2 << master; | ||||
return ProofId(ss2.GetHash()); | return ProofId(ss2.GetHash()); | ||||
} | } | ||||
} // namespace avalanche | } // namespace avalanche |