transaction_utils.h raw

   1  // Copyright (c) 2019-present The Bitcoin Core developers
   2  // Distributed under the MIT software license, see the accompanying
   3  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
   4  
   5  #ifndef BITCOIN_TEST_UTIL_TRANSACTION_UTILS_H
   6  #define BITCOIN_TEST_UTIL_TRANSACTION_UTILS_H
   7  
   8  #include <primitives/transaction.h>
   9  #include <script/sign.h>
  10  
  11  #include <array>
  12  
  13  class FillableSigningProvider;
  14  class CCoinsViewCache;
  15  
  16  // create crediting transaction
  17  // [1 coinbase input => 1 output with given scriptPubkey and value]
  18  CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, CAmount nValue = 0);
  19  
  20  // create spending transaction
  21  // [1 input with referenced transaction outpoint, scriptSig, scriptWitness =>
  22  //  1 output with empty scriptPubKey, full value of referenced transaction]
  23  CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CScriptWitness& scriptWitness, const CTransaction& txCredit);
  24  
  25  // Helper: create two dummy transactions, each with two outputs.
  26  // The first has nValues[0] and nValues[1] outputs paid to a TxoutType::PUBKEY,
  27  // the second nValues[2] and nValues[3] outputs paid to a TxoutType::PUBKEYHASH.
  28  std::vector<CMutableTransaction> SetupDummyInputs(FillableSigningProvider& keystoreRet, CCoinsViewCache& coinsRet, const std::array<CAmount,4>& nValues);
  29  
  30  // bulk transaction to reach a certain target weight,
  31  // by appending a single output with padded output script
  32  void BulkTransaction(CMutableTransaction& tx, int32_t target_weight);
  33  
  34  /**
  35   * Produce a satisfying script (scriptSig or witness).
  36   *
  37   * @param provider   Utility containing the information necessary to solve a script.
  38   * @param fromPubKey The script to produce a satisfaction for.
  39   * @param txTo       The spending transaction.
  40   * @param nIn        The index of the input in `txTo` referring the output being spent.
  41   * @param amount     The value of the output being spent.
  42   * @param nHashType  Signature hash type.
  43   * @param sig_data   Additional data provided to solve a script. Filled with the resulting satisfying
  44   *                   script and whether the satisfaction is complete.
  45   *
  46   * @return           True if the produced script is entirely satisfying `fromPubKey`.
  47   **/
  48  bool SignSignature(const SigningProvider &provider, const CScript& fromPubKey, CMutableTransaction& txTo,
  49                     unsigned int nIn, const CAmount& amount, int nHashType, SignatureData& sig_data);
  50  bool SignSignature(const SigningProvider &provider, const CTransaction& txFrom, CMutableTransaction& txTo,
  51                     unsigned int nIn, int nHashType, SignatureData& sig_data);
  52  
  53  #endif // BITCOIN_TEST_UTIL_TRANSACTION_UTILS_H
  54