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