| 124 | } |
| 125 | |
| 126 | WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransaction &transaction, const CCoinControl& coinControl) |
| 127 | { |
| 128 | CAmount total = 0; |
| 129 | bool fSubtractFeeFromAmount = false; |
| 130 | QList<SendCoinsRecipient> recipients = transaction.getRecipients(); |
| 131 | std::vector<CRecipient> vecSend; |
| 132 | |
| 133 | if(recipients.empty()) |
| 134 | { |
| 135 | return OK; |
| 136 | } |
| 137 | |
| 138 | QSet<QString> setAddress; // Used to detect duplicates |
| 139 | int nAddresses = 0; |
| 140 | |
| 141 | // Pre-check input data for validity |
| 142 | for (const SendCoinsRecipient &rcp : recipients) |
| 143 | { |
| 144 | if (rcp.fSubtractFeeFromAmount) |
| 145 | fSubtractFeeFromAmount = true; |
| 146 | |
| 147 | if (rcp.paymentRequest.IsInitialized()) |
| 148 | { // PaymentRequest... |
| 149 | CAmount subtotal = 0; |
| 150 | const payments::PaymentDetails& details = rcp.paymentRequest.getDetails(); |
| 151 | for (int i = 0; i < details.outputs_size(); i++) |
| 152 | { |
| 153 | const payments::Output& out = details.outputs(i); |
| 154 | if (out.amount() <= 0) continue; |
| 155 | subtotal += out.amount(); |
| 156 | const unsigned char* scriptStr = (const unsigned char*)out.script().data(); |
| 157 | CScript scriptPubKey(scriptStr, scriptStr+out.script().size()); |
| 158 | CAmount nAmount = out.amount(); |
| 159 | CRecipient recipient = {scriptPubKey, nAmount, rcp.fSubtractFeeFromAmount}; |
| 160 | vecSend.push_back(recipient); |
| 161 | } |
| 162 | if (subtotal <= 0) |
| 163 | { |
| 164 | return InvalidAmount; |
| 165 | } |
| 166 | total += subtotal; |
| 167 | } |
| 168 | else |
| 169 | { // User-entered bitcoin address / amount: |
| 170 | if(!validateAddress(rcp.address)) |
| 171 | { |
| 172 | return InvalidAddress; |
| 173 | } |
| 174 | if(rcp.amount <= 0) |
| 175 | { |
| 176 | return InvalidAmount; |
| 177 | } |
| 178 | setAddress.insert(rcp.address); |
| 179 | ++nAddresses; |
| 180 | |
| 181 | CScript scriptPubKey = GetScriptForDestination(DecodeDestination(rcp.address.toStdString())); |
| 182 | CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount}; |
| 183 | vecSend.push_back(recipient); |
no test coverage detected