LCOV - code coverage report
Current view: top level - src - clientversion.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 5 42 11.9 %
Date: 2023-10-05 12:38:51 Functions: 3 7 42.9 %
Branches: 4 96 4.2 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2012-2022 The Bitcoin Core developers
       2                 :            : // Distributed under the MIT software license, see the accompanying
       3                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4                 :            : 
       5                 :            : #include <clientversion.h>
       6                 :            : #include <util/translation.h>
       7                 :            : 
       8                 :            : #include <tinyformat.h>
       9                 :            : 
      10                 :            : #include <sstream>
      11                 :            : #include <string>
      12                 :            : #include <vector>
      13                 :            : 
      14                 :            : /**
      15                 :            :  * Name of client reported in the 'version' message. Report the same name
      16                 :            :  * for both bitcoind and bitcoin-qt, to make it harder for attackers to
      17                 :            :  * target servers or GUI users specifically.
      18                 :            :  */
      19         [ +  - ]:          2 : const std::string CLIENT_NAME("Satoshi");
      20                 :            : 
      21                 :            : 
      22                 :            : #ifdef HAVE_BUILD_INFO
      23                 :            : #include <obj/build.h>
      24                 :            : // The <obj/build.h>, which is generated by the build environment (share/genbuild.sh),
      25                 :            : // could contain only one line of the following:
      26                 :            : //   - "#define BUILD_GIT_TAG ...", if the top commit is tagged
      27                 :            : //   - "#define BUILD_GIT_COMMIT ...", if the top commit is not tagged
      28                 :            : //   - "// No build information available", if proper git information is not available
      29                 :            : #endif
      30                 :            : 
      31                 :            : //! git will put "#define GIT_COMMIT_ID ..." on the next line inside archives. $Format:%n#define GIT_COMMIT_ID "%H"$
      32                 :            : 
      33                 :            : #ifdef BUILD_GIT_TAG
      34                 :            :     #define BUILD_DESC BUILD_GIT_TAG
      35                 :            :     #define BUILD_SUFFIX ""
      36                 :            : #else
      37                 :            :     #define BUILD_DESC "v" PACKAGE_VERSION
      38                 :            :     #if CLIENT_VERSION_IS_RELEASE
      39                 :            :         #define BUILD_SUFFIX ""
      40                 :            :     #elif defined(BUILD_GIT_COMMIT)
      41                 :            :         #define BUILD_SUFFIX "-" BUILD_GIT_COMMIT
      42                 :            :     #elif defined(GIT_COMMIT_ID)
      43                 :            :         #define BUILD_SUFFIX "-g" GIT_COMMIT_ID
      44                 :            :     #else
      45                 :            :         #define BUILD_SUFFIX "-unk"
      46                 :            :     #endif
      47                 :            : #endif
      48                 :            : 
      49                 :          0 : static std::string FormatVersion(int nVersion)
      50                 :            : {
      51                 :          0 :     return strprintf("%d.%d.%d", nVersion / 10000, (nVersion / 100) % 100, nVersion % 100);
      52                 :            : }
      53                 :            : 
      54                 :          1 : std::string FormatFullVersion()
      55                 :            : {
      56   [ +  -  -  +  :          1 :     static const std::string CLIENT_BUILD(BUILD_DESC BUILD_SUFFIX);
                   +  - ]
      57                 :          1 :     return CLIENT_BUILD;
      58                 :          0 : }
      59                 :            : 
      60                 :            : /**
      61                 :            :  * Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki)
      62                 :            :  */
      63                 :          0 : std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
      64                 :            : {
      65                 :          0 :     std::ostringstream ss;
      66         [ #  # ]:          0 :     ss << "/";
      67   [ #  #  #  #  :          0 :     ss << name << ":" << FormatVersion(nClientVersion);
             #  #  #  # ]
      68         [ #  # ]:          0 :     if (!comments.empty())
      69                 :            :     {
      70                 :          0 :         std::vector<std::string>::const_iterator it(comments.begin());
      71   [ #  #  #  # ]:          0 :         ss << "(" << *it;
      72         [ #  # ]:          0 :         for(++it; it != comments.end(); ++it)
      73   [ #  #  #  # ]:          0 :             ss << "; " << *it;
      74         [ #  # ]:          2 :         ss << ")";
      75                 :          0 :     }
      76         [ #  # ]:          0 :     ss << "/";
      77         [ #  # ]:          0 :     return ss.str();
      78                 :          0 : }
      79                 :            : 
      80                 :          0 : std::string CopyrightHolders(const std::string& strPrefix)
      81                 :            : {
      82         [ #  # ]:          0 :     const auto copyright_devs = strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION);
      83         [ #  # ]:          0 :     std::string strCopyrightHolders = strPrefix + copyright_devs;
      84                 :            : 
      85                 :            :     // Make sure Bitcoin Core copyright is not removed by accident
      86         [ #  # ]:          0 :     if (copyright_devs.find("Bitcoin Core") == std::string::npos) {
      87   [ #  #  #  #  :          0 :         strCopyrightHolders += "\n" + strPrefix + "The Bitcoin Core developers";
                   #  # ]
      88                 :          0 :     }
      89                 :          0 :     return strCopyrightHolders;
      90         [ #  # ]:          0 : }
      91                 :            : 
      92                 :          0 : std::string LicenseInfo()
      93                 :            : {
      94         [ #  # ]:          0 :     const std::string URL_SOURCE_CODE = "<https://github.com/bitcoin/bitcoin>";
      95                 :            : 
      96   [ #  #  #  #  :          0 :     return CopyrightHolders(strprintf(_("Copyright (C) %i-%i").translated, 2009, COPYRIGHT_YEAR) + " ") + "\n" +
          #  #  #  #  #  
                #  #  # ]
      97         [ #  # ]:          0 :            "\n" +
      98   [ #  #  #  # ]:          0 :            strprintf(_("Please contribute if you find %s useful. "
      99         [ #  # ]:          0 :                        "Visit %s for further information about the software.").translated, PACKAGE_NAME, "<" PACKAGE_URL ">") +
     100         [ #  # ]:          0 :            "\n" +
     101   [ #  #  #  #  :          0 :            strprintf(_("The source code is available from %s.").translated, URL_SOURCE_CODE) +
                   #  # ]
     102         [ #  # ]:          0 :            "\n" +
     103         [ #  # ]:          0 :            "\n" +
     104   [ #  #  #  #  :          0 :            _("This is experimental software.").translated + "\n" +
                   #  # ]
     105   [ #  #  #  #  :          0 :            strprintf(_("Distributed under the MIT software license, see the accompanying file %s or %s").translated, "COPYING", "<https://opensource.org/licenses/MIT>") +
                   #  # ]
     106                 :            :            "\n";
     107                 :          0 : }

Generated by: LCOV version 1.14