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> | |||||
namespace avalanche { | namespace avalanche { | ||||
SignedStake ProofBuilder::StakeSigner::sign(const ProofId &proofid) { | SignedStake ProofBuilder::StakeSigner::sign(const ProofId &proofid) { | ||||
const uint256 h = stake.getHash(proofid); | const uint256 h = stake.getHash(proofid); | ||||
std::array<uint8_t, 64> sig; | std::array<uint8_t, 64> sig; | ||||
std::vector<uint8_t> vchSig; | std::vector<uint8_t> vchSig; | ||||
if (key.SignSchnorr(h, vchSig)) { | if (key.SignSchnorr(h, vchSig)) { | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | ProofId ProofBuilder::getProofId() const { | ||||
WriteCompactSize(ss, stakes.size()); | WriteCompactSize(ss, stakes.size()); | ||||
for (const auto &s : stakes) { | for (const auto &s : stakes) { | ||||
ss << s.stake; | ss << s.stake; | ||||
} | } | ||||
return ProofId(ss.GetHash()); | return ProofId(ss.GetHash()); | ||||
} | } | ||||
Proof ProofBuilder::buildRandom(uint32_t score) { | |||||
CKey key; | |||||
key.MakeNewKey(true); | |||||
ProofBuilder pb(0, std::numeric_limits<uint32_t>::max(), CPubKey()); | |||||
pb.addUTXO(COutPoint(TxId(GetRandHash()), 0), (int64_t(score) * COIN) / 100, | |||||
0, std::move(key)); | |||||
return pb.build(); | |||||
} | |||||
} // namespace avalanche | } // namespace avalanche |