Changeset View
Changeset View
Standalone View
Standalone View
src/test/util.cpp
- This file was copied to src/test/util/mining.cpp.
// Copyright (c) 2019 The Bitcoin Core developers | // Copyright (c) 2019 The Bitcoin Core 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 <test/util.h> | #include <test/util.h> | ||||
#include <chainparams.h> | |||||
#include <config.h> | #include <config.h> | ||||
#include <consensus/merkle.h> | |||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <miner.h> | |||||
#include <pow/pow.h> | |||||
#include <validation.h> | |||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#endif // ENABLE_WALLET | #endif // ENABLE_WALLET | ||||
const std::string ADDRESS_BCHREG_UNSPENDABLE = | const std::string ADDRESS_BCHREG_UNSPENDABLE = | ||||
"bchreg:qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqha9s37tt"; | "bchreg:qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqha9s37tt"; | ||||
Show All 19 Lines | void importaddress(CWallet &wallet, const std::string &address) { | ||||
wallet.MarkDirty(); | wallet.MarkDirty(); | ||||
assert(!spk_man->HaveWatchOnly(script)); | assert(!spk_man->HaveWatchOnly(script)); | ||||
if (!spk_man->AddWatchOnly(script, 0 /* nCreateTime */)) { | if (!spk_man->AddWatchOnly(script, 0 /* nCreateTime */)) { | ||||
assert(false); | assert(false); | ||||
} | } | ||||
wallet.SetAddressBook(dest, /* label */ "", "receive"); | wallet.SetAddressBook(dest, /* label */ "", "receive"); | ||||
} | } | ||||
#endif // ENABLE_WALLET | #endif // ENABLE_WALLET | ||||
CTxIn generatetoaddress(const Config &config, const std::string &address) { | |||||
const auto dest = DecodeDestination(address, config.GetChainParams()); | |||||
assert(IsValidDestination(dest)); | |||||
const auto coinbase_script = GetScriptForDestination(dest); | |||||
return MineBlock(config, coinbase_script); | |||||
} | |||||
CTxIn MineBlock(const Config &config, const CScript &coinbase_scriptPubKey) { | |||||
auto block = PrepareBlock(config, coinbase_scriptPubKey); | |||||
while (!CheckProofOfWork(block->GetHash(), block->nBits, | |||||
config.GetChainParams().GetConsensus())) { | |||||
++block->nNonce; | |||||
assert(block->nNonce); | |||||
} | |||||
bool processed{ProcessNewBlock(config, block, true, nullptr)}; | |||||
assert(processed); | |||||
return CTxIn{block->vtx[0]->GetId(), 0}; | |||||
} | |||||
std::shared_ptr<CBlock> PrepareBlock(const Config &config, | |||||
const CScript &coinbase_scriptPubKey) { | |||||
auto block = | |||||
std::make_shared<CBlock>(BlockAssembler{config, ::g_mempool} | |||||
.CreateNewBlock(coinbase_scriptPubKey) | |||||
->block); | |||||
LOCK(cs_main); | |||||
block->nTime = ::ChainActive().Tip()->GetMedianTimePast() + 1; | |||||
block->hashMerkleRoot = BlockMerkleRoot(*block); | |||||
return block; | |||||
} |