MCPcopy Create free account
hub / github.com/ElementsProject/elements / prepareTransaction

Method prepareTransaction

src/qt/walletmodel.cpp:183–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181}
182
183WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransaction &transaction, wallet::BlindDetails *blind_details, const CCoinControl& coinControl)
184{
185 CAmountMap total;
186 bool fSubtractFeeFromAmount = false;
187 QList<SendCoinsRecipient> recipients = transaction.getRecipients();
188 std::vector<CRecipient> vecSend;
189
190 if(recipients.empty())
191 {
192 return OK;
193 }
194
195 QSet<QString> setAddress; // Used to detect duplicates
196 int nAddresses = 0;
197
198 // Pre-check input data for validity
199 for (const SendCoinsRecipient &rcp : recipients)
200 {
201 if (rcp.fSubtractFeeFromAmount)
202 fSubtractFeeFromAmount = true;
203 { // User-entered bitcoin address / amount:
204 if(!validateAddress(rcp.address))
205 {
206 return InvalidAddress;
207 }
208 if(rcp.asset_amount <= 0)
209 {
210 return InvalidAmount;
211 }
212 setAddress.insert(rcp.address);
213 ++nAddresses;
214
215 CTxDestination dest = DecodeDestination(rcp.address.toStdString());
216 CScript scriptPubKey = GetScriptForDestination(dest);
217 CPubKey confidentiality_pubkey = GetDestinationBlindingKey(dest);
218 CRecipient recipient = {scriptPubKey, rcp.asset_amount, rcp.asset, confidentiality_pubkey, rcp.fSubtractFeeFromAmount};
219 vecSend.push_back(recipient);
220
221 total[rcp.asset] += rcp.asset_amount;
222 }
223 }
224 if(setAddress.size() != nAddresses)
225 {
226 return DuplicateAddress;
227 }
228
229 CAmountMap nBalance = m_wallet->getAvailableBalance(coinControl);
230
231 if(total > nBalance)
232 {
233 return AmountExceedsBalance;
234 }
235
236 {
237 CAmount nFeeRequired = 0;
238 int nChangePosRet = -1;
239 bilingual_str error;
240

Callers 1

PrepareSendTextMethod · 0.80

Calls 15

DecodeDestinationFunction · 0.85
GetScriptForDestinationFunction · 0.85
SendCoinsReturnClass · 0.85
getRecipientsMethod · 0.80
getAvailableBalanceMethod · 0.80
createTransactionMethod · 0.80
privateKeysDisabledMethod · 0.80
setTransactionFeeMethod · 0.80
reassignAmountsMethod · 0.80
getDefaultMaxTxFeeMethod · 0.80
ParamsClass · 0.50

Tested by

no test coverage detected