| 371 | } |
| 372 | |
| 373 | RPCHelpMan settxfee() |
| 374 | { |
| 375 | return RPCHelpMan{"settxfee", |
| 376 | "\nSet the transaction fee rate in " + CURRENCY_UNIT + "/kvB for this wallet. Overrides the global -paytxfee command line parameter.\n" |
| 377 | "Can be deactivated by passing 0 as the fee. In that case automatic fee selection will be used by default.\n", |
| 378 | { |
| 379 | {"amount", RPCArg::Type::AMOUNT, RPCArg::Optional::NO, "The transaction fee rate in " + CURRENCY_UNIT + "/kvB"}, |
| 380 | }, |
| 381 | RPCResult{ |
| 382 | RPCResult::Type::BOOL, "", "Returns true if successful" |
| 383 | }, |
| 384 | RPCExamples{ |
| 385 | HelpExampleCli("settxfee", "0.00001") |
| 386 | + HelpExampleRpc("settxfee", "0.00001") |
| 387 | }, |
| 388 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 389 | { |
| 390 | std::shared_ptr<CWallet> const pwallet = GetWalletForJSONRPCRequest(request); |
| 391 | if (!pwallet) return NullUniValue; |
| 392 | |
| 393 | LOCK(pwallet->cs_wallet); |
| 394 | |
| 395 | CAmount nAmount = AmountFromValue(request.params[0]); |
| 396 | CFeeRate tx_fee_rate(nAmount, 1000); |
| 397 | CFeeRate max_tx_fee_rate(pwallet->m_default_max_tx_fee, 1000); |
| 398 | if (tx_fee_rate == CFeeRate(0)) { |
| 399 | // automatic selection |
| 400 | } else if (tx_fee_rate < pwallet->chain().relayMinFee()) { |
| 401 | throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be less than min relay tx fee (%s)", pwallet->chain().relayMinFee().ToString())); |
| 402 | } else if (tx_fee_rate < pwallet->m_min_fee) { |
| 403 | throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be less than wallet min fee (%s)", pwallet->m_min_fee.ToString())); |
| 404 | } else if (tx_fee_rate > max_tx_fee_rate) { |
| 405 | throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be more than wallet max tx fee (%s)", max_tx_fee_rate.ToString())); |
| 406 | } |
| 407 | |
| 408 | pwallet->m_pay_tx_fee = tx_fee_rate; |
| 409 | return true; |
| 410 | }, |
| 411 | }; |
| 412 | } |
| 413 | |
| 414 | |
| 415 | // Only includes key documentation where the key is snake_case in all RPC methods. MixedCase keys can be added later. |
nothing calls this directly
no test coverage detected