From fd61d6f5068cf92d34569862b4225f177049a4f0 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Mon, 14 May 2012 19:07:52 +0200 Subject: Encapsulate public keys in CPubKey --- src/wallet.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/wallet.cpp') diff --git a/src/wallet.cpp b/src/wallet.cpp index 62f663c0dc..2f8d7c05ab 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -16,7 +16,7 @@ using namespace std; // mapWallet // -std::vector CWallet::GenerateNewKey() +CPubKey CWallet::GenerateNewKey() { bool fCompressed = CanSupportFeature(FEATURE_COMPRPUBKEY); // default to compressed public keys if we want 0.6.0 wallets @@ -44,7 +44,7 @@ bool CWallet::AddKey(const CKey& key) return true; } -bool CWallet::AddCryptedKey(const vector &vchPubKey, const vector &vchCryptedSecret) +bool CWallet::AddCryptedKey(const CPubKey &vchPubKey, const vector &vchCryptedSecret) { if (!CCryptoKeyStore::AddCryptedKey(vchPubKey, vchCryptedSecret)) return false; @@ -366,7 +366,7 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn) { if (txout.scriptPubKey == scriptDefaultKey) { - std::vector newDefaultKey; + CPubKey newDefaultKey; if (GetKeyFromPool(newDefaultKey, false)) { SetDefaultKey(newDefaultKey); @@ -1095,7 +1095,7 @@ bool CWallet::CreateTransaction(const vector >& vecSend, CW // post-backup change. // Reserve a new key pair from key pool - vector vchPubKey = reservekey.GetReservedKey(); + CPubKey vchPubKey = reservekey.GetReservedKey(); // assert(mapKeys.count(vchPubKey)); // Fill a vout to ourself @@ -1278,7 +1278,7 @@ 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; @@ -1332,7 +1332,7 @@ bool CWallet::GetTransaction(const uint256 &hashTx, CWalletTx& wtx) return false; } -bool CWallet::SetDefaultKey(const std::vector &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& result, bool fAllowReuse) +bool CWallet::GetKeyFromPool(CPubKey& result, bool fAllowReuse) { int64 nIndex = 0; CKeyPool keypool; @@ -1477,7 +1477,7 @@ bool CWallet::GetKeyFromPool(vector& 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 CReserveKey::GetReservedKey() +CPubKey CReserveKey::GetReservedKey() { if (nIndex == -1) { @@ -1517,7 +1517,7 @@ vector 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,7 +1534,7 @@ void CReserveKey::ReturnKey() if (nIndex != -1) pwallet->ReturnKey(nIndex); nIndex = -1; - vchPubKey.clear(); + vchPubKey = CPubKey(); } void CWallet::GetAllReserveAddresses(set& setAddress) @@ -1550,7 +1550,7 @@ void CWallet::GetAllReserveAddresses(set& setAddress) if (!walletdb.ReadPool(id, keypool)) throw runtime_error("GetAllReserveKeyHashes() : read failed"); CBitcoinAddress address(keypool.vchPubKey); - assert(!keypool.vchPubKey.empty()); + assert(keypool.vchPubKey.IsValid()); if (!HaveKey(address)) throw runtime_error("GetAllReserveKeyHashes() : unknown key in key pool"); setAddress.insert(address); -- cgit v1.2.3