From 618855133d4ae4ece130aec3b35c5a65bea95b8f Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Mon, 15 Jul 2013 15:20:50 +1000 Subject: Refactor: CAddressBookData for mapAddressBook Straight refactor, so mapAddressBook stores a CAddressBookData (which just contains a std::string) instead of a std::string. Preparation for payment protocol work, which will add the notion of refund addresses to the address book. --- src/qt/walletmodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/qt/walletmodel.cpp') diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index fb3ffc5c91..d3c3ddcab1 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -214,10 +214,10 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QListcs_wallet); - std::map::iterator mi = wallet->mapAddressBook.find(dest); + std::map::iterator mi = wallet->mapAddressBook.find(dest); // Check if we have a new address or an updated label - if (mi == wallet->mapAddressBook.end() || mi->second != strLabel) + if (mi == wallet->mapAddressBook.end() || mi->second.name != strLabel) { wallet->SetAddressBookName(dest, strLabel); } -- cgit v1.2.3 From a41d5fe01947f2f878c055670986a165af800f9a Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Mon, 22 Jul 2013 16:50:39 +1000 Subject: Payment Protocol: X509-validated payment requests Add support for a Payment Protocol to Bitcoin-Qt. Payment messages are protocol-buffer encoded and communicated over http(s), so this adds a dependency on the Google protocol buffer library, and requires Qt with OpenSSL support. --- src/qt/walletmodel.cpp | 96 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 27 deletions(-) (limited to 'src/qt/walletmodel.cpp') diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index d3c3ddcab1..61357647b7 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -127,31 +127,60 @@ bool WalletModel::validateAddress(const QString &address) WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList &recipients) { qint64 total = 0; - QSet setAddress; - QString hex; + std::vector > vecSend; + QByteArray transaction; if(recipients.empty()) { return OK; } + QSet setAddress; // Used to detect duplicates + int nAddresses = 0; + // Pre-check input data for validity foreach(const SendCoinsRecipient &rcp, recipients) { - if(!validateAddress(rcp.address)) - { - return InvalidAddress; + if (rcp.paymentRequest.IsInitialized()) + { // PaymentRequest... + int64 subtotal = 0; + const payments::PaymentDetails& details = rcp.paymentRequest.getDetails(); + for (int i = 0; i < details.outputs_size(); i++) + { + const payments::Output& out = details.outputs(i); + if (out.amount() <= 0) continue; + subtotal += out.amount(); + const unsigned char* scriptStr = (const unsigned char*)out.script().data(); + CScript scriptPubKey(scriptStr, scriptStr+out.script().size()); + vecSend.push_back(std::pair(scriptPubKey, out.amount())); + } + if (subtotal <= 0) + { + return InvalidAmount; + } + total += subtotal; } - setAddress.insert(rcp.address); + else + { // User-entered bitcoin address / amount: + if(!validateAddress(rcp.address)) + { + return InvalidAddress; + } + if(rcp.amount <= 0) + { + return InvalidAmount; + } + setAddress.insert(rcp.address); + ++nAddresses; - if(rcp.amount <= 0) - { - return InvalidAmount; + CScript scriptPubKey; + scriptPubKey.SetDestination(CBitcoinAddress(rcp.address.toStdString()).Get()); + vecSend.push_back(std::pair(scriptPubKey, rcp.amount)); + + total += rcp.amount; } - total += rcp.amount; } - - if(recipients.size() > setAddress.size()) + if(setAddress.size() != nAddresses) { return DuplicateAddress; } @@ -169,19 +198,10 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QListcs_wallet); - // Sendmany - std::vector > vecSend; - foreach(const SendCoinsRecipient &rcp, recipients) - { - CScript scriptPubKey; - scriptPubKey.SetDestination(CBitcoinAddress(rcp.address.toStdString()).Get()); - vecSend.push_back(make_pair(scriptPubKey, rcp.amount)); - } - - CWalletTx wtx; CReserveKey keyChange(wallet); int64 nFeeRequired = 0; std::string strFailReason; + CWalletTx wtx; bool fCreated = wallet->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, strFailReason); if(!fCreated) @@ -194,6 +214,18 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(const QList::iterator mi = wallet->mapAddressBook.find(dest); // Check if we have a new address or an updated label - if (mi == wallet->mapAddressBook.end() || mi->second.name != strLabel) + if (mi == wallet->mapAddressBook.end()) + { + wallet->SetAddressBook(dest, strLabel, "send"); + } + else if (mi->second.name != strLabel) { - wallet->SetAddressBookName(dest, strLabel); + wallet->SetAddressBook(dest, strLabel, ""); // "" means don't change purpose } } + emit coinsSent(wallet, rcp, transaction); } - return SendCoinsReturn(OK, 0, hex); + return SendCoinsReturn(OK, 0); } OptionsModel *WalletModel::getOptionsModel() -- cgit v1.2.3