changeset 698:bdd56c5adb38 draft

Bugfixes walletclass 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()
author Pieter Wuille <pieter.wuille@gmail.com>
date Sun, 19 Jun 2011 18:32:36 +0200
parents 5c79c3baa104
children 58a93d5d26ac
files src/keystore.h src/script.cpp src/wallet.cpp src/wallet.h
diffstat 4 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/keystore.h
+++ b/src/keystore.h
@@ -14,11 +14,15 @@
     {
         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();
 };
--- a/src/script.cpp
+++ b/src/script.cpp
@@ -1038,12 +1038,13 @@
             {
                 // 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 @@
                 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;
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -1006,8 +1006,8 @@
             wtx = (*mi).second;
             return true;
         }
-        return false;
     }
+    return false;
 }
 
 bool GetWalletFile(CWallet* pwallet, string &strWalletFileOut)
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -96,7 +96,7 @@
     {
         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
     {