| 62 | } |
| 63 | |
| 64 | void generateFakeBlock(const CChainParams& params, |
| 65 | const node::NodeContext& context, |
| 66 | CWallet& wallet, |
| 67 | const CScript& coinbase_out_script) |
| 68 | { |
| 69 | TipBlock tip{getTip(params, context)}; |
| 70 | |
| 71 | // Create block |
| 72 | CBlock block; |
| 73 | CMutableTransaction coinbase_tx; |
| 74 | coinbase_tx.vin.resize(1); |
| 75 | coinbase_tx.vin[0].prevout.SetNull(); |
| 76 | coinbase_tx.vout.resize(2); |
| 77 | coinbase_tx.vout[0].scriptPubKey = coinbase_out_script; |
| 78 | coinbase_tx.vout[0].nValue = 48 * COIN; |
| 79 | coinbase_tx.vin[0].scriptSig = CScript() << ++tip.tip_height << OP_0; |
| 80 | coinbase_tx.vout[1].scriptPubKey = coinbase_out_script; // extra output |
| 81 | coinbase_tx.vout[1].nValue = 1 * COIN; |
| 82 | |
| 83 | // Fill the coinbase with outputs that don't belong to the wallet in order to benchmark |
| 84 | // AvailableCoins' behavior with unnecessary TXOs |
| 85 | for (int i = 0; i < 50; ++i) { |
| 86 | coinbase_tx.vout.emplace_back(1 * COIN / 50, CScript(OP_TRUE)); |
| 87 | } |
| 88 | |
| 89 | block.vtx = {MakeTransactionRef(std::move(coinbase_tx))}; |
| 90 | |
| 91 | block.nVersion = VERSIONBITS_LAST_OLD_BLOCK_VERSION; |
| 92 | block.hashPrevBlock = tip.prev_block_hash; |
| 93 | block.hashMerkleRoot = BlockMerkleRoot(block); |
| 94 | block.nTime = ++tip.prev_block_time; |
| 95 | block.nBits = params.GenesisBlock().nBits; |
| 96 | block.nNonce = 0; |
| 97 | |
| 98 | { |
| 99 | LOCK(::cs_main); |
| 100 | // Add it to the index |
| 101 | CBlockIndex* pindex{context.chainman->m_blockman.AddToBlockIndex(block, context.chainman->m_best_header)}; |
| 102 | // add it to the chain |
| 103 | context.chainman->ActiveChain().SetTip(*pindex); |
| 104 | } |
| 105 | |
| 106 | // notify wallet |
| 107 | const auto& pindex = WITH_LOCK(::cs_main, return context.chainman->ActiveChain().Tip()); |
| 108 | wallet.blockConnected(ChainstateRole{}, kernel::MakeBlockInfo(pindex, &block)); |
| 109 | } |
| 110 | |
| 111 | struct PreSelectInputs { |
| 112 | // How many coins from the wallet the process should select |
no test coverage detected