Split CMerkleTx::SetMerkleBranch
[novacoin.git] / src / wallet.cpp
index 8006674..85bf6ac 100644 (file)
@@ -12,6 +12,7 @@
 #include "kernel.h"
 #include "coincontrol.h"
 #include <boost/algorithm/string/replace.hpp>
+#include <openssl/bio.h>
 
 #include "main.h"
 
@@ -74,8 +75,8 @@ CMalleableKeyView CWallet::GenerateNewMalleableKey()
     if (!nTimeFirstKey || nCreationTime < nTimeFirstKey)
         nTimeFirstKey = nCreationTime;
 
-    if (!AddMalleableKey(mKey))
-        throw std::runtime_error("CWallet::GenerateNewMalleableKey() : AddMalleableKey failed");
+    if (!AddKey(mKey))
+        throw std::runtime_error("CWallet::GenerateNewMalleableKey() : AddKey failed");
     return CMalleableKeyView(mKey);
 }
 
@@ -91,7 +92,7 @@ bool CWallet::AddKey(const CKey& key)
     return true;
 }
 
-bool CWallet::AddMalleableKey(const CMalleableKey& mKey)
+bool CWallet::AddKey(const CMalleableKey& mKey)
 {
     CMalleableKeyView keyView = CMalleableKeyView(mKey);
     CSecret vchSecretH = mKey.GetSecretH();
@@ -516,6 +517,19 @@ bool CWallet::DecryptWallet(const SecureString& strWalletPassphrase)
     return true;
 }
 
+bool CWallet::GetPEM(const CKeyID &keyID, const std::string &fileName, const SecureString &strPassKey) const
+{
+    BIO *pemOut = BIO_new_file(fileName.c_str(), "w");
+    if (pemOut == NULL)
+        return error("GetPEM() : failed to create file %s\n", fileName.c_str());
+    CKey key;
+    if (!GetKey(keyID, key))
+        return error("GetPEM() : failed to get key for address=%s\n", CBitcoinAddress(keyID).ToString().c_str());
+    bool result = key.WritePEM(pemOut, strPassKey);
+    BIO_free(pemOut);
+    return result;
+}
+
 int64_t CWallet::IncOrderPosNext(CWalletDB *pwalletdb)
 {
     int64_t nRet = nOrderPosNext++;
@@ -750,7 +764,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
             CWalletTx wtx(this,tx);
             // Get merkle branch if transaction was found in a block
             if (pblock)
-                wtx.SetMerkleBranch(pblock);
+                wtx.SetMerkleBranch(*pblock);
             return AddToWallet(wtx);
         }
         else
@@ -942,7 +956,7 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64_t& nGenerated,
     list<pair<CBitcoinAddress, int64_t> > listSent;
     GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount, filter);
 
-    if (strAccount == "")
+    if (strAccount.empty())
         nGenerated = allGeneratedMature;
     if (strAccount == strSentAccount)
     {
@@ -1660,7 +1674,7 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64_t> >& vecSend,
         CTxDB txdb("r");
         {
             nFeeRet = nTransactionFee;
-            while (true)
+            for ( ; ; )
             {
                 wtxNew.vin.clear();
                 wtxNew.vout.clear();
@@ -2048,7 +2062,7 @@ bool CWallet::CreateCoinStake(uint256 &hashTx, uint32_t nOut, uint32_t nGenerati
     nCredit += GetProofOfStakeReward(nCoinAge, nBits, nGenerationTime);
 
     int64_t nMinFee = 0;
-    while (true)
+    for ( ; ; )
     {
         // Set output amount
         if (fDontSplitCoins)
@@ -2236,6 +2250,11 @@ DBErrors CWallet::ZapWalletTx()
     return DB_LOAD_OK;
 }
 
+bool CWallet::SetAddressBookName(const CTxDestination& address, const string& strName)
+{
+    return SetAddressBookName(CBitcoinAddress(address), strName);
+}
+
 bool CWallet::SetAddressBookName(const CBitcoinAddress& address, const string& strName)
 {
     std::map<CBitcoinAddress, string>::iterator mi = mapAddressBook.find(address);