LCOV - code coverage report
Current view: top level - src - outputtype.cpp (source / functions) Hit Total Coverage
Test: test_dash_coverage.info Lines: 10 30 33.3 %
Date: 2026-06-25 07:23:51 Functions: 2 5 40.0 %

          Line data    Source code
       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             : 
       6             : #include <outputtype.h>
       7             : 
       8             : #include <pubkey.h>
       9             : #include <script/script.h>
      10             : #include <script/sign.h>
      11             : #include <script/signingprovider.h>
      12             : #include <script/standard.h>
      13             : #include <util/vector.h>
      14             : 
      15             : #include <assert.h>
      16             : #include <string>
      17             : 
      18             : static const std::string OUTPUT_TYPE_STRING_LEGACY = "legacy";
      19             : static const std::string OUTPUT_TYPE_STRING_UNKNOWN = "unknown";
      20             : 
      21             : const std::array<OutputType, 1> OUTPUT_TYPES = {OutputType::LEGACY};
      22             : 
      23           0 : bool ParseOutputType(const std::string& type, OutputType& output_type)
      24             : {
      25           0 :     if (type == OUTPUT_TYPE_STRING_LEGACY) {
      26           0 :         output_type = OutputType::LEGACY;
      27           0 :         return true;
      28             :     }
      29           0 :     return false;
      30           0 : }
      31             : 
      32          48 : const std::string& FormatOutputType(OutputType type)
      33             : {
      34          48 :     switch (type) {
      35          48 :     case OutputType::LEGACY: return OUTPUT_TYPE_STRING_LEGACY;
      36           0 :     case OutputType::UNKNOWN: return OUTPUT_TYPE_STRING_UNKNOWN;
      37             :     } // no default case, so the compiler can warn about missing cases
      38           0 :     assert(false);
      39          48 : }
      40             : 
      41           0 : CTxDestination GetDestinationForKey(const CPubKey& key, OutputType type)
      42             : {
      43           0 :     switch (type) {
      44           0 :     case OutputType::LEGACY: return PKHash(key);
      45             :     case OutputType::UNKNOWN: {} // This function should never be used with UNKNOWN, so let it assert
      46           0 :     } // no default case, so the compiler can warn about missing cases
      47           0 :     assert(false);
      48             : }
      49             : 
      50           0 : std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key)
      51             : {
      52           0 :     PKHash keyid(key);
      53           0 :     CTxDestination p2pkh{keyid};
      54           0 :     return Vector(std::move(p2pkh));
      55             : }
      56             : 
      57           1 : CTxDestination AddAndGetDestinationForScript(FillableSigningProvider& keystore, const CScript& script, OutputType type)
      58             : {
      59             :     // Add script to keystore
      60           1 :     keystore.AddCScript(script);
      61           1 :     ScriptHash sh(script);
      62             :     // Note that scripts over 520 bytes are not yet supported.
      63           1 :     switch (type) {
      64             :     case OutputType::LEGACY:
      65           1 :         keystore.AddCScript(GetScriptForDestination(sh));
      66           1 :         return sh;
      67             :     case OutputType::UNKNOWN: {} // This function should not be used for UNKNOWN, so let it assert
      68           0 :     } // no default case, so the compiler can warn about missing cases
      69           0 :     assert(false);
      70           0 : }

Generated by: LCOV version 1.16