Skip to content

Commit

Permalink
init: Print error if MN collateral utxo is not in the wallet.
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Feb 26, 2021
1 parent 6936cb2 commit fbe9200
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1863,13 +1863,16 @@ bool AppInitMain()
#ifdef ENABLE_WALLET
if (gArgs.GetBoolArg("-mnconflock", DEFAULT_MNCONFLOCK) && pwalletMain) {
LOCK(pwalletMain->cs_wallet);
LogPrintf("Locking Masternodes:\n");
LogPrintf("Locking Masternodes collateral utxo:\n");
uint256 mnTxHash;
for (CMasternodeConfig::CMasternodeEntry mne : masternodeConfig.getEntries()) {
LogPrintf(" %s %s\n", mne.getTxHash(), mne.getOutputIndex());
for (const auto& mne : masternodeConfig.getEntries()) {
mnTxHash.SetHex(mne.getTxHash());
COutPoint outpoint = COutPoint(mnTxHash, (unsigned int) std::stoul(mne.getOutputIndex().c_str()));
pwalletMain->LockCoin(outpoint);
COutPoint outpoint = COutPoint(mnTxHash, (unsigned int) std::stoul(mne.getOutputIndex()));
if (pwalletMain->LockCoin(outpoint)) {
LogPrintf("Locked collateral, tx hash: %s, output index: %s\n", mne.getTxHash(), mne.getOutputIndex());
} else {
LogPrintf("Error locking collateral, tx not found. hash %s, output index: %s\n", mne.getTxHash(), mne.getOutputIndex());
}
}
}
#endif
Expand Down
4 changes: 3 additions & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3618,10 +3618,12 @@ void CReserveKey::ReturnKey()
vchPubKey = CPubKey();
}

void CWallet::LockCoin(const COutPoint& output)
bool CWallet::LockCoin(const COutPoint& output)
{
AssertLockHeld(cs_wallet); // setLockedCoins
if (mapWallet.count(output.hash) == 0) return false;
setLockedCoins.insert(output);
return true;
}

void CWallet::UnlockCoin(const COutPoint& output)
Expand Down
3 changes: 2 additions & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,8 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
bool IsSpent(const uint256& hash, unsigned int n) const;

bool IsLockedCoin(const uint256& hash, unsigned int n) const;
void LockCoin(const COutPoint& output);
// Return false if the transaction doesn't exist in the wallet.
bool LockCoin(const COutPoint& output);
void UnlockCoin(const COutPoint& output);
void UnlockAllCoins();
std::set<COutPoint> ListLockedCoins();
Expand Down

0 comments on commit fbe9200

Please sign in to comment.