/ src / outputtype.h
outputtype.h
 1  // Copyright (c) 2009-2010 Satoshi Nakamoto
 2  // Copyright (c) 2009-2022 The Bitcoin Core 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 BITCOIN_OUTPUTTYPE_H
 7  #define BITCOIN_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      UNKNOWN,
23  };
24  
25  static constexpr auto OUTPUT_TYPES = std::array{
26      OutputType::LEGACY,
27      OutputType::P2SH_SEGWIT,
28      OutputType::BECH32,
29      OutputType::BECH32M,
30  };
31  
32  std::optional<OutputType> ParseOutputType(const std::string& str);
33  const std::string& FormatOutputType(OutputType type);
34  
35  /**
36   * Get a destination of the requested type (if possible) to the specified key.
37   * The caller must make sure LearnRelatedScripts has been called beforehand.
38   */
39  CTxDestination GetDestinationForKey(const CPubKey& key, OutputType);
40  
41  /** Get all destinations (potentially) supported by the wallet for the given key. */
42  std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key);
43  
44  /**
45   * Get a destination of the requested type (if possible) to the specified script.
46   * This function will automatically add the script (and any other
47   * necessary scripts) to the keystore.
48   */
49  CTxDestination AddAndGetDestinationForScript(FillableSigningProvider& keystore, const CScript& script, OutputType);
50  
51  /** Get the OutputType for a CTxDestination */
52  std::optional<OutputType> OutputTypeFromDestination(const CTxDestination& dest);
53  
54  #endif // BITCOIN_OUTPUTTYPE_H