Skip to content
Bitcoin Roots

v30.3-roots.1 · Commit 28: [PATCH 28/68] fix(wallet): secure asynchronous sweep cancellation

src/wallet/interfaces.cpp

Before: src/wallet/interfaces.cpp · After: src/wallet/interfaces.cpp

File metadata
index b1daafb60b88755b329a528532ccc1b58731f907..b8384d8800448ae00448a7c462c62a75737bc54a 100644

Download original patch · Release notes

Diff rows 1–29 of 29. 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/interfaces.cpp CHANGED
@@ -216,9 +216,11 @@ public:
216
  util::Result<WalletSweepResult> sweepPrivateKey(const SecureString& private_key,
217
  const CTxDestination& destination,
218
  bool broadcast,
219
- const std::optional<Txid>& expected_txid) override
 
220
  {
221
- CKey key{DecodeSecret(std::string{private_key.begin(), private_key.end()})};
 
222
  if (!key.IsValid()) return util::Error{Untranslated("Invalid private key or wrong network")};
223
  const CPubKey pubkey{key.GetPubKey()};
224
  FlatSigningProvider provider;
@@ -239,7 +241,7 @@ public:
239
  }
240
  }
241
  std::map<COutPoint, Coin> coins;
242
- switch (m_wallet->chain().findScriptPubKeys(scan_objects, coins)) {
243
  case interfaces::ScanResult::SUCCESS: break;
244
  case interfaces::ScanResult::BUSY: return util::Error{Untranslated("UTXO scan already in progress")};
245
  case interfaces::ScanResult::ABORTED: return util::Error{Untranslated("UTXO scan aborted")};
@@ -251,7 +253,7 @@ public:
251
  return false;
252
  }
253
  return m_wallet->chain().broadcastTransaction(tx, m_wallet->m_default_max_tx_fee, /*relay=*/true, error);
254
- }} : SweepBroadcastFn{})};
255
  if (!swept) return util::Error{util::ErrorString(swept)};
256
  return WalletSweepResult{swept->tx, swept->amount, swept->fee, coins.size(), GetVirtualTransactionSize(*swept->tx), broadcast};
257
  }
 
216
  util::Result<WalletSweepResult> sweepPrivateKey(const SecureString& private_key,
217
  const CTxDestination& destination,
218
  bool broadcast,
219
+ const std::optional<Txid>& expected_txid,
220
+ const std::shared_ptr<interfaces::SweepAuthorization>& authorization) override
221
  {
222
+ if (!authorization || authorization->IsCancelled()) return util::Error{Untranslated("Sweep cancelled")};
223
+ CKey key{DecodeSecret(private_key)};
224
  if (!key.IsValid()) return util::Error{Untranslated("Invalid private key or wrong network")};
225
  const CPubKey pubkey{key.GetPubKey()};
226
  FlatSigningProvider provider;
 
241
  }
242
  }
243
  std::map<COutPoint, Coin> coins;
244
+ switch (m_wallet->chain().findScriptPubKeys(scan_objects, coins, [&] { return authorization->IsCancelled(); })) {
245
  case interfaces::ScanResult::SUCCESS: break;
246
  case interfaces::ScanResult::BUSY: return util::Error{Untranslated("UTXO scan already in progress")};
247
  case interfaces::ScanResult::ABORTED: return util::Error{Untranslated("UTXO scan aborted")};
 
253
  return false;
254
  }
255
  return m_wallet->chain().broadcastTransaction(tx, m_wallet->m_default_max_tx_fee, /*relay=*/true, error);
256
+ }} : SweepBroadcastFn{}, *authorization)};
257
  if (!swept) return util::Error{util::ErrorString(swept)};
258
  return WalletSweepResult{swept->tx, swept->amount, swept->fee, coins.size(), GetVirtualTransactionSize(*swept->tx), broadcast};
259
  }