| 292 | } |
| 293 | |
| 294 | RPCHelpMan lockunspent() |
| 295 | { |
| 296 | return RPCHelpMan{"lockunspent", |
| 297 | "\nUpdates list of temporarily unspendable outputs.\n" |
| 298 | "Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n" |
| 299 | "If no transaction outputs are specified when unlocking then all current locked transaction outputs are unlocked.\n" |
| 300 | "A locked transaction output will not be chosen by automatic coin selection, when spending bitcoins.\n" |
| 301 | "Manually selected coins are automatically unlocked.\n" |
| 302 | "Locks are stored in memory only, unless persistent=true, in which case they will be written to the\n" |
| 303 | "wallet database and loaded on node start. Unwritten (persistent=false) locks are always cleared\n" |
| 304 | "(by virtue of process exit) when a node stops or fails. Unlocking will clear both persistent and not.\n" |
| 305 | "Also see the listunspent call\n", |
| 306 | { |
| 307 | {"unlock", RPCArg::Type::BOOL, RPCArg::Optional::NO, "Whether to unlock (true) or lock (false) the specified transactions"}, |
| 308 | {"transactions", RPCArg::Type::ARR, RPCArg::Default{UniValue::VARR}, "The transaction outputs and within each, the txid (string) vout (numeric).", |
| 309 | { |
| 310 | {"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "", |
| 311 | { |
| 312 | {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id"}, |
| 313 | {"vout", RPCArg::Type::NUM, RPCArg::Optional::NO, "The output number"}, |
| 314 | }, |
| 315 | }, |
| 316 | }, |
| 317 | }, |
| 318 | {"persistent", RPCArg::Type::BOOL, RPCArg::Default{false}, "Whether to write/erase this lock in the wallet database, or keep the change in memory only. Ignored for unlocking."}, |
| 319 | }, |
| 320 | RPCResult{ |
| 321 | RPCResult::Type::BOOL, "", "Whether the command was successful or not" |
| 322 | }, |
| 323 | RPCExamples{ |
| 324 | "\nList the unspent transactions\n" |
| 325 | + HelpExampleCli("listunspent", "") + |
| 326 | "\nLock an unspent transaction\n" |
| 327 | + HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") + |
| 328 | "\nList the locked transactions\n" |
| 329 | + HelpExampleCli("listlockunspent", "") + |
| 330 | "\nUnlock the transaction again\n" |
| 331 | + HelpExampleCli("lockunspent", "true \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") + |
| 332 | "\nLock the transaction persistently in the wallet database\n" |
| 333 | + HelpExampleCli("lockunspent", "false \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\" true") + |
| 334 | "\nAs a JSON-RPC call\n" |
| 335 | + HelpExampleRpc("lockunspent", "false, \"[{\\\"txid\\\":\\\"a08e6907dbbd3d809776dbfc5d82e371b764ed838b5655e72f463568df1aadf0\\\",\\\"vout\\\":1}]\"") |
| 336 | }, |
| 337 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 338 | { |
| 339 | std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request); |
| 340 | if (!pwallet) return NullUniValue; |
| 341 | |
| 342 | // Make sure the results are valid at least up to the most recent block |
| 343 | // the user could have gotten from another RPC command prior to now |
| 344 | pwallet->BlockUntilSyncedToCurrentChain(); |
| 345 | |
| 346 | LOCK(pwallet->cs_wallet); |
| 347 | |
| 348 | RPCTypeCheckArgument(request.params[0], UniValue::VBOOL); |
| 349 | |
| 350 | bool fUnlock = request.params[0].get_bool(); |
| 351 |
nothing calls this directly
no test coverage detected