diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2012-12-12 09:15:43 -0800 |
---|---|---|
committer | Gavin Andresen <gavinandresen@gmail.com> | 2012-12-12 09:15:43 -0800 |
commit | 78504bb04ffe77ac156aaa5f863424deaaa3ca0f (patch) | |
tree | 2c0349f4b97a5254e375743989f827b20a9a69bc /src/wallet.cpp | |
parent | 043a8fb98df03c458bb0b4c119418fd23b59f2bc (diff) | |
parent | fdbb537d263497529c8f9deb0bb98371530839c3 (diff) |
Merge pull request #1861 from jgarzik/coinlock
Add new RPC "lockunspent", to prevent spending of selected outputs
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r-- | src/wallet.cpp | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp index cedda9e9e0..c07adff6c6 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -957,9 +957,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())); + } } } } @@ -1770,3 +1772,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); + } +} + |