Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/util.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 <amount.h> | #include <amount.h> | ||||
#include <avalanche/proofbuilder.h> | #include <avalanche/proofbuilder.h> | ||||
#include <avalanche/test/util.h> | #include <avalanche/test/util.h> | ||||
#include <key.h> | #include <key.h> | ||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <random.h> | #include <random.h> | ||||
#include <script/standard.h> | |||||
#include <validation.h> | |||||
#include <limits> | #include <limits> | ||||
namespace avalanche { | namespace avalanche { | ||||
Proof buildRandomProof(uint32_t score) { | Proof buildRandomProof(uint32_t score) { | ||||
CKey key; | CKey key; | ||||
key.MakeNewKey(true); | key.MakeNewKey(true); | ||||
const COutPoint o(TxId(GetRandHash()), 0); | |||||
const Amount v = (int64_t(score) * COIN) / 100; | |||||
const int height = 1234; | |||||
const bool is_coinbase = false; | |||||
{ | |||||
CScript script = GetScriptForDestination(PKHash(key.GetPubKey())); | |||||
LOCK(cs_main); | |||||
CCoinsViewCache &coins = ::ChainstateActive().CoinsTip(); | |||||
coins.AddCoin(o, Coin(CTxOut(v, script), height, is_coinbase), false); | |||||
} | |||||
ProofBuilder pb(0, std::numeric_limits<uint32_t>::max(), CPubKey()); | ProofBuilder pb(0, std::numeric_limits<uint32_t>::max(), CPubKey()); | ||||
pb.addUTXO(COutPoint(TxId(GetRandHash()), 0), (int64_t(score) * COIN) / 100, | pb.addUTXO(o, v, height, is_coinbase, std::move(key)); | ||||
0, false, std::move(key)); | |||||
return pb.build(); | return pb.build(); | ||||
} | } | ||||
} // namespace avalanche | } // namespace avalanche |