From 449b730579566459e350703611629e63e54657ed Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Tue, 10 Nov 2020 12:29:01 +0100 Subject: wallet: provide valid values if invalid estimate mode passed Co-authored-by: Murch --- src/rpc/mining.cpp | 2 +- src/util/fees.cpp | 5 +++++ src/util/fees.h | 1 + src/wallet/rpcwallet.cpp | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index a561b7e93c..6522c0d73e 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -1070,7 +1070,7 @@ static RPCHelpMan estimatesmartfee() if (!request.params[1].isNull()) { FeeEstimateMode fee_mode; if (!FeeModeFromString(request.params[1].get_str(), fee_mode)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter"); + throw JSONRPCError(RPC_INVALID_PARAMETER, InvalidEstimateModeErrorMessage()); } if (fee_mode == FeeEstimateMode::ECONOMICAL) conservative = false; } diff --git a/src/util/fees.cpp b/src/util/fees.cpp index 9a1cea1d4e..1855c0bc90 100644 --- a/src/util/fees.cpp +++ b/src/util/fees.cpp @@ -49,6 +49,11 @@ std::string FeeModes(const std::string& delimiter) return Join(FeeModeMap(), delimiter, [&](const std::pair& i) { return i.first; }); } +const std::string InvalidEstimateModeErrorMessage() +{ + return "Invalid estimate_mode parameter, must be one of: \"" + FeeModes("\", \"") + "\""; +} + bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode) { auto searchkey = ToUpper(mode_string); diff --git a/src/util/fees.h b/src/util/fees.h index d52046a44c..3f1c33ad9c 100644 --- a/src/util/fees.h +++ b/src/util/fees.h @@ -13,5 +13,6 @@ enum class FeeReason; bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode); std::string StringForFeeReason(FeeReason reason); std::string FeeModes(const std::string& delimiter); +const std::string InvalidEstimateModeErrorMessage(); #endif // BITCOIN_UTIL_FEES_H diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1725bba712..45451db96d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -221,7 +221,7 @@ static void SetFeeEstimateMode(const CWallet* pwallet, CCoinControl& cc, const U return; } if (!estimate_mode.isNull() && !FeeModeFromString(estimate_mode.get_str(), cc.m_fee_mode)) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter"); + throw JSONRPCError(RPC_INVALID_PARAMETER, InvalidEstimateModeErrorMessage()); } if (!conf_target.isNull()) { cc.m_confirm_target = ParseConfirmTarget(conf_target, pwallet->chain().estimateMaxBlocks()); -- cgit v1.2.3