Bugfixes walletclass
authorPieter Wuille <pieter.wuille@gmail.com>
Sun, 19 Jun 2011 16:32:36 +0000 (18:32 +0200)
committerPieter Wuille <pieter.wuille@gmail.com>
Mon, 20 Jun 2011 18:07:28 +0000 (20:07 +0200)
Some problems found by ius:
* compiler complains with no return after critical section block
* CKeyStore::GetPrivKey(key) was undefined for unknown key
* missing return statement in GetChange()

src/keystore.h
src/script.cpp
src/wallet.cpp
src/wallet.h

index 3b6869b..6080d7d 100644 (file)
@@ -14,11 +14,15 @@ public:
     {
         return (mapKeys.count(vchPubKey) > 0);
     }
-    CPrivKey GetPrivKey(const std::vector<unsigned char> &vchPubKey) const
+    bool GetPrivKey(const std::vector<unsigned char> &vchPubKey, CPrivKey& keyOut) const
     {
         std::map<std::vector<unsigned char>, CPrivKey>::const_iterator mi = mapKeys.find(vchPubKey);
         if (mi != mapKeys.end())
-            return (*mi).second;
+        {
+            keyOut = (*mi).second;
+            return true;
+        }
+        return false;
     }
     std::vector<unsigned char> GenerateNewKey();
 };
index e1b5ae8..bd1b5b3 100644 (file)
@@ -1038,12 +1038,13 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
             {
                 // Sign
                 const valtype& vchPubKey = item.second;
-                if (!keystore.HaveKey(vchPubKey))
+                CPrivKey privkey;
+                if (!keystore.GetPrivKey(vchPubKey, privkey))
                     return false;
                 if (hash != 0)
                 {
                     vector<unsigned char> vchSig;
-                    if (!CKey::Sign(keystore.GetPrivKey(vchPubKey), hash, vchSig))
+                    if (!CKey::Sign(privkey, hash, vchSig))
                         return false;
                     vchSig.push_back((unsigned char)nHashType);
                     scriptSigRet << vchSig;
@@ -1056,12 +1057,13 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
                 if (mi == mapPubKeys.end())
                     return false;
                 const vector<unsigned char>& vchPubKey = (*mi).second;
-                if (!keystore.HaveKey(vchPubKey))
+                CPrivKey privkey;
+                if (!keystore.GetPrivKey(vchPubKey, privkey))
                     return false;
                 if (hash != 0)
                 {
                     vector<unsigned char> vchSig;
-                    if (!CKey::Sign(keystore.GetPrivKey(vchPubKey), hash, vchSig))
+                    if (!CKey::Sign(privkey, hash, vchSig))
                         return false;
                     vchSig.push_back((unsigned char)nHashType);
                     scriptSigRet << vchSig << vchPubKey;
index 7a65b2a..b06187a 100644 (file)
@@ -1006,8 +1006,8 @@ bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx)
             wtx = (*mi).second;
             return true;
         }
-        return false;
     }
+    return false;
 }
 
 bool GetWalletFile(CWallet* pwallet, string &strWalletFileOut)
index b14a2e8..cda4293 100644 (file)
@@ -96,7 +96,7 @@ public:
     {
         if (!MoneyRange(txout.nValue))
             throw std::runtime_error("CWallet::GetChange() : value out of range");
-        if (IsChange(txout) ? txout.nValue : 0);
+        return (IsChange(txout) ? txout.nValue : 0);
     }
     bool IsMine(const CTransaction& tx) const
     {