wallet, rpc: Move (Un)LockCoin WalletBatch creation out of RPC

If the locked coin needs to be persisted to the wallet database,
insteead of having the RPC figure out when to create a WalletBatch and
having LockCoin's behavior depend on it, have LockCoin take whether to
persist as a parameter so it makes the batch.

Since unlocking a persisted locked coin requires a database write as
well, we need to track whether the locked coin was persisted to the
wallet database so that it can erase the locked coin when necessary.

Keeping track of whether a locked coin was persisted is also useful
information for future PRs.
This commit is contained in:
Ava Chow committed 2025-06-02 13:14:19 -07:00
1 parent 2df824f4e6
commit 6135e0553e
8 files changed
+49 -47

No files matched your search

+2 -4
View File
@@ -249,14 +249,12 @@ public:
bool lockCoin(const COutPoint& output, const bool write_to_db) override
{
LOCK(m_wallet->cs_wallet);
std::unique_ptr<WalletBatch> batch = write_to_db ? std::make_unique<WalletBatch>(m_wallet->GetDatabase()) : nullptr;
return m_wallet->LockCoin(output, batch.get());
return m_wallet->LockCoin(output, write_to_db);
}
bool unlockCoin(const COutPoint& output) override
{
LOCK(m_wallet->cs_wallet);
std::unique_ptr<WalletBatch> batch = std::make_unique<WalletBatch>(m_wallet->GetDatabase());
return m_wallet->UnlockCoin(output, batch.get());
return m_wallet->UnlockCoin(output);
}
bool isLockedCoin(const COutPoint& output) override
{