| 82 | } |
| 83 | |
| 84 | RPCHelpMan getrawchangeaddress() |
| 85 | { |
| 86 | return RPCHelpMan{"getrawchangeaddress", |
| 87 | "\nReturns a new Bitcoin address, for receiving change.\n" |
| 88 | "This is for use with raw transactions, NOT normal use.\n", |
| 89 | { |
| 90 | {"address_type", RPCArg::Type::STR, RPCArg::DefaultHint{"set by -changetype"}, "The address type to use. Options are \"legacy\", \"p2sh-segwit\", \"bech32\", and \"bech32m\"."}, |
| 91 | }, |
| 92 | RPCResult{ |
| 93 | RPCResult::Type::STR, "address", "The address" |
| 94 | }, |
| 95 | RPCExamples{ |
| 96 | HelpExampleCli("getrawchangeaddress", "") |
| 97 | + HelpExampleRpc("getrawchangeaddress", "") |
| 98 | }, |
| 99 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 100 | { |
| 101 | std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request); |
| 102 | if (!pwallet) return NullUniValue; |
| 103 | |
| 104 | LOCK(pwallet->cs_wallet); |
| 105 | |
| 106 | if (!pwallet->CanGetAddresses(true)) { |
| 107 | throw JSONRPCError(RPC_WALLET_ERROR, "Error: This wallet has no available keys"); |
| 108 | } |
| 109 | |
| 110 | OutputType output_type = pwallet->m_default_change_type.value_or(pwallet->m_default_address_type); |
| 111 | bool force_blind = false; |
| 112 | if (!request.params[0].isNull()) { |
| 113 | std::optional<OutputType> parsed = ParseOutputType(request.params[0].get_str()); |
| 114 | if (!parsed) { |
| 115 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[0].get_str())); |
| 116 | } else if (parsed.value() == OutputType::BECH32M && pwallet->GetLegacyScriptPubKeyMan()) { |
| 117 | throw JSONRPCError(RPC_INVALID_PARAMETER, "Legacy wallets cannot provide bech32m addresses"); |
| 118 | } |
| 119 | // Special case for "blech32" when `-blindedaddresses=0` in the config. |
| 120 | if (request.params[0].get_str() == "blech32") { |
| 121 | force_blind = true; |
| 122 | } |
| 123 | output_type = parsed.value(); |
| 124 | } |
| 125 | |
| 126 | CTxDestination dest; |
| 127 | bilingual_str error; |
| 128 | bool add_blinding_key = force_blind || gArgs.GetBoolArg("-blindedaddresses", g_con_elementsmode); |
| 129 | if (!pwallet->GetNewChangeDestination(output_type, dest, error, add_blinding_key)) { |
| 130 | throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, error.original); |
| 131 | } |
| 132 | return EncodeDestination(dest); |
| 133 | }, |
| 134 | }; |
| 135 | } |
| 136 | |
| 137 | |
| 138 | RPCHelpMan setlabel() |
nothing calls this directly
no test coverage detected