Skip to content
Bitcoin Roots

v30.3-roots.1 · Commit 28: [PATCH 28/68] 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 92778e1f7b3f666a99ea374f90b303a46cce0450..70a5f38f3486683e2ace285a602c30ed2adedbd3 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>
@@ -100,9 +101,10 @@ RPCHelpMan sweepprivkeys()
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
  auto swept{CreateSweepTransaction(*pwallet, provider, coins, destination_script, broadcast ? SweepBroadcastFn{[&](const CTransactionRef& tx, std::string& error) {
104
  return pwallet->chain().broadcastTransaction(tx, pwallet->m_default_max_tx_fee, /*relay=*/true, error);
105
- }} : SweepBroadcastFn{})};
106
  if (!swept) {
107
  const std::string error{util::ErrorString(swept).original};
108
  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>
 
101
  case interfaces::ScanResult::UNAVAILABLE: throw JSONRPCError(RPC_MISC_ERROR, "UTXO scan unavailable");
102
  }
103
  const bool broadcast{!request.params[2].isNull() && request.params[2].get_bool()};
104
+ interfaces::SweepAuthorization authorization;
105
  auto swept{CreateSweepTransaction(*pwallet, provider, coins, destination_script, broadcast ? SweepBroadcastFn{[&](const CTransactionRef& tx, std::string& error) {
106
  return pwallet->chain().broadcastTransaction(tx, pwallet->m_default_max_tx_fee, /*relay=*/true, error);
107
+ }} : SweepBroadcastFn{}, authorization)};
108
  if (!swept) {
109
  const std::string error{util::ErrorString(swept).original};
110
  const int code{error == "No spendable UTXOs found" || error == "Fee exceeds swept value" ? RPC_WALLET_INSUFFICIENT_FUNDS :