/src/outputtype.h

https://github.com/soitun/bitcoin · C Header · 53 lines · 27 code · 11 blank · 15 comment · 0 complexity · 0c17e1a52f66467e89a6f0f5b36420c8 MD5 · raw file

  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2021 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. #ifndef BITCOIN_OUTPUTTYPE_H
  6. #define BITCOIN_OUTPUTTYPE_H
  7. #include <script/signingprovider.h>
  8. #include <script/standard.h>
  9. #include <array>
  10. #include <optional>
  11. #include <string>
  12. #include <vector>
  13. enum class OutputType {
  14. LEGACY,
  15. P2SH_SEGWIT,
  16. BECH32,
  17. BECH32M,
  18. };
  19. static constexpr auto OUTPUT_TYPES = std::array{
  20. OutputType::LEGACY,
  21. OutputType::P2SH_SEGWIT,
  22. OutputType::BECH32,
  23. OutputType::BECH32M,
  24. };
  25. std::optional<OutputType> ParseOutputType(const std::string& str);
  26. const std::string& FormatOutputType(OutputType type);
  27. /**
  28. * Get a destination of the requested type (if possible) to the specified key.
  29. * The caller must make sure LearnRelatedScripts has been called beforehand.
  30. */
  31. CTxDestination GetDestinationForKey(const CPubKey& key, OutputType);
  32. /** Get all destinations (potentially) supported by the wallet for the given key. */
  33. std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key);
  34. /**
  35. * Get a destination of the requested type (if possible) to the specified script.
  36. * This function will automatically add the script (and any other
  37. * necessary scripts) to the keystore.
  38. */
  39. CTxDestination AddAndGetDestinationForScript(FillableSigningProvider& keystore, const CScript& script, OutputType);
  40. /** Get the OutputType for a CTxDestination */
  41. std::optional<OutputType> OutputTypeFromDestination(const CTxDestination& dest);
  42. #endif // BITCOIN_OUTPUTTYPE_H