I want to generate a block with specific transaction via bitcoin-cli on regtest.
The "generate" command does not have the option. It collects transactions in mempool by the default rule.
I guess I can do it with some code change like the following way but I don't want to change it if possible.
TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey)
{
const CChainParams& chainparams = Params();
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey);
CBlock& block = pblocktemplate->block;
// Replace mempool-selected txns with just coinbase plus passed-in txns:
block.vtx.resize(1);
for (const CMutableTransaction& tx : txns)
block.vtx.push_back(MakeTransactionRef(tx));
https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/miner.cpp#L147 https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/test/test_bitcoin.cpp#L155 https://bitcoincore.org/en/doc/0.17.0/rpc/generating/generate/