aboutsummaryrefslogtreecommitdiff
path: root/src/ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.cpp')
-rw-r--r--src/ui.cpp80
1 files changed, 39 insertions, 41 deletions
diff --git a/src/ui.cpp b/src/ui.cpp
index eae0a4f4c8..7d06caaec4 100644
--- a/src/ui.cpp
+++ b/src/ui.cpp
@@ -235,12 +235,13 @@ 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;
- if (!mapPubKeys.count(hash160))
+ vector<unsigned char> vchPubKey;
+ if (!pwalletMain->GetPubKey(address, vchPubKey))
return;
- pwalletMain->SetDefaultKey(mapPubKeys[hash160]);
+ pwalletMain->SetDefaultKey(vchPubKey);
pframeMain->m_textCtrlAddress->SetValue(strAddress);
}
}
@@ -366,7 +367,7 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent)
// Fill your address text box
vector<unsigned char> 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);
@@ -703,24 +704,23 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
{
if (pwalletMain->IsMine(txout))
{
- vector<unsigned char> vchPubKey;
- if (ExtractPubKey(txout.scriptPubKey, pwalletMain, vchPubKey))
+ 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 = PubKeyToAddress(vchPubKey);
- map<string, string>::iterator mi = pwalletMain->mapAddressBook.find(strAddress);
+ map<CBitcoinAddress, string>::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;
@@ -785,9 +785,9 @@ bool CMainFrame::InsertTransaction(const CWalletTx& wtx, bool fNew, int nIndex)
else
{
// Sent to Bitcoin Address
- uint160 hash160;
- if (ExtractHash160(txout.scriptPubKey, hash160))
- strAddress = Hash160ToAddress(hash160);
+ CBitcoinAddress address;
+ if (ExtractAddress(txout.scriptPubKey, pwalletMain, address))
+ strAddress = address.ToString();
}
string strDescription = _("To: ");
@@ -1114,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);
}
@@ -1393,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();
@@ -1502,17 +1502,16 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
{
if (pwalletMain->IsMine(txout))
{
- vector<unsigned char> vchPubKey;
- if (ExtractPubKey(txout.scriptPubKey, pwalletMain, vchPubKey))
+ CBitcoinAddress address;
+ if (ExtractAddress(txout.scriptPubKey, pwalletMain, address))
{
- string strAddress = PubKeyToAddress(vchPubKey);
- if (pwalletMain->mapAddressBook.count(strAddress))
+ if (pwalletMain->mapAddressBook.count(address))
{
strHTML += string() + _("<b>From:</b> ") + _("unknown") + "<br>";
strHTML += _("<b>To:</b> ");
- 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 += "<br>";
@@ -1588,13 +1587,13 @@ CTxDetailsDialog::CTxDetailsDialog(wxWindow* parent, CWalletTx wtx) : CTxDetails
if (wtx.mapValue["to"].empty())
{
// Offline transaction
- uint160 hash160;
- if (ExtractHash160(txout.scriptPubKey, hash160))
+ CBitcoinAddress address;
+ if (ExtractAddress(txout.scriptPubKey, pwalletMain, address))
{
- string strAddress = Hash160ToAddress(hash160);
+ string strAddress = address.ToString();
strHTML += _("<b>To:</b> ");
- 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 += "<br>";
}
@@ -2155,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)
{
@@ -2169,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 == "")
@@ -2213,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);
@@ -2625,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) && mapPubKeys.count(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);
}
}
@@ -2740,8 +2738,8 @@ void CAddressBookDialog::OnButtonCopy(wxCommandEvent& event)
bool CAddressBookDialog::CheckIfMine(const string& strAddress, const string& strTitle)
{
- uint160 hash160;
- bool fMine = (AddressToHash160(strAddress, hash160) && mapPubKeys.count(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;
@@ -2827,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();