Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proofbuilder.cpp
// Copyright (c) 2020 The Bitcoin developers | // Copyright (c) 2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <avalanche/proofbuilder.h> | #include <avalanche/proofbuilder.h> | ||||
#include <random.h> | #include <random.h> | ||||
namespace avalanche { | namespace avalanche { | ||||
SignedStake ProofBuilder::StakeSigner::sign(const ProofId &proofid) { | SignedStake ProofBuilder::StakeSigner::sign(const StakeCommitment &commitment) { | ||||
const uint256 h = stake.getHash(proofid); | const uint256 h = stake.getHash(commitment); | ||||
SchnorrSig sig; | SchnorrSig sig; | ||||
if (!key.SignSchnorr(h, sig)) { | if (!key.SignSchnorr(h, sig)) { | ||||
sig.fill(0); | sig.fill(0); | ||||
} | } | ||||
return SignedStake(std::move(stake), std::move(sig)); | return SignedStake(std::move(stake), std::move(sig)); | ||||
} | } | ||||
bool ProofBuilder::addUTXO(COutPoint utxo, Amount amount, uint32_t height, | bool ProofBuilder::addUTXO(COutPoint utxo, Amount amount, uint32_t height, | ||||
bool is_coinbase, CKey key) { | bool is_coinbase, CKey key) { | ||||
if (!key.IsValid()) { | if (!key.IsValid()) { | ||||
return false; | return false; | ||||
} | } | ||||
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() { | ||||
const ProofId proofid = getProofId(); | const ProofId proofid = getProofId(); | ||||
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(proofid)); | 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); | ||||
} | } | ||||
ProofId ProofBuilder::getProofId() const { | ProofId ProofBuilder::getProofId() const { | ||||
CHashWriter ss(SER_GETHASH, 0); | CHashWriter ss(SER_GETHASH, 0); | ||||
Show All 20 Lines |