outputtype.h raw

   1  // Copyright (c) 2009-2010 Satoshi Nakamoto
   2  // Copyright (c) 2009-2022 The Limenka developers
   3  // Distributed under the MIT software license, see the accompanying
   4  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
   5  
   6  #ifndef LIMENKA_OUTPUTTYPE_H
   7  #define LIMENKA_OUTPUTTYPE_H
   8  
   9  #include <addresstype.h>
  10  #include <script/signingprovider.h>
  11  
  12  #include <array>
  13  #include <optional>
  14  #include <string>
  15  #include <vector>
  16  
  17  enum class OutputType {
  18      LEGACY,
  19      P2SH_SEGWIT,
  20      BECH32,
  21      BECH32M,
  22      P2SPKH,
  23      UNKNOWN,
  24  };
  25  
  26  static constexpr auto OUTPUT_TYPES = std::array{
  27      OutputType::LEGACY,
  28      OutputType::P2SH_SEGWIT,
  29      OutputType::BECH32,
  30      OutputType::BECH32M,
  31      OutputType::P2SPKH,
  32  };
  33  
  34  std::optional<OutputType> ParseOutputType(const std::string& str);
  35  const std::string& FormatOutputType(OutputType type);
  36  
  37  /**
  38   * Get a destination of the requested type (if possible) to the specified key.
  39   * The caller must make sure LearnRelatedScripts has been called beforehand.
  40   */
  41  CTxDestination GetDestinationForKey(const CPubKey& key, OutputType);
  42  
  43  /** Get all destinations (potentially) supported by the wallet for the given key. */
  44  std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key);
  45  
  46  /**
  47   * Get a destination of the requested type (if possible) to the specified script.
  48   * This function will automatically add the script (and any other
  49   * necessary scripts) to the keystore.
  50   */
  51  CTxDestination AddAndGetDestinationForScript(FlatSigningProvider& keystore, const CScript& script, OutputType);
  52  
  53  /** Get the OutputType for a CTxDestination */
  54  std::optional<OutputType> OutputTypeFromDestination(const CTxDestination& dest);
  55  
  56  #endif // LIMENKA_OUTPUTTYPE_H
  57