| 331 | |
| 332 | |
| 333 | CMutableTransaction 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 | |
| 382 | CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(const CMutableTransaction& tx) const |
| 383 | { |
nothing calls this directly
no test coverage detected