LCOV - code coverage report
Current view: top level - src - clientversion.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 17 20 85.0 %
Date: 2025-02-23 09:33:43 Functions: 3 4 75.0 %

          Line data    Source code
       1             : // Copyright (c) 2012-2017 The Bitcoin Core developers
       2             : // Copyright (c) 2016-2021 The PIVX 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 "clientversion.h"
       7             : 
       8             : #include "tinyformat.h"
       9             : 
      10             : 
      11             : /**
      12             :  * Name of client reported in the 'version' message. Report the same name
      13             :  * for both pivxd and pivx-qt, to make it harder for attackers to
      14             :  * target servers or GUI users specifically.
      15             :  */
      16             : const std::string CLIENT_NAME(PACKAGE_NAME);
      17             : 
      18             : /**
      19             :  * Client version number
      20             :  */
      21             : #define CLIENT_VERSION_SUFFIX ""
      22             : 
      23             : 
      24             : /**
      25             :  * The following part of the code determines the CLIENT_BUILD variable.
      26             :  * Several mechanisms are used for this:
      27             :  * * first, if HAVE_BUILD_INFO is defined, include build.h, a file that is
      28             :  *   generated by the build environment, possibly containing the output
      29             :  *   of git-describe in a macro called BUILD_DESC
      30             :  * * secondly, if this is an exported version of the code, GIT_ARCHIVE will
      31             :  *   be defined (automatically using the export-subst git attribute), and
      32             :  *   GIT_COMMIT will contain the commit id.
      33             :  * * then, three options exist for determining CLIENT_BUILD:
      34             :  *   * if BUILD_DESC is defined, use that literally (output of git-describe)
      35             :  *   * if not, but GIT_COMMIT is defined, use v[maj].[min].[rev].[build]-g[commit]
      36             :  *   * otherwise, use v[maj].[min].[rev].[build]-unk
      37             :  * finally CLIENT_VERSION_SUFFIX is added
      38             :  */
      39             : 
      40             : //! First, include build.h if requested
      41             : #ifdef HAVE_BUILD_INFO
      42             : #include "obj/build.h"
      43             : #endif
      44             : 
      45             : //! git will put "#define GIT_ARCHIVE 1" on the next line inside archives. $Format:%n#define GIT_ARCHIVE 1$
      46             : #ifdef GIT_ARCHIVE
      47             : #define GIT_COMMIT_ID "$Format:%H$"
      48             : #define GIT_COMMIT_DATE "$Format:%cD$"
      49             : #endif
      50             : 
      51             : #define BUILD_DESC_WITH_SUFFIX(maj, min, rev, build, suffix) \
      52             :     "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-" DO_STRINGIZE(suffix)
      53             : 
      54             : #define BUILD_DESC_FROM_COMMIT(maj, min, rev, build, commit) \
      55             :     "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-g" commit
      56             : 
      57             : #define BUILD_DESC_FROM_UNKNOWN(maj, min, rev, build) \
      58             :     "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-unk"
      59             : 
      60             : #ifndef BUILD_DESC
      61             : #ifdef BUILD_SUFFIX
      62             : #define BUILD_DESC BUILD_DESC_WITH_SUFFIX(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, BUILD_SUFFIX)
      63             : #elif defined(GIT_COMMIT_ID)
      64             : #define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID)
      65             : #else
      66             : #define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD)
      67             : #endif
      68             : #endif
      69             : 
      70             : const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX);
      71             : 
      72         366 : static std::string FormatVersion(int nVersion)
      73             : {
      74         366 :     if (nVersion % 100 == 0)
      75         366 :         return strprintf("%d.%d.%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100);
      76             :     else
      77           0 :         return strprintf("%d.%d.%d.%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100, nVersion % 100);
      78             : }
      79             : 
      80         389 : std::string FormatFullVersion()
      81             : {
      82         389 :     return CLIENT_BUILD;
      83             : }
      84             : 
      85           0 : std::string FormatVersionFriendly()
      86             : {
      87           0 :     return FormatVersion(CLIENT_VERSION);
      88             : }
      89             : 
      90             : /** 
      91             :  * Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki) 
      92             :  */
      93         366 : std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
      94             : {
      95         366 :     std::ostringstream ss;
      96         366 :     ss << "/";
      97         732 :     ss << name << ":" << FormatVersion(nClientVersion);
      98         366 :     if (!comments.empty()) {
      99         360 :         std::vector<std::string>::const_iterator it(comments.begin());
     100         360 :         ss << "(" << *it;
     101         364 :         for (++it; it != comments.end(); ++it)
     102           4 :             ss << "; " << *it;
     103         360 :         ss << ")";
     104             :     }
     105         366 :     ss << "/";
     106         366 :     return ss.str();
     107             : }

Generated by: LCOV version 1.14