Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 2,967 Lines • ▼ Show 20 Lines | static UniValue lockunspent(const Config &config, | ||||
if (request.params.size() == 1) { | if (request.params.size() == 1) { | ||||
if (fUnlock) { | if (fUnlock) { | ||||
pwallet->UnlockAllCoins(); | pwallet->UnlockAllCoins(); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
UniValue outputs = request.params[1].get_array(); | const UniValue &output_params = request.params[1]; | ||||
for (size_t idx = 0; idx < outputs.size(); idx++) { | |||||
const UniValue &output = outputs[idx]; | // Create and validate the COutPoints first. | ||||
if (!output.isObject()) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | std::vector<COutPoint> outputs; | ||||
"Invalid parameter, expected object"); | outputs.reserve(output_params.size()); | ||||
} | |||||
const UniValue &o = output.get_obj(); | for (size_t idx = 0; idx < output_params.size(); idx++) { | ||||
deadalnix: As it turns out, Univalue's size is an unsigned int so size_t is not correct here. | |||||
FabienAuthorUnsubmitted Done Inline ActionsFrom univalue.h: class Univalue { public: [...] size_t size() const { return values.size(); } Unless I'm missing Univalue's size seems to be a size_t ? Fabien: From univalue.h:
```
class Univalue {
public:
[...]
size_t size() const { return values. | |||||
deadalnixUnsubmitted Not Done Inline Actionsok :) deadalnix: ok :) | |||||
const UniValue &o = output_params[idx].get_obj(); | |||||
RPCTypeCheckObj(o, { | RPCTypeCheckObj(o, { | ||||
{"txid", UniValueType(UniValue::VSTR)}, | {"txid", UniValueType(UniValue::VSTR)}, | ||||
{"vout", UniValueType(UniValue::VNUM)}, | {"vout", UniValueType(UniValue::VNUM)}, | ||||
}); | }); | ||||
std::string txid = find_value(o, "txid").get_str(); | const std::string &txid = find_value(o, "txid").get_str(); | ||||
if (!IsHex(txid)) { | if (!IsHex(txid)) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Invalid parameter, expected hex txid"); | "Invalid parameter, expected hex txid"); | ||||
} | } | ||||
int nOutput = find_value(o, "vout").get_int(); | const int nOutput = find_value(o, "vout").get_int(); | ||||
if (nOutput < 0) { | if (nOutput < 0) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Invalid parameter, vout must be positive"); | "Invalid parameter, vout must be positive"); | ||||
} | } | ||||
COutPoint outpt(uint256S(txid), nOutput); | const COutPoint outpt(uint256S(txid), nOutput); | ||||
const auto it = pwallet->mapWallet.find(outpt.GetTxId()); | |||||
if (it == pwallet->mapWallet.end()) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
"Invalid parameter, unknown transaction"); | |||||
} | |||||
const CWalletTx &trans = it->second; | |||||
if (outpt.GetN() >= trans.tx->vout.size()) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
"Invalid parameter, vout index out of bounds"); | |||||
} | |||||
if (pwallet->IsSpent(outpt.GetTxId(), outpt.GetN())) { | |||||
deadalnixUnsubmitted Not Done Inline ActionsLooks like IsSpent should take an outpoint, but what do I know... It's out of scope anyways. deadalnix: Looks like IsSpent should take an outpoint, but what do I know...
It's out of scope anyways. | |||||
FabienAuthorUnsubmitted Done Inline ActionsAgreed, and it's not the only function (see IsLockedCoin). I noticed it and added to my todo-list, if the impact is not crazy I'll submit a follow up refactor anytime soon. Fabien: Agreed, and it's not the only function (see `IsLockedCoin`). I noticed it and added to my todo… | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
"Invalid parameter, expected unspent output"); | |||||
} | |||||
const bool is_locked = | |||||
pwallet->IsLockedCoin(outpt.GetTxId(), outpt.GetN()); | |||||
if (fUnlock && !is_locked) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
"Invalid parameter, expected locked output"); | |||||
} | |||||
if (!fUnlock && is_locked) { | |||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | |||||
"Invalid parameter, output already locked"); | |||||
} | |||||
outputs.push_back(outpt); | |||||
} | |||||
// Atomically set (un)locked status for the outputs. | |||||
for (const COutPoint &outpt : outputs) { | |||||
if (fUnlock) { | if (fUnlock) { | ||||
pwallet->UnlockCoin(outpt); | pwallet->UnlockCoin(outpt); | ||||
} else { | } else { | ||||
pwallet->LockCoin(outpt); | pwallet->LockCoin(outpt); | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 1,227 Lines • Show Last 20 Lines |
As it turns out, Univalue's size is an unsigned int so size_t is not correct here.