outputtype.h raw
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-present 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 <string_view>
16 #include <vector>
17
18 enum class OutputType {
19 LEGACY,
20 P2SH_SEGWIT,
21 BECH32,
22 BECH32M,
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 };
32
33 std::optional<OutputType> ParseOutputType(std::string_view str);
34 const std::string& FormatOutputType(OutputType type);
35 std::string FormatAllOutputTypes();
36
37 /**
38 * Get a destination of the requested type (if possible) to the specified script.
39 * This function will automatically add the script (and any other
40 * necessary scripts) to the keystore.
41 */
42 CTxDestination AddAndGetDestinationForScript(FlatSigningProvider& keystore, const CScript& script, OutputType);
43
44 /** Get the OutputType for a CTxDestination */
45 std::optional<OutputType> OutputTypeFromDestination(const CTxDestination& dest);
46
47 #endif // BITCOIN_OUTPUTTYPE_H
48