aboutsummaryrefslogtreecommitdiff
path: root/src/wallet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet.cpp')
-rw-r--r--src/wallet.cpp88
1 files changed, 44 insertions, 44 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 62f663c0dc..3c4aeb4eaf 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -7,6 +7,7 @@
#include "walletdb.h"
#include "crypter.h"
#include "ui_interface.h"
+#include "base58.h"
using namespace std;
@@ -16,7 +17,7 @@ using namespace std;
// mapWallet
//
-std::vector<unsigned char> CWallet::GenerateNewKey()
+CPubKey CWallet::GenerateNewKey()
{
bool fCompressed = CanSupportFeature(FEATURE_COMPRPUBKEY); // default to compressed public keys if we want 0.6.0 wallets
@@ -44,7 +45,7 @@ bool CWallet::AddKey(const CKey& key)
return true;
}
-bool CWallet::AddCryptedKey(const vector<unsigned char> &vchPubKey, const vector<unsigned char> &vchCryptedSecret)
+bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, const vector<unsigned char> &vchCryptedSecret)
{
if (!CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret))
return false;
@@ -361,16 +362,16 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn)
#ifndef QT_GUI
// If default receiving address gets used, replace it with a new one
CScript scriptDefaultKey;
- scriptDefaultKey.SetBitcoinAddress(vchDefaultKey);
+ scriptDefaultKey.SetDestination(vchDefaultKey.GetID());
BOOST_FOREACH(const CTxOut& txout, wtx.vout)
{
if (txout.scriptPubKey == scriptDefaultKey)
{
- std::vector<unsigned char> newDefaultKey;
+ CPubKey newDefaultKey;
if (GetKeyFromPool(newDefaultKey, false))
{
SetDefaultKey(newDefaultKey);
- SetAddressBookName(CBitcoinAddress(vchDefaultKey), "");
+ SetAddressBookName(vchDefaultKey.GetID(), "");
}
}
}
@@ -455,7 +456,7 @@ int64 CWallet::GetDebit(const CTxIn &txin) const
bool CWallet::IsChange(const CTxOut& txout) const
{
- CBitcoinAddress address;
+ CTxDestination address;
// TODO: fix handling of 'change' outputs. The assumption is that any
// payment to a TX_PUBKEYHASH that is mine but isn't in the address book
@@ -464,7 +465,7 @@ bool CWallet::IsChange(const CTxOut& txout) const
// a better way of identifying which outputs are 'the send' and which are
// 'the change' will need to be implemented (maybe extend CWalletTx to remember
// which output, if any, was change).
- if (ExtractAddress(txout.scriptPubKey, address) && HaveKey(address))
+ if (ExtractDestination(txout.scriptPubKey, address) && ::IsMine(*this, address))
{
LOCK(cs_wallet);
if (!mapAddressBook.count(address))
@@ -517,8 +518,8 @@ int CWalletTx::GetRequestCount() const
return nRequests;
}
-void CWalletTx::GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, list<pair<CBitcoinAddress, int64> >& listReceived,
- list<pair<CBitcoinAddress, int64> >& listSent, int64& nFee, string& strSentAccount) const
+void CWalletTx::GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, list<pair<CTxDestination, int64> >& listReceived,
+ list<pair<CTxDestination, int64> >& listSent, int64& nFee, string& strSentAccount) const
{
nGeneratedImmature = nGeneratedMature = nFee = 0;
listReceived.clear();
@@ -545,13 +546,12 @@ void CWalletTx::GetAmounts(int64& nGeneratedImmature, int64& nGeneratedMature, l
// Sent/received.
BOOST_FOREACH(const CTxOut& txout, vout)
{
- CBitcoinAddress address;
+ CTxDestination address;
vector<unsigned char> vchPubKey;
- if (!ExtractAddress(txout.scriptPubKey, address))
+ if (!ExtractDestination(txout.scriptPubKey, address))
{
printf("CWalletTx::GetAmounts: Unknown transaction type found, txid %s\n",
this->GetHash().ToString().c_str());
- address = " unknown ";
}
// Don't report 'change' txouts
@@ -575,25 +575,25 @@ void CWalletTx::GetAccountAmounts(const string& strAccount, int64& nGenerated, i
int64 allGeneratedImmature, allGeneratedMature, allFee;
allGeneratedImmature = allGeneratedMature = allFee = 0;
string strSentAccount;
- list<pair<CBitcoinAddress, int64> > listReceived;
- list<pair<CBitcoinAddress, int64> > listSent;
+ list<pair<CTxDestination, int64> > listReceived;
+ list<pair<CTxDestination, int64> > listSent;
GetAmounts(allGeneratedImmature, allGeneratedMature, listReceived, listSent, allFee, strSentAccount);
if (strAccount == "")
nGenerated = allGeneratedMature;
if (strAccount == strSentAccount)
{
- BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64)& s, listSent)
+ BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& s, listSent)
nSent += s.second;
nFee = allFee;
}
{
LOCK(pwallet->cs_wallet);
- BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress,int64)& r, listReceived)
+ BOOST_FOREACH(const PAIRTYPE(CTxDestination,int64)& r, listReceived)
{
if (pwallet->mapAddressBook.count(r.first))
{
- map<CBitcoinAddress, string>::const_iterator mi = pwallet->mapAddressBook.find(r.first);
+ map<CTxDestination, string>::const_iterator mi = pwallet->mapAddressBook.find(r.first);
if (mi != pwallet->mapAddressBook.end() && (*mi).second == strAccount)
nReceived += r.second;
}
@@ -1095,14 +1095,14 @@ bool CWallet::CreateTransaction(const vector<pair<CScript, int64> >& vecSend, CW
// post-backup change.
// Reserve a new key pair from key pool
- vector<unsigned char> vchPubKey = reservekey.GetReservedKey();
+ CPubKey vchPubKey = reservekey.GetReservedKey();
// assert(mapKeys.count(vchPubKey));
// Fill a vout to ourself
// TODO: pass in scriptChange instead of reservekey so
// change transaction isn't always pay-to-bitcoin-address
CScript scriptChange;
- scriptChange.SetBitcoinAddress(vchPubKey);
+ scriptChange.SetDestination(vchPubKey.GetID());
// Insert change txn at random position:
vector<CTxOut>::iterator position = wtxNew.vout.begin()+GetRandInt(wtxNew.vout.size());
@@ -1240,7 +1240,7 @@ string CWallet::SendMoney(CScript scriptPubKey, int64 nValue, CWalletTx& wtxNew,
-string CWallet::SendMoneyToBitcoinAddress(const CBitcoinAddress& address, int64 nValue, CWalletTx& wtxNew, bool fAskFee)
+string CWallet::SendMoneyToDestination(const CTxDestination& address, int64 nValue, CWalletTx& wtxNew, bool fAskFee)
{
// Check amount
if (nValue <= 0)
@@ -1250,7 +1250,7 @@ string CWallet::SendMoneyToBitcoinAddress(const CBitcoinAddress& address, int64
// Parse Bitcoin address
CScript scriptPubKey;
- scriptPubKey.SetBitcoinAddress(address);
+ scriptPubKey.SetDestination(address);
return SendMoney(scriptPubKey, nValue, wtxNew, fAskFee);
}
@@ -1278,30 +1278,30 @@ int CWallet::LoadWallet(bool& fFirstRunRet)
if (nLoadWalletRet != DB_LOAD_OK)
return nLoadWalletRet;
- fFirstRunRet = vchDefaultKey.empty();
+ fFirstRunRet = !vchDefaultKey.IsValid();
CreateThread(ThreadFlushWalletDB, &strWalletFile);
return DB_LOAD_OK;
}
-bool CWallet::SetAddressBookName(const CBitcoinAddress& address, const string& strName)
+bool CWallet::SetAddressBookName(const CTxDestination& address, const string& strName)
{
- std::map<CBitcoinAddress, std::string>::iterator mi = mapAddressBook.find(address);
+ std::map<CTxDestination, std::string>::iterator mi = mapAddressBook.find(address);
mapAddressBook[address] = strName;
- NotifyAddressBookChanged(this, address.ToString(), strName, HaveKey(address), (mi == mapAddressBook.end()) ? CT_NEW : CT_UPDATED);
+ NotifyAddressBookChanged(this, address, strName, ::IsMine(*this, address), (mi == mapAddressBook.end()) ? CT_NEW : CT_UPDATED);
if (!fFileBacked)
return false;
- return CWalletDB(strWalletFile).WriteName(address.ToString(), strName);
+ return CWalletDB(strWalletFile).WriteName(CBitcoinAddress(address).ToString(), strName);
}
-bool CWallet::DelAddressBookName(const CBitcoinAddress& address)
+bool CWallet::DelAddressBookName(const CTxDestination& address)
{
mapAddressBook.erase(address);
- NotifyAddressBookChanged(this, address.ToString(), "", HaveKey(address), CT_DELETED);
+ NotifyAddressBookChanged(this, address, "", ::IsMine(*this, address), CT_DELETED);
if (!fFileBacked)
return false;
- return CWalletDB(strWalletFile).EraseName(address.ToString());
+ return CWalletDB(strWalletFile).EraseName(CBitcoinAddress(address).ToString());
}
@@ -1332,7 +1332,7 @@ bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx)
return false;
}
-bool CWallet::SetDefaultKey(const std::vector<unsigned char> &vchPubKey)
+bool CWallet::SetDefaultKey(const CPubKey &vchPubKey)
{
if (fFileBacked)
{
@@ -1408,7 +1408,7 @@ bool CWallet::TopUpKeyPool()
void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool)
{
nIndex = -1;
- keypool.vchPubKey.clear();
+ keypool.vchPubKey = CPubKey();
{
LOCK(cs_wallet);
@@ -1425,9 +1425,9 @@ void CWallet::ReserveKeyFromKeyPool(int64& nIndex, CKeyPool& keypool)
setKeyPool.erase(setKeyPool.begin());
if (!walletdb.ReadPool(nIndex, keypool))
throw runtime_error("ReserveKeyFromKeyPool() : read failed");
- if (!HaveKey(Hash160(keypool.vchPubKey)))
+ if (!HaveKey(keypool.vchPubKey.GetID()))
throw runtime_error("ReserveKeyFromKeyPool() : unknown key in key pool");
- assert(!keypool.vchPubKey.empty());
+ assert(keypool.vchPubKey.IsValid());
printf("keypool reserve %"PRI64d"\n", nIndex);
}
}
@@ -1468,7 +1468,7 @@ void CWallet::ReturnKey(int64 nIndex)
printf("keypool return %"PRI64d"\n", nIndex);
}
-bool CWallet::GetKeyFromPool(vector<unsigned char>& result, bool fAllowReuse)
+bool CWallet::GetKeyFromPool(CPubKey& result, bool fAllowReuse)
{
int64 nIndex = 0;
CKeyPool keypool;
@@ -1477,7 +1477,7 @@ bool CWallet::GetKeyFromPool(vector<unsigned char>& result, bool fAllowReuse)
ReserveKeyFromKeyPool(nIndex, keypool);
if (nIndex == -1)
{
- if (fAllowReuse && !vchDefaultKey.empty())
+ if (fAllowReuse && vchDefaultKey.IsValid())
{
result = vchDefaultKey;
return true;
@@ -1503,7 +1503,7 @@ int64 CWallet::GetOldestKeyPoolTime()
return keypool.nTime;
}
-vector<unsigned char> CReserveKey::GetReservedKey()
+CPubKey CReserveKey::GetReservedKey()
{
if (nIndex == -1)
{
@@ -1517,7 +1517,7 @@ vector<unsigned char> CReserveKey::GetReservedKey()
vchPubKey = pwallet->vchDefaultKey;
}
}
- assert(!vchPubKey.empty());
+ assert(vchPubKey.IsValid());
return vchPubKey;
}
@@ -1526,7 +1526,7 @@ void CReserveKey::KeepKey()
if (nIndex != -1)
pwallet->KeepKey(nIndex);
nIndex = -1;
- vchPubKey.clear();
+ vchPubKey = CPubKey();
}
void CReserveKey::ReturnKey()
@@ -1534,10 +1534,10 @@ void CReserveKey::ReturnKey()
if (nIndex != -1)
pwallet->ReturnKey(nIndex);
nIndex = -1;
- vchPubKey.clear();
+ vchPubKey = CPubKey();
}
-void CWallet::GetAllReserveAddresses(set<CBitcoinAddress>& setAddress)
+void CWallet::GetAllReserveKeys(set<CKeyID>& setAddress)
{
setAddress.clear();
@@ -1549,11 +1549,11 @@ void CWallet::GetAllReserveAddresses(set<CBitcoinAddress>& setAddress)
CKeyPool keypool;
if (!walletdb.ReadPool(id, keypool))
throw runtime_error("GetAllReserveKeyHashes() : read failed");
- CBitcoinAddress address(keypool.vchPubKey);
- assert(!keypool.vchPubKey.empty());
- if (!HaveKey(address))
+ assert(keypool.vchPubKey.IsValid());
+ CKeyID keyID = keypool.vchPubKey.GetID();
+ if (!HaveKey(keyID))
throw runtime_error("GetAllReserveKeyHashes() : unknown key in key pool");
- setAddress.insert(address);
+ setAddress.insert(keyID);
}
}