aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgavinandresen <gavinandresen@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-11-03 23:40:43 +0000
committergavinandresen <gavinandresen@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-11-03 23:40:43 +0000
commit3cac997e19aae151f11d7201982d286ae4c386f6 (patch)
treea5d7730b63adbd53b7e9b56a2ebc95cc07bed301
parentc891967b6fcab2e8dc4ce0c787312b36c07efa4d (diff)
downloadbitcoin-3cac997e19aae151f11d7201982d286ae4c386f6.tar.xz
Prevent double-sends from quick double-button-clicks
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@174 1a98c847-1fd6-4fd8-948a-caf3550aa51b
-rw-r--r--ui.cpp110
1 files changed, 57 insertions, 53 deletions
diff --git a/ui.cpp b/ui.cpp
index ed5ccdea03..a6f550054b 100644
--- a/ui.cpp
+++ b/ui.cpp
@@ -1929,69 +1929,73 @@ void CSendDialog::OnButtonPaste(wxCommandEvent& event)
void CSendDialog::OnButtonSend(wxCommandEvent& event)
{
- CWalletTx wtx;
- string strAddress = (string)m_textCtrlAddress->GetValue();
-
- // Parse amount
- int64 nValue = 0;
- if (!ParseMoney(m_textCtrlAmount->GetValue(), nValue) || nValue <= 0)
- {
- wxMessageBox(_("Error in amount "), _("Send Coins"));
- return;
- }
- if (nValue > GetBalance())
+ static CCriticalSection cs_sendlock;
+ TRY_CRITICAL_BLOCK(cs_sendlock)
{
- wxMessageBox(_("Amount exceeds your balance "), _("Send Coins"));
- return;
- }
- if (nValue + nTransactionFee > GetBalance())
- {
- wxMessageBox(string(_("Total exceeds your balance when the ")) + FormatMoney(nTransactionFee) + _(" transaction fee is included "), _("Send Coins"));
- return;
- }
+ CWalletTx wtx;
+ string strAddress = (string)m_textCtrlAddress->GetValue();
- // Parse bitcoin address
- uint160 hash160;
- bool fBitcoinAddress = AddressToHash160(strAddress, hash160);
+ // Parse amount
+ int64 nValue = 0;
+ if (!ParseMoney(m_textCtrlAmount->GetValue(), nValue) || nValue <= 0)
+ {
+ wxMessageBox(_("Error in amount "), _("Send Coins"));
+ return;
+ }
+ if (nValue > GetBalance())
+ {
+ wxMessageBox(_("Amount exceeds your balance "), _("Send Coins"));
+ return;
+ }
+ if (nValue + nTransactionFee > GetBalance())
+ {
+ wxMessageBox(string(_("Total exceeds your balance when the ")) + FormatMoney(nTransactionFee) + _(" transaction fee is included "), _("Send Coins"));
+ return;
+ }
- if (fBitcoinAddress)
- {
- // Send to bitcoin address
- CScript scriptPubKey;
- scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG;
+ // Parse bitcoin address
+ uint160 hash160;
+ bool fBitcoinAddress = AddressToHash160(strAddress, hash160);
- string strError = SendMoney(scriptPubKey, nValue, wtx, true);
- if (strError == "")
- wxMessageBox(_("Payment sent "), _("Sending..."));
- else if (strError != "ABORTED")
- wxMessageBox(strError + " ", _("Sending..."));
- }
- else
- {
- // Parse IP address
- CAddress addr(strAddress);
- if (!addr.IsValid())
+ if (fBitcoinAddress)
{
- wxMessageBox(_("Invalid address "), _("Send Coins"));
- return;
+ // Send to bitcoin address
+ CScript scriptPubKey;
+ scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG;
+
+ string strError = SendMoney(scriptPubKey, nValue, wtx, true);
+ if (strError == "")
+ wxMessageBox(_("Payment sent "), _("Sending..."));
+ else if (strError != "ABORTED")
+ wxMessageBox(strError + " ", _("Sending..."));
}
+ else
+ {
+ // Parse IP address
+ CAddress addr(strAddress);
+ if (!addr.IsValid())
+ {
+ wxMessageBox(_("Invalid address "), _("Send Coins"));
+ return;
+ }
- // Message
- wtx.mapValue["to"] = strAddress;
- wtx.mapValue["from"] = m_textCtrlFrom->GetValue();
- wtx.mapValue["message"] = m_textCtrlMessage->GetValue();
+ // Message
+ wtx.mapValue["to"] = strAddress;
+ wtx.mapValue["from"] = m_textCtrlFrom->GetValue();
+ wtx.mapValue["message"] = m_textCtrlMessage->GetValue();
- // Send to IP address
- CSendingDialog* pdialog = new CSendingDialog(this, addr, nValue, wtx);
- if (!pdialog->ShowModal())
- return;
- }
+ // Send to IP address
+ CSendingDialog* pdialog = new CSendingDialog(this, addr, nValue, wtx);
+ if (!pdialog->ShowModal())
+ return;
+ }
- CRITICAL_BLOCK(cs_mapAddressBook)
- if (!mapAddressBook.count(strAddress))
- SetAddressBookName(strAddress, "");
+ CRITICAL_BLOCK(cs_mapAddressBook)
+ if (!mapAddressBook.count(strAddress))
+ SetAddressBookName(strAddress, "");
- EndModal(true);
+ EndModal(true);
+ }
}
void CSendDialog::OnButtonCancel(wxCommandEvent& event)