LCOV - code coverage report
Current view: top level - src - clientversion.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 22 23 95.7 %
Date: 2020-09-26 01:30:44 Functions: 5 5 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2012-2018 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             : 
       7             : #include <tinyformat.h>
       8             : 
       9             : 
      10             : /**
      11             :  * Name of client reported in the 'version' message. Report the same name
      12             :  * for both bitcoind and bitcoin-qt, to make it harder for attackers to
      13             :  * target servers or GUI users specifically.
      14             :  */
      15        1150 : const std::string CLIENT_NAME("Satoshi");
      16             : 
      17             : 
      18             : #ifdef HAVE_BUILD_INFO
      19             : #include <obj/build.h>
      20             : // The <obj/build.h>, which is generated by the build environment (share/genbuild.sh),
      21             : // could contain only one line of the following:
      22             : //   - "#define BUILD_GIT_TAG ...", if the top commit is tagged
      23             : //   - "#define BUILD_GIT_COMMIT ...", if the top commit is not tagged
      24             : //   - "// No build information available", if proper git information is not available
      25             : #endif
      26             : 
      27             : //! git will put "#define GIT_COMMIT_ID ..." on the next line inside archives. $Format:%n#define GIT_COMMIT_ID "%H"$
      28             : 
      29             : #ifdef BUILD_GIT_TAG
      30             :     #define BUILD_DESC BUILD_GIT_TAG
      31             :     #define BUILD_SUFFIX ""
      32             : #else
      33             :     #define BUILD_DESC "v" STRINGIZE(CLIENT_VERSION_MAJOR) "." STRINGIZE(CLIENT_VERSION_MINOR) \
      34             :                        "." STRINGIZE(CLIENT_VERSION_REVISION) "." STRINGIZE(CLIENT_VERSION_BUILD)
      35             :     #ifdef BUILD_GIT_COMMIT
      36             :         #define BUILD_SUFFIX "-" BUILD_GIT_COMMIT
      37             :     #elif defined(GIT_COMMIT_ID)
      38             :         #define BUILD_SUFFIX "-g" GIT_COMMIT_ID
      39             :     #else
      40             :         #define BUILD_SUFFIX "-unk"
      41             :     #endif
      42             : #endif
      43             : 
      44        1150 : const std::string CLIENT_BUILD(BUILD_DESC BUILD_SUFFIX);
      45             : 
      46         507 : static std::string FormatVersion(int nVersion)
      47             : {
      48         507 :     if (nVersion % 100 == 0)
      49         507 :         return strprintf("%d.%d.%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100);
      50             :     else
      51           0 :         return strprintf("%d.%d.%d.%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100, nVersion % 100);
      52         507 : }
      53             : 
      54         997 : std::string FormatFullVersion()
      55             : {
      56         997 :     return CLIENT_BUILD;
      57             : }
      58             : 
      59             : /**
      60             :  * Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki)
      61             :  */
      62         507 : std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
      63             : {
      64         507 :     std::ostringstream ss;
      65         507 :     ss << "/";
      66         507 :     ss << name << ":" << FormatVersion(nClientVersion);
      67         507 :     if (!comments.empty())
      68             :     {
      69         505 :         std::vector<std::string>::const_iterator it(comments.begin());
      70         505 :         ss << "(" << *it;
      71         516 :         for(++it; it != comments.end(); ++it)
      72          11 :             ss << "; " << *it;
      73         505 :         ss << ")";
      74         505 :     }
      75         507 :     ss << "/";
      76         507 :     return ss.str();
      77         507 : }

Generated by: LCOV version 1.15