aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.cpp
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@exmulti.com>2012-09-27 13:52:09 -0400
committerJeff Garzik <jgarzik@redhat.com>2012-11-15 21:11:30 -0500
commitfdbb537d263497529c8f9deb0bb98371530839c3 (patch)
treea18245d2f8858efde12448d67c3db2c63d175f1a /src/wallet.cpp
parent6caffb5358b1e403b293846b3c832433fa928e46 (diff)
Add new RPC "lockunspent", to prevent spending of selected outputs
and associated RPC "listlockunspent". This is a memory-only filter, which is empty when a node restarts.
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r--src/wallet.cpp38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 0115e56b8e..af3612d435 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -953,9 +953,11 @@ void CWallet::AvailableCoins(vector<COutput>& vCoins, bool fOnlyConfirmed) const
if (pcoin->IsCoinBase() && pcoin->GetBlocksToMaturity() > 0)
continue;
- for (unsigned int i = 0; i < pcoin->vout.size(); i++)
- if (!(pcoin->IsSpent(i)) && IsMine(pcoin->vout[i]) && pcoin->vout[i].nValue > 0)
+ for (unsigned int i = 0; i < pcoin->vout.size(); i++) {
+ if (!(pcoin->IsSpent(i)) && IsMine(pcoin->vout[i]) &&
+ !IsLockedCoin((*it).first, i) && pcoin->vout[i].nValue > 0)
vCoins.push_back(COutput(pcoin, i, pcoin->GetDepthInMainChain()));
+ }
}
}
}
@@ -1766,3 +1768,35 @@ void CWallet::UpdatedTransaction(const uint256 &hashTx)
NotifyTransactionChanged(this, hashTx, CT_UPDATED);
}
}
+
+void CWallet::LockCoin(COutPoint& output)
+{
+ setLockedCoins.insert(output);
+}
+
+void CWallet::UnlockCoin(COutPoint& output)
+{
+ setLockedCoins.erase(output);
+}
+
+void CWallet::UnlockAllCoins()
+{
+ setLockedCoins.clear();
+}
+
+bool CWallet::IsLockedCoin(uint256 hash, unsigned int n) const
+{
+ COutPoint outpt(hash, n);
+
+ return (setLockedCoins.count(outpt) > 0);
+}
+
+void CWallet::ListLockedCoins(std::vector<COutPoint>& vOutpts)
+{
+ for (std::set<COutPoint>::iterator it = setLockedCoins.begin();
+ it != setLockedCoins.end(); it++) {
+ COutPoint outpt = (*it);
+ vOutpts.push_back(outpt);
+ }
+}
+