refactor: Move license info into new module
What changed, and why it matters
This commit is a straightforward code cleanup: it moves the functions that generate copyright and license text from one source file to a new dedicated module, then updates the various Bitcoin programs to include that new module. There is no change to what the software does, no bug fix, and no security-relevant behavior change.
No security action needed. Treat as normal refactoring review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change extracts CopyrightHolders() and LicenseInfo() from src/clientversion.cpp/.h into a new src/common/license_info.cpp/.h translation unit. It adds the new source file to CMakeLists.txt, updates IWYU enforcement regex, and adjusts #include directives across bitcoin-cli, bitcoin-tx, bitcoin-util, bitcoin-wallet, bitcoin (GUI), bitcoind, qt/splashscreen, qt/utilitydialog, and test/fuzz/string.cpp. The moved code is identical in behavior; only its location and include dependencies change.
Changed components
src/clientversion.cppsrc/clientversion.hsrc/common/license_info.cppsrc/common/license_info.hsrc/bitcoin-cli.cppsrc/bitcoin-tx.cppsrc/bitcoin-util.cppsrc/bitcoin-wallet.cppsrc/bitcoin.cppsrc/bitcoind.cppsrc/qt/splashscreen.cppsrc/qt/utilitydialog.cppsrc/test/fuzz/string.cppsrc/CMakeLists.txtci/test/03_test_script.shInspect captured patch +70 / −40
diff --git a/ci/test/03_test_script.sh b/ci/test/03_test_script.sh
index 7b4d7837..9d6351af 100755
--- a/ci/test/03_test_script.sh
+++ b/ci/test/03_test_script.sh
@@ -209,7 +209,7 @@ fi
if [[ "${RUN_IWYU}" == true ]]; then
# TODO: Consider enforcing IWYU across the entire codebase.
- FILES_WITH_ENFORCED_IWYU="/src/((crypto|index|kernel|primitives|univalue/(lib|test)|zmq)/.*\\.cpp|node/blockstorage\\.cpp|node/utxo_snapshot\\.cpp|core_io\\.cpp|signet\\.cpp)"
+ FILES_WITH_ENFORCED_IWYU="/src/(((crypto|index|kernel|primitives|univalue/(lib|test)|zmq)/.*|common/license_info|node/blockstorage|node/utxo_snapshot|clientversion|core_io|signet)\\.cpp)"
jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns)))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_errors.json"
jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns) | not))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_warnings.json"
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ad18115b..f8588efd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -97,6 +97,7 @@ add_library(bitcoin_common STATIC EXCLUDE_FROM_ALL
common/config.cpp
common/init.cpp
common/interfaces.cpp
+ common/license_info.cpp
common/messages.cpp
common/netif.cpp
common/pcp.cpp
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index 2c02d87c..b0caf2d1 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -8,6 +8,7 @@
#include <chainparamsbase.h>
#include <clientversion.h>
#include <common/args.h>
+#include <common/license_info.h>
#include <common/system.h>
#include <compat/compat.h>
#include <compat/stdin.h>
diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp
index fdff656f..d4702a9c 100644
--- a/src/bitcoin-tx.cpp
+++ b/src/bitcoin-tx.cpp
@@ -8,6 +8,7 @@
#include <clientversion.h>
#include <coins.h>
#include <common/args.h>
+#include <common/license_info.h>
#include <common/system.h>
#include <compat/compat.h>
#include <consensus/amount.h>
diff --git a/src/bitcoin-util.cpp b/src/bitcoin-util.cpp
index a6fd026b..aa3fd306 100644
--- a/src/bitcoin-util.cpp
+++ b/src/bitcoin-util.cpp
@@ -10,6 +10,7 @@
#include <chainparamsbase.h>
#include <clientversion.h>
#include <common/args.h>
+#include <common/license_info.h>
#include <common/system.h>
#include <compat/compat.h>
#include <core_io.h>
diff --git a/src/bitcoin-wallet.cpp b/src/bitcoin-wallet.cpp
index 6811f8c5..9b0136da 100644
--- a/src/bitcoin-wallet.cpp
+++ b/src/bitcoin-wallet.cpp
@@ -8,6 +8,7 @@
#include <chainparamsbase.h>
#include <clientversion.h>
#include <common/args.h>
+#include <common/license_info.h>
#include <common/system.h>
#include <compat/compat.h>
#include <interfaces/init.h>
diff --git a/src/bitcoin.cpp b/src/bitcoin.cpp
index 5d42bb04..827f6cf1 100644
--- a/src/bitcoin.cpp
+++ b/src/bitcoin.cpp
@@ -6,6 +6,7 @@
#include <clientversion.h>
#include <common/args.h>
+#include <common/license_info.h>
#include <common/system.h>
#include <util/fs.h>
#include <util/exec.h>
diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
index 32db3e72..ac731587 100644
--- a/src/bitcoind.cpp
+++ b/src/bitcoind.cpp
@@ -9,6 +9,7 @@
#include <clientversion.h>
#include <common/args.h>
#include <common/init.h>
+#include <common/license_info.h>
#include <common/system.h>
#include <compat/compat.h>
#include <init.h>
diff --git a/src/clientversion.cpp b/src/clientversion.cpp
index 86610112..222dafb3 100644
--- a/src/clientversion.cpp
+++ b/src/clientversion.cpp
@@ -6,10 +6,8 @@
#include <clientversion.h>
-#include <util/string.h>
-#include <util/translation.h>
-
#include <tinyformat.h>
+#include <util/string.h>
#include <string>
#include <vector>
@@ -70,34 +68,3 @@ std::string FormatSubVersion(const std::string& name, int nClientVersion, const
if (!comments.empty()) comments_str = strprintf("(%s)", Join(comments, "; "));
return strprintf("/%s:%s%s/", name, FormatVersion(nClientVersion), comments_str);
}
-
-std::string CopyrightHolders(const std::string& strPrefix)
-{
- const auto copyright_devs = strprintf(_(COPYRIGHT_HOLDERS), COPYRIGHT_HOLDERS_SUBSTITUTION).translated;
- std::string strCopyrightHolders = strPrefix + copyright_devs;
-
- // Make sure Bitcoin Core copyright is not removed by accident
- if (copyright_devs.find("Bitcoin Core") == std::string::npos) {
- strCopyrightHolders += "\n" + strPrefix + "The Bitcoin Core developers";
- }
- return strCopyrightHolders;
-}
-
-std::string LicenseInfo()
-{
- const std::string URL_SOURCE_CODE = "<https://github.com/bitcoin/bitcoin>";
-
- return CopyrightHolders(strprintf(_("Copyright (C) %i-%i"), 2009, COPYRIGHT_YEAR).translated + " ") + "\n" +
- "\n" +
- strprintf(_("Please contribute if you find %s useful. "
- "Visit %s for further information about the software."),
- CLIENT_NAME, "<" CLIENT_URL ">")
- .translated +
- "\n" +
- strprintf(_("The source code is available from %s."), URL_SOURCE_CODE).translated +
- "\n" +
- "\n" +
- _("This is experimental software.") + "\n" +
- strprintf(_("Distributed under the MIT software license, see the accompanying file %s or %s"), "COPYING", "<https://opensource.org/license/MIT>").translated +
- "\n";
-}
diff --git a/src/clientversion.h b/src/clientversion.h
index 9d09e502..f4822a12 100644
--- a/src/clientversion.h
+++ b/src/clientversion.h
@@ -34,11 +34,6 @@ extern const std::string UA_NAME;
std::string FormatFullVersion();
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
-std::string CopyrightHolders(const std::string& strPrefix);
-
-/** Returns licensing information (for -version) */
-std::string LicenseInfo();
-
#endif // RC_INVOKED
#endif // BITCOIN_CLIENTVERSION_H
diff --git a/src/common/license_info.cpp b/src/common/license_info.cpp
new file mode 100644
index 00000000..8cf99c29
--- /dev/null
+++ b/src/common/license_info.cpp
@@ -0,0 +1,43 @@
+// Copyright (c) The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or https://opensource.org/license/mit/.
+
+#include <bitcoin-build-config.h> // IWYU pragma: keep
+
+#include <common/license_info.h>
+
+#include <tinyformat.h>
+#include <util/translation.h>
+
+#include <string>
+
+std::string CopyrightHolders(const std::string& strPrefix)
+{
+ const auto copyright_devs = strprintf(_(COPYRIGHT_HOLDERS), COPYRIGHT_HOLDERS_SUBSTITUTION).translated;
+ std::string strCopyrightHolders = strPrefix + copyright_devs;
+
+ // Make sure Bitcoin Core copyright is not removed by accident
+ if (copyright_devs.find("Bitcoin Core") == std::string::npos) {
+ strCopyrightHolders += "\n" + strPrefix + "The Bitcoin Core developers";
+ }
+ return strCopyrightHolders;
+}
+
+std::string LicenseInfo()
+{
+ const std::string URL_SOURCE_CODE = "<https://github.com/bitcoin/bitcoin>";
+
+ return CopyrightHolders(strprintf(_("Copyright (C) %i-%i"), 2009, COPYRIGHT_YEAR).translated + " ") + "\n" +
+ "\n" +
+ strprintf(_("Please contribute if you find %s useful. "
+ "Visit %s for further information about the software."),
+ CLIENT_NAME, "<" CLIENT_URL ">")
+ .translated +
+ "\n" +
+ strprintf(_("The source code is available from %s."), URL_SOURCE_CODE).translated +
+ "\n" +
+ "\n" +
+ _("This is experimental software.") + "\n" +
+ strprintf(_("Distributed under the MIT software license, see the accompanying file %s or %s"), "COPYING", "<https://opensource.org/license/MIT>").translated +
+ "\n";
+}
diff --git a/src/common/license_info.h b/src/common/license_info.h
new file mode 100644
index 00000000..aedb1b7f
--- /dev/null
+++ b/src/common/license_info.h
@@ -0,0 +1,15 @@
+// Copyright (c) The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or https://opensource.org/license/mit/.
+
+#ifndef BITCOIN_COMMON_LICENSE_INFO_H
+#define BITCOIN_COMMON_LICENSE_INFO_H
+
+#include <string>
+
+std::string CopyrightHolders(const std::string& strPrefix);
+
+/** Returns licensing information (for -version) */
+std::string LicenseInfo();
+
+#endif // BITCOIN_COMMON_LICENSE_INFO_H
diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp
index 553f6789..5a89ce08 100644
--- a/src/qt/splashscreen.cpp
+++ b/src/qt/splashscreen.cpp
@@ -7,6 +7,7 @@
#include <qt/splashscreen.h>
#include <clientversion.h>
+#include <common/license_info.h>
#include <common/system.h>
#include <interfaces/handler.h>
#include <interfaces/node.h>
diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp
index 99a3a837..5784b317 100644
--- a/src/qt/utilitydialog.cpp
+++ b/src/qt/utilitydialog.cpp
@@ -12,6 +12,7 @@
#include <clientversion.h>
#include <common/args.h>
+#include <common/license_info.h>
#include <init.h>
#include <util/strencodings.h>
diff --git a/src/test/fuzz/string.cpp b/src/test/fuzz/string.cpp
index d3156336..4402caa0 100644
--- a/src/test/fuzz/string.cpp
+++ b/src/test/fuzz/string.cpp
@@ -5,6 +5,7 @@
#include <blockfilter.h>
#include <clientversion.h>
#include <common/args.h>
+#include <common/license_info.h>
#include <common/messages.h>
#include <common/settings.h>
#include <common/system.h>
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.