MCPcopy Create free account
hub / github.com/ElementsProject/elements / CreateValidMempoolTransaction

Method CreateValidMempoolTransaction

src/test/util/setup_common.cpp:333–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331
332
333CMutableTransaction TestChain100Setup::CreateValidMempoolTransaction(CTransactionRef input_transaction,
334 int input_vout,
335 int input_height,
336 CKey input_signing_key,
337 CScript output_destination,
338 CAmount output_amount,
339 bool submit)
340{
341 // Transaction we will submit to the mempool
342 CMutableTransaction mempool_txn;
343
344 // Create an input
345 COutPoint outpoint_to_spend(input_transaction->GetHash(), input_vout);
346 CTxIn input(outpoint_to_spend);
347 mempool_txn.vin.push_back(input);
348
349 // Create an output
350 CTxOut output(CAsset(), output_amount, output_destination);
351 mempool_txn.vout.push_back(output);
352
353 // Sign the transaction
354 // - Add the signing key to a keystore
355 FillableSigningProvider keystore;
356 keystore.AddKey(input_signing_key);
357 // - Populate a CoinsViewCache with the unspent output
358 CCoinsView coins_view;
359 CCoinsViewCache coins_cache(&coins_view);
360 AddCoins(coins_cache, *input_transaction.get(), input_height);
361 // - Use GetCoin to properly populate utxo_to_spend,
362 Coin utxo_to_spend;
363 assert(coins_cache.GetCoin(outpoint_to_spend, utxo_to_spend));
364 // - Then add it to a map to pass in to SignTransaction
365 std::map<COutPoint, Coin> input_coins;
366 input_coins.insert({outpoint_to_spend, utxo_to_spend});
367 // - Default signature hashing type
368 int nHashType = SIGHASH_ALL;
369 std::map<int, bilingual_str> input_errors;
370 assert(SignTransaction(mempool_txn, &keystore, input_coins, nHashType, Params().HashGenesisBlock(), input_errors));
371
372 // If submit=true, add transaction to the mempool.
373 if (submit) {
374 LOCK(cs_main);
375 const MempoolAcceptResult result = m_node.chainman->ProcessTransaction(MakeTransactionRef(mempool_txn));
376 assert(result.m_result_type == MempoolAcceptResult::ResultType::VALID);
377 }
378
379 return mempool_txn;
380}
381
382CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction& tx) const
383{

Callers

nothing calls this directly

Calls 12

CAssetClass · 0.85
AddCoinsFunction · 0.85
ProcessTransactionMethod · 0.80
SignTransactionFunction · 0.50
ParamsClass · 0.50
MakeTransactionRefFunction · 0.50
GetHashMethod · 0.45
push_backMethod · 0.45
AddKeyMethod · 0.45
getMethod · 0.45
GetCoinMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected