Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proofbuilder.cpp
Show All 28 Lines | bool ProofBuilder::addUTXO(COutPoint utxo, Amount amount, uint32_t height, | ||||
return stakes | return stakes | ||||
.emplace(Stake(std::move(utxo), amount, height, is_coinbase, | .emplace(Stake(std::move(utxo), amount, height, is_coinbase, | ||||
key.GetPubKey()), | key.GetPubKey()), | ||||
std::move(key)) | std::move(key)) | ||||
.second; | .second; | ||||
} | } | ||||
Proof ProofBuilder::build() { | Proof ProofBuilder::build() { | ||||
SchnorrSig proofSignature; | |||||
const LimitedProofId limitedProofId = getLimitedProofId(); | |||||
if (!masterKey.SignSchnorr(limitedProofId, proofSignature)) { | |||||
proofSignature.fill(0); | |||||
} | |||||
const ProofId proofid = getProofId(); | const ProofId proofid = getProofId(); | ||||
const StakeCommitment commitment(proofid); | const StakeCommitment commitment(proofid); | ||||
std::vector<SignedStake> signedStakes; | std::vector<SignedStake> signedStakes; | ||||
signedStakes.reserve(stakes.size()); | signedStakes.reserve(stakes.size()); | ||||
while (!stakes.empty()) { | while (!stakes.empty()) { | ||||
auto handle = stakes.extract(stakes.begin()); | auto handle = stakes.extract(stakes.begin()); | ||||
signedStakes.push_back(handle.value().sign(commitment)); | signedStakes.push_back(handle.value().sign(commitment)); | ||||
} | } | ||||
return Proof(sequence, expirationTime, masterKey.GetPubKey(), | return Proof(sequence, expirationTime, masterKey.GetPubKey(), | ||||
std::move(signedStakes), payoutScriptPubKey); | std::move(signedStakes), payoutScriptPubKey, | ||||
std::move(proofSignature)); | |||||
} | } | ||||
ProofId ProofBuilder::getProofId() const { | LimitedProofId ProofBuilder::getLimitedProofId() const { | ||||
CHashWriter ss(SER_GETHASH, 0); | CHashWriter ss(SER_GETHASH, 0); | ||||
ss << sequence; | ss << sequence; | ||||
ss << expirationTime; | ss << expirationTime; | ||||
if (!Proof::useLegacy(gArgs)) { | if (!Proof::useLegacy(gArgs)) { | ||||
ss << payoutScriptPubKey; | ss << payoutScriptPubKey; | ||||
} | } | ||||
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); | return LimitedProofId(ss.GetHash()); | ||||
ss2 << ss.GetHash(); | } | ||||
ss2 << masterKey.GetPubKey(); | |||||
ProofId ProofBuilder::getProofId() const { | |||||
CHashWriter ss(SER_GETHASH, 0); | |||||
ss << getLimitedProofId(); | |||||
ss << masterKey.GetPubKey(); | |||||
return ProofId(ss2.GetHash()); | return ProofId(ss.GetHash()); | ||||
} | } | ||||
} // namespace avalanche | } // namespace avalanche |