transaction_utils.h raw

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