mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
[test] move mining helper functions into test library
This commit is contained in:
parent
2cb4e8bdc7
commit
f613e5dfda
7 changed files with 79 additions and 59 deletions
|
|
@ -4,15 +4,9 @@
|
|||
|
||||
#include <test/util.h>
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <consensus/merkle.h>
|
||||
#include <key_io.h>
|
||||
#include <miner.h>
|
||||
#include <outputtype.h>
|
||||
#include <pow.h>
|
||||
#include <script/standard.h>
|
||||
#include <validation.h>
|
||||
#include <validationinterface.h>
|
||||
#ifdef ENABLE_WALLET
|
||||
#include <wallet/wallet.h>
|
||||
#endif
|
||||
|
|
@ -44,41 +38,3 @@ void importaddress(CWallet& wallet, const std::string& address)
|
|||
wallet.SetAddressBook(dest, /* label */ "", "receive");
|
||||
}
|
||||
#endif // ENABLE_WALLET
|
||||
|
||||
CTxIn generatetoaddress(const std::string& address)
|
||||
{
|
||||
const auto dest = DecodeDestination(address);
|
||||
assert(IsValidDestination(dest));
|
||||
const auto coinbase_script = GetScriptForDestination(dest);
|
||||
|
||||
return MineBlock(coinbase_script);
|
||||
}
|
||||
|
||||
CTxIn MineBlock(const CScript& coinbase_scriptPubKey)
|
||||
{
|
||||
auto block = PrepareBlock(coinbase_scriptPubKey);
|
||||
|
||||
while (!CheckProofOfWork(block->GetHash(), block->nBits, Params().GetConsensus())) {
|
||||
++block->nNonce;
|
||||
assert(block->nNonce);
|
||||
}
|
||||
|
||||
bool processed{ProcessNewBlock(Params(), block, true, nullptr)};
|
||||
assert(processed);
|
||||
|
||||
return CTxIn{block->vtx[0]->GetHash(), 0};
|
||||
}
|
||||
|
||||
std::shared_ptr<CBlock> PrepareBlock(const CScript& coinbase_scriptPubKey)
|
||||
{
|
||||
auto block = std::make_shared<CBlock>(
|
||||
BlockAssembler{Params()}
|
||||
.CreateNewBlock(coinbase_scriptPubKey)
|
||||
->block);
|
||||
|
||||
LOCK(cs_main);
|
||||
block->nTime = ::ChainActive().Tip()->GetMedianTimePast() + 1;
|
||||
block->hashMerkleRoot = BlockMerkleRoot(*block);
|
||||
|
||||
return block;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue