mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
refactor: Add sanity checks in LabelFromValue
This commit is contained in:
parent
67e7ba8e1a
commit
552b51e682
4 changed files with 15 additions and 23 deletions
|
@ -43,9 +43,7 @@ RPCHelpMan getnewaddress()
|
|||
}
|
||||
|
||||
// Parse the label first so we don't generate a key if there's an error
|
||||
std::string label;
|
||||
if (!request.params[0].isNull())
|
||||
label = LabelFromValue(request.params[0]);
|
||||
const std::string label{LabelFromValue(request.params[0])};
|
||||
|
||||
OutputType output_type = pwallet->m_default_address_type;
|
||||
if (!request.params[1].isNull()) {
|
||||
|
@ -140,7 +138,7 @@ RPCHelpMan setlabel()
|
|||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
||||
}
|
||||
|
||||
std::string label = LabelFromValue(request.params[1]);
|
||||
const std::string label{LabelFromValue(request.params[1])};
|
||||
|
||||
if (pwallet->IsMine(dest)) {
|
||||
pwallet->SetAddressBook(dest, label, "receive");
|
||||
|
@ -258,9 +256,7 @@ RPCHelpMan addmultisigaddress()
|
|||
|
||||
LOCK2(pwallet->cs_wallet, spk_man.cs_KeyStore);
|
||||
|
||||
std::string label;
|
||||
if (!request.params[2].isNull())
|
||||
label = LabelFromValue(request.params[2]);
|
||||
const std::string label{LabelFromValue(request.params[2])};
|
||||
|
||||
int required = request.params[0].getInt<int>();
|
||||
|
||||
|
@ -662,7 +658,7 @@ RPCHelpMan getaddressesbylabel()
|
|||
|
||||
LOCK(pwallet->cs_wallet);
|
||||
|
||||
std::string label = LabelFromValue(request.params[0]);
|
||||
const std::string label{LabelFromValue(request.params[0])};
|
||||
|
||||
// Find all addresses that have the given label
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
|
|
|
@ -140,9 +140,7 @@ RPCHelpMan importprivkey()
|
|||
EnsureWalletIsUnlocked(*pwallet);
|
||||
|
||||
std::string strSecret = request.params[0].get_str();
|
||||
std::string strLabel;
|
||||
if (!request.params[1].isNull())
|
||||
strLabel = LabelFromValue(request.params[1]);
|
||||
const std::string strLabel{LabelFromValue(request.params[1])};
|
||||
|
||||
// Whether to perform rescan after import
|
||||
if (!request.params[2].isNull())
|
||||
|
@ -233,9 +231,7 @@ RPCHelpMan importaddress()
|
|||
|
||||
EnsureLegacyScriptPubKeyMan(*pwallet, true);
|
||||
|
||||
std::string strLabel;
|
||||
if (!request.params[1].isNull())
|
||||
strLabel = LabelFromValue(request.params[1]);
|
||||
const std::string strLabel{LabelFromValue(request.params[1])};
|
||||
|
||||
// Whether to perform rescan after import
|
||||
bool fRescan = true;
|
||||
|
@ -426,9 +422,7 @@ RPCHelpMan importpubkey()
|
|||
|
||||
EnsureLegacyScriptPubKeyMan(*pwallet, true);
|
||||
|
||||
std::string strLabel;
|
||||
if (!request.params[1].isNull())
|
||||
strLabel = LabelFromValue(request.params[1]);
|
||||
const std::string strLabel{LabelFromValue(request.params[1])};
|
||||
|
||||
// Whether to perform rescan after import
|
||||
bool fRescan = true;
|
||||
|
@ -1163,7 +1157,7 @@ static UniValue ProcessImport(CWallet& wallet, const UniValue& data, const int64
|
|||
if (internal && data.exists("label")) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Internal addresses should not have a label");
|
||||
}
|
||||
const std::string& label = data.exists("label") ? LabelFromValue(data["label"]) : "";
|
||||
const std::string label{LabelFromValue(data["label"])};
|
||||
const bool add_keypool = data.exists("keypool") ? data["keypool"].get_bool() : false;
|
||||
|
||||
// Add to keypool only works with privkeys disabled
|
||||
|
@ -1457,7 +1451,7 @@ static UniValue ProcessDescriptorImport(CWallet& wallet, const UniValue& data, c
|
|||
const std::string& descriptor = data["desc"].get_str();
|
||||
const bool active = data.exists("active") ? data["active"].get_bool() : false;
|
||||
const bool internal = data.exists("internal") ? data["internal"].get_bool() : false;
|
||||
const std::string& label = data.exists("label") ? LabelFromValue(data["label"]) : "";
|
||||
const std::string label{LabelFromValue(data["label"])};
|
||||
|
||||
// Parse descriptor string
|
||||
FlatSigningProvider keys;
|
||||
|
|
|
@ -635,10 +635,9 @@ RPCHelpMan listsinceblock()
|
|||
bool include_removed = (request.params[3].isNull() || request.params[3].get_bool());
|
||||
bool include_change = (!request.params[4].isNull() && request.params[4].get_bool());
|
||||
|
||||
// Only set it if 'label' was provided.
|
||||
std::optional<std::string> filter_label;
|
||||
if (!request.params[5].isNull()) {
|
||||
filter_label = LabelFromValue(request.params[5]);
|
||||
}
|
||||
if (!request.params[5].isNull()) filter_label.emplace(LabelFromValue(request.params[5]));
|
||||
|
||||
int depth = height ? wallet.GetLastBlockHeight() + 1 - *height : -1;
|
||||
|
||||
|
|
|
@ -132,7 +132,10 @@ const LegacyScriptPubKeyMan& EnsureConstLegacyScriptPubKeyMan(const CWallet& wal
|
|||
|
||||
std::string LabelFromValue(const UniValue& value)
|
||||
{
|
||||
std::string label = value.get_str();
|
||||
static const std::string empty_string;
|
||||
if (value.isNull()) return empty_string;
|
||||
|
||||
const std::string& label{value.get_str()};
|
||||
if (label == "*")
|
||||
throw JSONRPCError(RPC_WALLET_INVALID_LABEL_NAME, "Invalid label name");
|
||||
return label;
|
||||
|
|
Loading…
Add table
Reference in a new issue