Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2009-2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6#include <common/messages.h>8#include <common/types.h>9#include <node/types.h>10#include <tinyformat.h>11#include <util/check.h>12#include <util/fees.h>13#include <util/strencodings.h>14#include <util/string.h>15#include <util/translation.h>17#include <map>18#include <string>19#include <string_view>20#include <utility>21#include <vector>23using node::TransactionError;24using util::Join;26namespace common {27std::string StringForFeeReason(FeeReason reason)28{29static const std::map<FeeReason, std::string> fee_reason_strings = {30{FeeReason::FEE_RATE_ESTIMATOR, "Fee Rate Estimator"},31{FeeReason::MEMPOOL_MIN, "Mempool Min Fee"},32{FeeReason::USER_SPECIFIED, "User Specified Fee"},33{FeeReason::FALLBACK, "Fallback fee"},34{FeeReason::REQUIRED, "Minimum Required Fee"},35};36auto reason_string = fee_reason_strings.find(reason);38if (reason_string == fee_reason_strings.end()) return "Unknown";40return reason_string->second;41}43const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()44{45static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {46{"unset", FeeEstimateMode::UNSET},47{"economical", FeeEstimateMode::ECONOMICAL},48{"conservative", FeeEstimateMode::CONSERVATIVE},49};50return FEE_MODES;51}53std::string FeeModeInfo(const std::pair<std::string, FeeEstimateMode>& mode, std::string& default_info)54{55switch (mode.second) {56case FeeEstimateMode::UNSET:57return strprintf("%s means no mode set (%s). \n", mode.first, default_info);58case FeeEstimateMode::ECONOMICAL:59return strprintf("%s mode potentially returns a lower fee rate estimate.\n", mode.first);60case FeeEstimateMode::CONSERVATIVE:61return strprintf("%s potentially returns a higher fee rate estimate.\n", mode.first);62} // no default case, so the compiler can warn about missing cases63assert(false);64}66std::string FeeModesDetail(std::string default_info)67{68std::string info;69for (const auto& fee_mode : FeeModeMap()) {70info += FeeModeInfo(fee_mode, default_info);71}72return strprintf("%s \n%s", FeeModes(", "), info);73}75std::string FeeModes(const std::string& delimiter)76{77return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; });78}80std::string InvalidEstimateModeErrorMessage()81{82return "Invalid estimate_mode parameter, must be one of: \"" + FeeModes("\", \"") + "\"";83}85bool FeeModeFromString(std::string_view mode_string, FeeEstimateMode& fee_estimate_mode)86{87auto searchkey = ToUpper(mode_string);88for (const auto& pair : FeeModeMap()) {89if (ToUpper(pair.first) == searchkey) {90fee_estimate_mode = pair.second;91return true;92}93}94return false;95}97bilingual_str PSBTErrorString(PSBTError err)98{99switch (err) {100case PSBTError::MISSING_INPUTS:101return Untranslated("Inputs missing or spent");102case PSBTError::SIGHASH_MISMATCH:103return Untranslated("Specified sighash value does not match value stored in PSBT");104case PSBTError::EXTERNAL_SIGNER_NOT_FOUND:105return Untranslated("External signer not found");106case PSBTError::EXTERNAL_SIGNER_FAILED:107return Untranslated("External signer failed to sign");108case PSBTError::UNSUPPORTED:109return Untranslated("Signer does not support PSBT");110case PSBTError::INCOMPLETE:111return Untranslated("Input needs additional signatures or other data");112case PSBTError::INVALID_TX:113return Untranslated("The transaction cannot be valid");114} // no default case, so the compiler can warn about missing cases115assert(false);116}118bilingual_str TransactionErrorString(const TransactionError err)119{120switch (err) {121case TransactionError::OK:122return Untranslated("No error");123case TransactionError::MISSING_INPUTS:124return Untranslated("Inputs missing or spent");125case TransactionError::ALREADY_IN_UTXO_SET:126return Untranslated("Transaction outputs already in utxo set");127case TransactionError::MEMPOOL_REJECTED:128return Untranslated("Transaction rejected by mempool");129case TransactionError::MEMPOOL_ERROR:130return Untranslated("Mempool internal error");131case TransactionError::MAX_FEE_EXCEEDED:132return Untranslated("Fee exceeds maximum configured by user (e.g. -maxtxfee, maxfeerate)");133case TransactionError::MAX_BURN_EXCEEDED:134return Untranslated("Unspendable output exceeds maximum configured by user (maxburnamount)");135case TransactionError::INVALID_PACKAGE:136return Untranslated("Transaction rejected due to invalid package");137case TransactionError::PRIVATE_BROADCAST_FULL:138return Untranslated("Private broadcast queue is full");139} // no default case, so the compiler can warn about missing cases140assert(false);141}143bilingual_str ResolveErrMsg(const std::string& optname, const std::string& strBind)144{145return strprintf(_("Cannot resolve -%s address: '%s'"), optname, strBind);146}148bilingual_str InvalidPortErrMsg(const std::string& optname, const std::string& invalid_value)149{150return strprintf(_("Invalid port specified in %s: '%s'"), optname, invalid_value);151}153bilingual_str AmountHighWarn(const std::string& optname)154{155return strprintf(_("%s is set very high!"), optname);156}158bilingual_str AmountErrMsg(const std::string& optname, const std::string& strValue)159{160return strprintf(_("Invalid amount for -%s=<amount>: '%s'"), optname, strValue);161}162} // namespace common
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.