@@ -260,6 +260,55 @@ CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransa
260
260
return block;
261
261
}
262
262
263
+
264
+ CMutableTransaction TestChain100Setup::CreateValidMempoolTransaction (CTransactionRef input_transaction,
265
+ int input_vout,
266
+ int input_height,
267
+ CKey input_signing_key,
268
+ CScript output_destination,
269
+ CAmount output_amount)
270
+ {
271
+ // Transaction we will submit to the mempool
272
+ CMutableTransaction mempool_txn;
273
+
274
+ // Create an input
275
+ COutPoint outpoint_to_spend (input_transaction->GetHash (), input_vout);
276
+ CTxIn input (outpoint_to_spend);
277
+ mempool_txn.vin .push_back (input);
278
+
279
+ // Create an output
280
+ CTxOut output (output_amount, output_destination);
281
+ mempool_txn.vout .push_back (output);
282
+
283
+ // Sign the transaction
284
+ // - Add the signing key to a keystore
285
+ FillableSigningProvider keystore;
286
+ keystore.AddKey (input_signing_key);
287
+ // - Populate a CoinsViewCache with the unspent output
288
+ CCoinsView coins_view;
289
+ CCoinsViewCache coins_cache (&coins_view);
290
+ AddCoins (coins_cache, *input_transaction.get (), input_height);
291
+ // - Use GetCoin to properly populate utxo_to_spend,
292
+ Coin utxo_to_spend;
293
+ assert (coins_cache.GetCoin (outpoint_to_spend, utxo_to_spend));
294
+ // - Then add it to a map to pass in to SignTransaction
295
+ std::map<COutPoint, Coin> input_coins;
296
+ input_coins.insert ({outpoint_to_spend, utxo_to_spend});
297
+ // - Default signature hashing type
298
+ int nHashType = SIGHASH_ALL;
299
+ std::map<int , std::string> input_errors;
300
+ assert (SignTransaction (mempool_txn, &keystore, input_coins, nHashType, input_errors));
301
+
302
+ // Add transaction to the mempool
303
+ {
304
+ LOCK (cs_main);
305
+ const MempoolAcceptResult result = AcceptToMemoryPool (*m_node.mempool .get (), MakeTransactionRef (mempool_txn), /* bypass_limits */ false );
306
+ assert (result.m_result_type == MempoolAcceptResult::ResultType::VALID);
307
+ }
308
+
309
+ return mempool_txn;
310
+ }
311
+
263
312
TestChain100Setup::~TestChain100Setup ()
264
313
{
265
314
gArgs .ForceSetArg (" -segwitheight" , " 0" );
0 commit comments