v29.4-roots.4 · Commit 28: [PATCH 28/37] fix(wallet): secure asynchronous sweep cancellation
src/wallet/rpc/spend.cpp
Before: src/wallet/rpc/spend.cpp · After: src/wallet/rpc/spend.cpp
File metadata
index a20946e2b434d26aa228846d364e25aaa9bb22ee..bcdfb41efc83770cb8d57cde508b3b15d61b5819 100644
Download original patch · Release notes
Diff rows 1–18 of 18. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
src/wallet/rpc/spend.cpp
CHANGED
|
@@ -5,6 +5,7 @@
|
|
| 5 |
#include <common/messages.h>
|
| 6 |
#include <consensus/validation.h>
|
| 7 |
#include <core_io.h>
|
|
|
|
| 8 |
#include <key_io.h>
|
| 9 |
#include <node/types.h>
|
| 10 |
#include <policy/policy.h>
|
|
@@ -99,9 +100,10 @@ RPCHelpMan sweepprivkeys()
|
|
| 99 |
case interfaces::ScanResult::UNAVAILABLE: throw JSONRPCError(RPC_MISC_ERROR, "UTXO scan unavailable");
|
| 100 |
}
|
| 101 |
const bool broadcast{!request.params[2].isNull() && request.params[2].get_bool()};
|
|
|
|
| 102 |
auto swept{CreateSweepTransaction(*pwallet, provider, coins, destination_script, broadcast ? SweepBroadcastFn{[&](const CTransactionRef& tx, std::string& error) {
|
| 103 |
return pwallet->chain().broadcastTransaction(tx, pwallet->m_default_max_tx_fee, /*relay=*/true, error);
|
| 104 |
-
}} : SweepBroadcastFn{})};
|
| 105 |
if (!swept) {
|
| 106 |
const std::string error{util::ErrorString(swept).original};
|
| 107 |
const int code{error == "No spendable UTXOs found" || error == "Fee exceeds swept value" ? RPC_WALLET_INSUFFICIENT_FUNDS :
|
|
|
|
| 5 |
#include <common/messages.h>
|
| 6 |
#include <consensus/validation.h>
|
| 7 |
#include <core_io.h>
|
| 8 |
+
#include <interfaces/wallet.h>
|
| 9 |
#include <key_io.h>
|
| 10 |
#include <node/types.h>
|
| 11 |
#include <policy/policy.h>
|
|
|
|
| 100 |
case interfaces::ScanResult::UNAVAILABLE: throw JSONRPCError(RPC_MISC_ERROR, "UTXO scan unavailable");
|
| 101 |
}
|
| 102 |
const bool broadcast{!request.params[2].isNull() && request.params[2].get_bool()};
|
| 103 |
+
interfaces::SweepAuthorization authorization;
|
| 104 |
auto swept{CreateSweepTransaction(*pwallet, provider, coins, destination_script, broadcast ? SweepBroadcastFn{[&](const CTransactionRef& tx, std::string& error) {
|
| 105 |
return pwallet->chain().broadcastTransaction(tx, pwallet->m_default_max_tx_fee, /*relay=*/true, error);
|
| 106 |
+
}} : SweepBroadcastFn{}, authorization)};
|
| 107 |
if (!swept) {
|
| 108 |
const std::string error{util::ErrorString(swept).original};
|
| 109 |
const int code{error == "No spendable UTXOs found" || error == "Fee exceeds swept value" ? RPC_WALLET_INSUFFICIENT_FUNDS :
|