From 03fbd7904903928b0d1c8542a3d597aaf5bdd31b Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 5 Jul 2011 16:42:32 +0200 Subject: get rid of mapPubKeys Make CKeyStore's interface work on uint160's instead of pubkeys, so no separate global mapPubKeys is necessary anymore. --- src/ui.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/ui.cpp') diff --git a/src/ui.cpp b/src/ui.cpp index eae0a4f4c8..fba8ed8061 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -238,9 +238,10 @@ void SetDefaultReceivingAddress(const string& strAddress) uint160 hash160; if (!AddressToHash160(strAddress, hash160)) return; - if (!mapPubKeys.count(hash160)) + vector vchPubKey; + if (!pwalletMain->GetPubKey(hash160, vchPubKey)) return; - pwalletMain->SetDefaultKey(mapPubKeys[hash160]); + pwalletMain->SetDefaultKey(vchPubKey); pframeMain->m_textCtrlAddress->SetValue(strAddress); } } @@ -703,15 +704,15 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex) { if (pwalletMain->IsMine(txout)) { - vector vchPubKey; - if (ExtractPubKey(txout.scriptPubKey, pwalletMain, vchPubKey)) + uint160 hash160; + if (ExtractHash160(txout.scriptPubKey, pwalletMain, hash160)) { CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) { //strDescription += _("Received payment to "); //strDescription += _("Received with address "); strDescription += _("Received with: "); - string strAddress = PubKeyToAddress(vchPubKey); + string strAddress = Hash160ToAddress(hash160); map::iterator mi = pwalletMain->mapAddressBook.find(strAddress); if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.empty()) { @@ -786,7 +787,7 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex) { // Sent to Bitcoin Address uint160 hash160; - if (ExtractHash160(txout.scriptPubKey, hash160)) + if (ExtractHash160(txout.scriptPubKey, pwalletMain, hash160)) strAddress = Hash160ToAddress(hash160); } @@ -1502,10 +1503,10 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails { if (pwalletMain->IsMine(txout)) { - vector vchPubKey; - if (ExtractPubKey(txout.scriptPubKey, pwalletMain, vchPubKey)) + uint160 hash160; + if (ExtractHash160(txout.scriptPubKey, pwalletMain, hash160)) { - string strAddress = PubKeyToAddress(vchPubKey); + string strAddress = Hash160ToAddress(hash160); if (pwalletMain->mapAddressBook.count(strAddress)) { strHTML += string() + _("From: ") + _("unknown") + "
"; @@ -1589,7 +1590,7 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails { // Offline transaction uint160 hash160; - if (ExtractHash160(txout.scriptPubKey, hash160)) + if (ExtractHash160(txout.scriptPubKey, pwalletMain, hash160)) { string strAddress = Hash160ToAddress(hash160); strHTML += _("To: "); @@ -2630,7 +2631,7 @@ CAddressBookDialog::CAddressBookDialog(wxWindow* parent, const wxString& strInit string strAddress = item.first; string strName = item.second; uint160 hash160; - bool fMine = (AddressToHash160(strAddress, hash160) && mapPubKeys.count(hash160)); + bool fMine = (AddressToHash160(strAddress, hash160) && pwalletMain->HaveKey(hash160)); wxListCtrl* plistCtrl = fMine ? m_listCtrlReceiving : m_listCtrlSending; int nIndex = InsertLine(plistCtrl, strName, strAddress); if (strAddress == (fMine ? strDefaultReceiving : string(strInitSelected))) @@ -2741,7 +2742,7 @@ void CAddressBookDialog::OnButtonCopy(wxCommandEvent& event) bool CAddressBookDialog::CheckIfMine(const string& strAddress, const string& strTitle) { uint160 hash160; - bool fMine = (AddressToHash160(strAddress, hash160) && mapPubKeys.count(hash160)); + bool fMine = (AddressToHash160(strAddress, hash160) && pwalletMain->HaveKey(hash160)); if (fMine) wxMessageBox(_("This is one of your own addresses for receiving payments and cannot be entered in the address book. "), strTitle); return fMine; -- cgit v1.2.3 From 2ffba736e9102d016b96c2e5de2ce7757e612667 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 5 Jul 2011 20:53:43 +0200 Subject: Use CBitcoinAddress instead of string/uint160 Instead of conversion functions between pubkey/uint160/address in base58.h, have a fully fledged class CBitcoinAddress (CAddress was already taken) to represent addresses. --- src/ui.cpp | 77 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 37 insertions(+), 40 deletions(-) (limited to 'src/ui.cpp') diff --git a/src/ui.cpp b/src/ui.cpp index fba8ed8061..7d06caaec4 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -235,11 +235,11 @@ void SetDefaultReceivingAddress(const string& strAddress) return; if (strAddress != pframeMain->m_textCtrlAddress->GetValue()) { - uint160 hash160; - if (!AddressToHash160(strAddress, hash160)) + CBitcoinAddress address(strAddress); + if (!address.IsValid()) return; vector vchPubKey; - if (!pwalletMain->GetPubKey(hash160, vchPubKey)) + if (!pwalletMain->GetPubKey(address, vchPubKey)) return; pwalletMain->SetDefaultKey(vchPubKey); pframeMain->m_textCtrlAddress->SetValue(strAddress); @@ -367,7 +367,7 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent) // Fill your address text box vector vchPubKey; if (CWalletDB(pwalletMain->strWalletFile,"r").ReadDefaultKey(vchPubKey)) - m_textCtrlAddress->SetValue(PubKeyToAddress(vchPubKey)); + m_textCtrlAddress->SetValue(CBitcoinAddress(vchPubKey).ToString()); if (pwalletMain->IsCrypted()) m_menuOptions->Remove(m_menuOptionsEncryptWallet); @@ -704,24 +704,23 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex) { if (pwalletMain->IsMine(txout)) { - uint160 hash160; - if (ExtractHash160(txout.scriptPubKey, pwalletMain, hash160)) + CBitcoinAddress address; + if (ExtractAddress(txout.scriptPubKey, pwalletMain, address)) { CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) { //strDescription += _("Received payment to "); //strDescription += _("Received with address "); strDescription += _("Received with: "); - string strAddress = Hash160ToAddress(hash160); - map::iterator mi = pwalletMain->mapAddressBook.find(strAddress); + map::iterator mi = pwalletMain->mapAddressBook.find(address); if (mi != pwalletMain->mapAddressBook.end() && !(*mi).second.empty()) { string strLabel = (*mi).second; - strDescription += strAddress.substr(0,12) + "... "; + strDescription += address.ToString().substr(0,12) + "... "; strDescription += "(" + strLabel + ")"; } else - strDescription += strAddress; + strDescription += address.ToString(); } } break; @@ -786,9 +785,9 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex) else { // Sent to Bitcoin Address - uint160 hash160; - if (ExtractHash160(txout.scriptPubKey, pwalletMain, hash160)) - strAddress = Hash160ToAddress(hash160); + CBitcoinAddress address; + if (ExtractAddress(txout.scriptPubKey, pwalletMain, address)) + strAddress = address.ToString(); } string strDescription = _("To: "); @@ -1115,7 +1114,7 @@ void CMainFrame::OnPaintListCtrl(wxPaintEvent& event) m_statusBar->SetStatusText(strStatus, 2); // Update receiving address - string strDefaultAddress = PubKeyToAddress(pwalletMain->vchDefaultKey); + string strDefaultAddress = CBitcoinAddress(pwalletMain->vchDefaultKey).ToString(); if (m_textCtrlAddress->GetValue() != strDefaultAddress) m_textCtrlAddress->SetValue(strDefaultAddress); } @@ -1394,7 +1393,7 @@ void CMainFrame::OnButtonNew(wxCommandEvent& event) return; // Generate new key - strAddress = PubKeyToAddress(pwalletMain->GetOrReuseKeyFromPool()); + strAddress = CBitcoinAddress(pwalletMain->GetOrReuseKeyFromPool()).ToString(); if (fWasLocked) pwalletMain->Lock(); @@ -1503,17 +1502,16 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails { if (pwalletMain->IsMine(txout)) { - uint160 hash160; - if (ExtractHash160(txout.scriptPubKey, pwalletMain, hash160)) + CBitcoinAddress address; + if (ExtractAddress(txout.scriptPubKey, pwalletMain, address)) { - string strAddress = Hash160ToAddress(hash160); - if (pwalletMain->mapAddressBook.count(strAddress)) + if (pwalletMain->mapAddressBook.count(address)) { strHTML += string() + _("From: ") + _("unknown") + "
"; strHTML += _("To: "); - strHTML += HtmlEscape(strAddress); - if (!pwalletMain->mapAddressBook[strAddress].empty()) - strHTML += _(" (yours, label: ") + pwalletMain->mapAddressBook[strAddress] + ")"; + strHTML += HtmlEscape(address.ToString()); + if (!pwalletMain->mapAddressBook[address].empty()) + strHTML += _(" (yours, label: ") + pwalletMain->mapAddressBook[address] + ")"; else strHTML += _(" (yours)"); strHTML += "
"; @@ -1589,13 +1587,13 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails if (wtx.mapValue["to"].empty()) { // Offline transaction - uint160 hash160; - if (ExtractHash160(txout.scriptPubKey, pwalletMain, hash160)) + CBitcoinAddress address; + if (ExtractAddress(txout.scriptPubKey, pwalletMain, address)) { - string strAddress = Hash160ToAddress(hash160); + string strAddress = address.ToString(); strHTML += _("To: "); - if (pwalletMain->mapAddressBook.count(strAddress) && !pwalletMain->mapAddressBook[strAddress].empty()) - strHTML += pwalletMain->mapAddressBook[strAddress] + " "; + if (pwalletMain->mapAddressBook.count(address) && !pwalletMain->mapAddressBook[address].empty()) + strHTML += pwalletMain->mapAddressBook[address] + " "; strHTML += strAddress; strHTML += "
"; } @@ -2156,8 +2154,8 @@ void CSendDialog::OnButtonSend(wxCommandEvent& event) } // Parse bitcoin address - uint160 hash160; - bool fBitcoinAddress = AddressToHash160(strAddress, hash160); + CBitcoinAddress address(strAddress); + bool fBitcoinAddress = address.IsValid(); if (fBitcoinAddress) { @@ -2170,7 +2168,7 @@ void CSendDialog::OnButtonSend(wxCommandEvent& event) // Send to bitcoin address CScript scriptPubKey; - scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG; + scriptPubKey.SetBitcoinAddress(address); string strError = pwalletMain->SendMoney(scriptPubKey, nValue, wtx, true); if (strError == "") @@ -2214,7 +2212,7 @@ void CSendDialog::OnButtonSend(wxCommandEvent& event) } CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) - if (!pwalletMain->mapAddressBook.count(strAddress)) + if (!pwalletMain->mapAddressBook.count(address)) pwalletMain->SetAddressBookName(strAddress, ""); EndModal(true); @@ -2626,15 +2624,14 @@ CAddressBookDialog::CAddressBookDialog(wxWindow* parent, const wxString& strInit CRITICAL_BLOCK(pwalletMain->cs_mapAddressBook) { string strDefaultReceiving = (string)pframeMain->m_textCtrlAddress->GetValue(); - BOOST_FOREACH(const PAIRTYPE(string, string)& item, pwalletMain->mapAddressBook) + BOOST_FOREACH(const PAIRTYPE(CBitcoinAddress, string)& item, pwalletMain->mapAddressBook) { - string strAddress = item.first; + const CBitcoinAddress& address = item.first; string strName = item.second; - uint160 hash160; - bool fMine = (AddressToHash160(strAddress, hash160) && pwalletMain->HaveKey(hash160)); + bool fMine = pwalletMain->HaveKey(address); wxListCtrl* plistCtrl = fMine ? m_listCtrlReceiving : m_listCtrlSending; - int nIndex = InsertLine(plistCtrl, strName, strAddress); - if (strAddress == (fMine ? strDefaultReceiving : string(strInitSelected))) + int nIndex = InsertLine(plistCtrl, strName, address.ToString()); + if (address.ToString() == (fMine ? strDefaultReceiving : string(strInitSelected))) plistCtrl->SetItemState(nIndex, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED, wxLIST_STATE_SELECTED|wxLIST_STATE_FOCUSED); } } @@ -2741,8 +2738,8 @@ void CAddressBookDialog::OnButtonCopy(wxCommandEvent& event) bool CAddressBookDialog::CheckIfMine(const string& strAddress, const string& strTitle) { - uint160 hash160; - bool fMine = (AddressToHash160(strAddress, hash160) && pwalletMain->HaveKey(hash160)); + CBitcoinAddress address(strAddress); + bool fMine = address.IsValid() && pwalletMain->HaveKey(address); if (fMine) wxMessageBox(_("This is one of your own addresses for receiving payments and cannot be entered in the address book. "), strTitle); return fMine; @@ -2828,7 +2825,7 @@ void CAddressBookDialog::OnButtonNew(wxCommandEvent& event) return; // Generate new key - strAddress = PubKeyToAddress(pwalletMain->GetOrReuseKeyFromPool()); + strAddress = CBitcoinAddress(pwalletMain->GetOrReuseKeyFromPool()).ToString(); if (fWasLocked) pwalletMain->Lock(); -- cgit v1.2.3