changeset 699:58a93d5d26ac draft

Merge pull request #334 from sipa/walletclass Bugfixes walletclass
author Pieter Wuille <pieter.wuille@gmail.com>
date Mon, 20 Jun 2011 11:10:58 -0700
parents 5c79c3baa104 (current diff) bdd56c5adb38 (diff)
children 70d9ec57e0b3 60dfcabae0fc
files
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
     {