From bd730cb92780d4aa3712e6bef84b07b93d30b593 Mon Sep 17 00:00:00 2001 From: Duke Date: Sun, 18 May 2025 14:47:43 -0400 Subject: [PATCH] Lock zins inside z_sendmany async operation --- src/wallet/asyncrpcoperation_sendmany.cpp | 46 +++++++++++++++++++++++ src/wallet/asyncrpcoperation_sendmany.h | 5 +++ 2 files changed, 51 insertions(+) diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index 311fc217c..f46a458dd 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -119,6 +119,11 @@ AsyncRPCOperation_sendmany::AsyncRPCOperation_sendmany( } else { LogPrint("zrpc", "%s: z_sendmany initialized\n", getId()); } + + // Lock UTXOs + //lock_utxos(); + // Lock shielded input notes + lock_notes(); } AsyncRPCOperation_sendmany::~AsyncRPCOperation_sendmany() { @@ -185,6 +190,9 @@ void AsyncRPCOperation_sendmany::main() { s += strprintf(", error=%s)\n", getErrorMessage()); } LogPrintf("%s",s); + + //unlock_utxos(); // clean up + unlock_notes(); // clean up } // Notes: @@ -781,3 +789,41 @@ UniValue AsyncRPCOperation_sendmany::getStatus() const { obj.push_back(Pair("params", contextinfo_ )); return obj; } + +/* TODO: support locking taddr utxo inputs + +// Lock input utxos + void AsyncRPCOperation_sendmany::lock_utxos() { + LOCK2(cs_main, pwalletMain->cs_wallet); + for (auto utxo : t_inputs_) { + COutPoint outpt(utxo.txid, utxo.vout); + pwalletMain->LockCoin(outpt); + } +} + +// Unlock input utxos +void AsyncRPCOperation_sendmany::unlock_utxos() { + LOCK2(cs_main, pwalletMain->cs_wallet); + for (auto utxo : t_inputs_) { + COutPoint outpt(utxo.txid, utxo.vout); + pwalletMain->UnlockCoin(outpt); + } +} + +*/ + +// Lock input notes +void AsyncRPCOperation_sendmany::lock_notes() { + LOCK2(cs_main, pwalletMain->cs_wallet); + for (auto note : z_sapling_inputs_) { + pwalletMain->LockNote(note.op); + } +} + +// Unlock input notes +void AsyncRPCOperation_sendmany::unlock_notes() { + LOCK2(cs_main, pwalletMain->cs_wallet); + for (auto note : z_sapling_inputs_) { + pwalletMain->UnlockNote(note.op); + } +} diff --git a/src/wallet/asyncrpcoperation_sendmany.h b/src/wallet/asyncrpcoperation_sendmany.h index f71c6d2e2..8684cf97c 100644 --- a/src/wallet/asyncrpcoperation_sendmany.h +++ b/src/wallet/asyncrpcoperation_sendmany.h @@ -112,6 +112,11 @@ private: bool main_impl(); void sign_send_raw_transaction(UniValue obj); // throws exception if there was an error + + void lock_utxos(); + void unlock_utxos(); + void lock_notes(); + void unlock_notes(); };