Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcwallet.cpp
Show First 20 Lines • Show All 3,005 Lines • ▼ Show 20 Lines | static UniValue lockunspent(const Config &config, | ||||
for (size_t idx = 0; idx < output_params.size(); idx++) { | for (size_t idx = 0; idx < output_params.size(); idx++) { | ||||
const UniValue &o = output_params[idx].get_obj(); | 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)}, | ||||
}); | }); | ||||
const std::string &txid = find_value(o, "txid").get_str(); | const std::string &strTxId = find_value(o, "txid").get_str(); | ||||
if (!IsHex(txid)) { | if (!IsHex(strTxId)) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Invalid parameter, expected hex txid"); | "Invalid parameter, expected hex txid"); | ||||
} | } | ||||
const 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"); | ||||
} | } | ||||
const COutPoint output(uint256S(txid), nOutput); | const TxId txid(uint256S(strTxId)); | ||||
const auto it = pwallet->mapWallet.find(txid); | |||||
const auto it = pwallet->mapWallet.find(output.GetTxId()); | |||||
if (it == pwallet->mapWallet.end()) { | if (it == pwallet->mapWallet.end()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Invalid parameter, unknown transaction"); | "Invalid parameter, unknown transaction"); | ||||
} | } | ||||
const COutPoint output(txid, nOutput); | |||||
const CWalletTx &trans = it->second; | const CWalletTx &trans = it->second; | ||||
if (output.GetN() >= trans.tx->vout.size()) { | if (output.GetN() >= trans.tx->vout.size()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Invalid parameter, vout index out of bounds"); | "Invalid parameter, vout index out of bounds"); | ||||
} | } | ||||
if (pwallet->IsSpent(output)) { | if (pwallet->IsSpent(output)) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Invalid parameter, expected unspent output"); | "Invalid parameter, expected unspent output"); | ||||
} | } | ||||
const bool is_locked = pwallet->IsLockedCoin(output); | const bool is_locked = pwallet->IsLockedCoin(output); | ||||
if (fUnlock && !is_locked) { | if (fUnlock && !is_locked) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Invalid parameter, expected locked output"); | "Invalid parameter, expected locked output"); | ||||
} | } | ||||
if (!fUnlock && is_locked) { | if (!fUnlock && is_locked) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Invalid parameter, output already locked"); | "Invalid parameter, output already locked"); | ||||
▲ Show 20 Lines • Show All 1,244 Lines • Show Last 20 Lines |