mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Merge #11050: Avoid treating null RPC arguments different from missing arguments
745d2e3Clean up getbalance RPC parameter handling (Russell Yanofsky)fd5d71eUpdate developer notes after params.size() cleanup (Russell Yanofsky)e067673Avoid treating null RPC arguments different from missing arguments (Russell Yanofsky)e666efcGet rid of redundant RPC params.size() checks (Russell Yanofsky) Pull request description: This is a followup to #10783. - The first commit doesn't change behavior at all, just simplifies code. - The second commit just changes RPC methods to treat null arguments the same as missing arguments instead of throwing type errors. - The third commit updates developer notes after the cleanup. - The forth commit does some additional code cleanup in `getbalance`. Followup changes that should happen in future PRs: - [ ] Replace uses of `.isTrue()` with calls to `.get_bool()` so numbers, objects, and strings cause type errors instead of being interpreted as false. https://github.com/bitcoin/bitcoin/pull/11050#discussion_r133850525 - [ ] Add braces around if statements. https://github.com/bitcoin/bitcoin/pull/11050#discussion_r133851133 - [ ] Maybe improve UniValue type error exceptions and eliminate RPCTypeCheck and RPCTypeCheckArgument functions. https://github.com/bitcoin/bitcoin/pull/11050#discussion_r133829303 Tree-SHA512: e72f696011d20acc0778e996659e41f9426bffce387b29ff63bf59ad1163d5146761e4445b2b9b9e069a80596a57c7f4402b75a15d5d20f69f775ae558cf67e9
This commit is contained in:
@@ -336,14 +336,14 @@ UniValue createrawtransaction(const JSONRPCRequest& request)
|
||||
|
||||
CMutableTransaction rawTx;
|
||||
|
||||
if (request.params.size() > 2 && !request.params[2].isNull()) {
|
||||
if (!request.params[2].isNull()) {
|
||||
int64_t nLockTime = request.params[2].get_int64();
|
||||
if (nLockTime < 0 || nLockTime > std::numeric_limits<uint32_t>::max())
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, locktime out of range");
|
||||
rawTx.nLockTime = nLockTime;
|
||||
}
|
||||
|
||||
bool rbfOptIn = request.params.size() > 3 ? request.params[3].isTrue() : false;
|
||||
bool rbfOptIn = request.params[3].isTrue();
|
||||
|
||||
for (unsigned int idx = 0; idx < inputs.size(); idx++) {
|
||||
const UniValue& input = inputs[idx];
|
||||
@@ -732,7 +732,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
|
||||
|
||||
bool fGivenKeys = false;
|
||||
CBasicKeyStore tempKeystore;
|
||||
if (request.params.size() > 2 && !request.params[2].isNull()) {
|
||||
if (!request.params[2].isNull()) {
|
||||
fGivenKeys = true;
|
||||
UniValue keys = request.params[2].get_array();
|
||||
for (unsigned int idx = 0; idx < keys.size(); idx++) {
|
||||
@@ -754,7 +754,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
|
||||
#endif
|
||||
|
||||
// Add previous txouts given in the RPC call:
|
||||
if (request.params.size() > 1 && !request.params[1].isNull()) {
|
||||
if (!request.params[1].isNull()) {
|
||||
UniValue prevTxs = request.params[1].get_array();
|
||||
for (unsigned int idx = 0; idx < prevTxs.size(); idx++) {
|
||||
const UniValue& p = prevTxs[idx];
|
||||
@@ -825,7 +825,7 @@ UniValue signrawtransaction(const JSONRPCRequest& request)
|
||||
#endif
|
||||
|
||||
int nHashType = SIGHASH_ALL;
|
||||
if (request.params.size() > 3 && !request.params[3].isNull()) {
|
||||
if (!request.params[3].isNull()) {
|
||||
static std::map<std::string, int> mapSigHashValues = {
|
||||
{std::string("ALL"), int(SIGHASH_ALL)},
|
||||
{std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)},
|
||||
@@ -919,7 +919,7 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
|
||||
const uint256& hashTx = tx->GetHash();
|
||||
|
||||
CAmount nMaxRawTxFee = maxTxFee;
|
||||
if (request.params.size() > 1 && request.params[1].get_bool())
|
||||
if (!request.params[1].isNull() && request.params[1].get_bool())
|
||||
nMaxRawTxFee = 0;
|
||||
|
||||
CCoinsViewCache &view = *pcoinsTip;
|
||||
|
||||
Reference in New Issue
Block a user