Save and restore fWalletUnlockMintonly flag
authorMASM fan <masmfan@gmail.com>
Tue, 10 Feb 2015 20:02:00 +0000 (12:02 -0800)
committerMASM fan <masmfan@gmail.com>
Tue, 10 Feb 2015 20:02:00 +0000 (12:02 -0800)
Fixes issue #145

src/qt/walletmodel.cpp
src/qt/walletmodel.h

index 0d8b0ab..2f2ccab 100644 (file)
@@ -410,12 +410,12 @@ void WalletModel::unsubscribeFromCoreSignals()
 WalletModel::UnlockContext WalletModel::requestUnlock()
 {
     bool was_locked = getEncryptionStatus() == Locked;
+    bool mintflag = fWalletUnlockMintOnly;
 
     if ((!was_locked) && fWalletUnlockMintOnly)
     {
-       setWalletLocked(true);
-       was_locked = getEncryptionStatus() == Locked;
-
+        setWalletLocked(true);
+        was_locked = getEncryptionStatus() == Locked;
     }
     if(was_locked)
     {
@@ -425,13 +425,14 @@ WalletModel::UnlockContext WalletModel::requestUnlock()
     // If wallet is still locked, unlock was failed or cancelled, mark context as invalid
     bool valid = getEncryptionStatus() != Locked;
 
-    return UnlockContext(this, valid, was_locked && !fWalletUnlockMintOnly);
+    return UnlockContext(this, valid, was_locked, mintflag);
 }
 
-WalletModel::UnlockContext::UnlockContext(WalletModel *wallet, bool valid, bool relock):
+WalletModel::UnlockContext::UnlockContext(WalletModel *wallet, bool valid, bool relock, bool mintflag):
         wallet(wallet),
         valid(valid),
-        relock(relock)
+        relock(relock),
+        mintflag(mintflag)
 {
 }
 
@@ -439,7 +440,14 @@ WalletModel::UnlockContext::~UnlockContext()
 {
     if(valid && relock)
     {
+        if (mintflag)
+        {
+            // Restore unlock minting flag
+            fWalletUnlockMintOnly = mintflag;
+            return;
+        }
         wallet->setWalletLocked(true);
+
     }
 }
 
@@ -452,7 +460,7 @@ void WalletModel::UnlockContext::CopyFrom(const UnlockContext& rhs)
 
 bool WalletModel::getPubKey(const CKeyID &address, CPubKey& vchPubKeyOut) const
 {
-    return wallet->GetPubKey(address, vchPubKeyOut);   
+    return wallet->GetPubKey(address, vchPubKeyOut);
 }
 
 // returns a list of COutputs from COutPoints
index f00ce70..e0e1163 100644 (file)
@@ -110,7 +110,7 @@ public:
     class UnlockContext
     {
     public:
-        UnlockContext(WalletModel *wallet, bool valid, bool relock);
+        UnlockContext(WalletModel *wallet, bool valid, bool relock, bool mintflag);
         ~UnlockContext();
 
         bool isValid() const { return valid; }
@@ -122,6 +122,7 @@ public:
         WalletModel *wallet;
         bool valid;
         mutable bool relock; // mutable, as it can be set to false by copying
+        bool mintflag;
 
         void CopyFrom(const UnlockContext& rhs);
     };