Changeset View
Changeset View
Standalone View
Standalone View
src/test/util/mining.cpp
- This file was copied from src/test/util.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/mining.h> | ||||
#include <chainparams.h> | #include <chainparams.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <consensus/merkle.h> | #include <consensus/merkle.h> | ||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <miner.h> | #include <miner.h> | ||||
#include <pow/pow.h> | #include <pow/pow.h> | ||||
#include <script/standard.h> | |||||
#include <validation.h> | #include <validation.h> | ||||
#ifdef ENABLE_WALLET | |||||
#include <wallet/wallet.h> | |||||
#endif // ENABLE_WALLET | |||||
const std::string ADDRESS_BCHREG_UNSPENDABLE = | const std::string ADDRESS_BCHREG_UNSPENDABLE = | ||||
"bchreg:qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqha9s37tt"; | "bchreg:qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqha9s37tt"; | ||||
#ifdef ENABLE_WALLET | |||||
std::string getnewaddress(const Config &config, CWallet &w) { | |||||
constexpr auto output_type = OutputType::LEGACY; | |||||
CTxDestination dest; | |||||
std::string error; | |||||
if (!w.GetNewDestination(output_type, "", dest, error)) { | |||||
assert(false); | |||||
} | |||||
return EncodeDestination(dest, config); | |||||
} | |||||
void importaddress(CWallet &wallet, const std::string &address) { | |||||
auto spk_man = wallet.GetLegacyScriptPubKeyMan(); | |||||
LOCK(wallet.cs_wallet); | |||||
AssertLockHeld(spk_man->cs_wallet); | |||||
const auto dest = DecodeDestination(address, wallet.chainParams); | |||||
assert(IsValidDestination(dest)); | |||||
const auto script = GetScriptForDestination(dest); | |||||
wallet.MarkDirty(); | |||||
assert(!spk_man->HaveWatchOnly(script)); | |||||
if (!spk_man->AddWatchOnly(script, 0 /* nCreateTime */)) { | |||||
assert(false); | |||||
} | |||||
wallet.SetAddressBook(dest, /* label */ "", "receive"); | |||||
} | |||||
#endif // ENABLE_WALLET | |||||
CTxIn generatetoaddress(const Config &config, const std::string &address) { | CTxIn generatetoaddress(const Config &config, const std::string &address) { | ||||
const auto dest = DecodeDestination(address, config.GetChainParams()); | const auto dest = DecodeDestination(address, config.GetChainParams()); | ||||
assert(IsValidDestination(dest)); | assert(IsValidDestination(dest)); | ||||
const auto coinbase_script = GetScriptForDestination(dest); | const auto coinbase_script = GetScriptForDestination(dest); | ||||
return MineBlock(config, coinbase_script); | return MineBlock(config, coinbase_script); | ||||
} | } | ||||
Show All 28 Lines |