v29.4-roots.3 · Commit 28: [PATCH 28/30] fix(wallet): secure asynchronous sweep cancellation
src/wallet/interfaces.cpp
Before: src/wallet/interfaces.cpp · After: src/wallet/interfaces.cpp
File metadata
index 8294d1a3cc1534031a41b2ef3332c300dec02f33..b6b22fe11ff25ba0f3a22a23ff91de0f004b24d8 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. The two line-number columns refer to before and after.
src/wallet/interfaces.cpp
CHANGED
|
@@ -217,9 +217,11 @@ public:
|
|
|
217
217
|
util::Result<WalletSweepResult> sweepPrivateKey(const SecureString& private_key,
|
|
218
218
|
const CTxDestination& destination,
|
|
219
219
|
bool broadcast,
|
|
220
|
-
const std::optional<uint256>& expected_txid) override
|
|
220
|
+
const std::optional<uint256>& expected_txid,
|
|
221
|
+
const std::shared_ptr<interfaces::SweepAuthorization>& authorization) override
|
|
221
222
|
{
|
|
222
|
-
CKey key{DecodeSecret(std::string{private_key.begin(), private_key.end()})};
|
|
223
|
+
if (!authorization || authorization->IsCancelled()) return util::Error{Untranslated("Sweep cancelled")};
|
|
224
|
+
CKey key{DecodeSecret(private_key)};
|
|
223
225
|
if (!key.IsValid()) return util::Error{Untranslated("Invalid private key or wrong network")};
|
|
224
226
|
const CPubKey pubkey{key.GetPubKey()};
|
|
225
227
|
FlatSigningProvider provider;
|
|
@@ -240,7 +242,7 @@ public:
|
|
|
240
242
|
}
|
|
241
243
|
}
|
|
242
244
|
std::map<COutPoint, Coin> coins;
|
|
243
|
-
switch (m_wallet->chain().findScriptPubKeys(scan_objects, coins)) {
|
|
245
|
+
switch (m_wallet->chain().findScriptPubKeys(scan_objects, coins, [&] { return authorization->IsCancelled(); })) {
|
|
244
246
|
case interfaces::ScanResult::SUCCESS: break;
|
|
245
247
|
case interfaces::ScanResult::BUSY: return util::Error{Untranslated("UTXO scan already in progress")};
|
|
246
248
|
case interfaces::ScanResult::ABORTED: return util::Error{Untranslated("UTXO scan aborted")};
|
|
@@ -252,7 +254,7 @@ public:
|
|
|
252
254
|
return false;
|
|
253
255
|
}
|
|
254
256
|
return m_wallet->chain().broadcastTransaction(tx, m_wallet->m_default_max_tx_fee, /*relay=*/true, error);
|
|
255
|
-
}} : SweepBroadcastFn{})};
|
|
257
|
+
}} : SweepBroadcastFn{}, *authorization)};
|
|
256
258
|
if (!swept) return util::Error{util::ErrorString(swept)};
|
|
257
259
|
return WalletSweepResult{swept->tx, swept->amount, swept->fee, coins.size(), GetVirtualTransactionSize(*swept->tx), broadcast};
|
|
258
260
|
}
|