MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / prepareTransaction

Method prepareTransaction

src/qt/walletmodel.cpp:151–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149}
150
151WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransaction &transaction, const CCoinControl& coinControl)
152{
153 transaction.getWtx() = nullptr; // reset tx output
154
155 CAmount total = 0;
156 bool fSubtractFeeFromAmount = false;
157 QList<SendCoinsRecipient> recipients = transaction.getRecipients();
158 std::vector<CRecipient> vecSend;
159
160 if(recipients.empty())
161 {
162 return OK;
163 }
164
165 QSet<QString> setAddress; // Used to detect duplicates
166 int nAddresses = 0;
167
168 // Pre-check input data for validity
169 for (const SendCoinsRecipient &rcp : recipients)
170 {
171 if (rcp.fSubtractFeeFromAmount)
172 fSubtractFeeFromAmount = true;
173 { // User-entered bitcoin address / amount:
174 if(!validateAddress(rcp.address))
175 {
176 return InvalidAddress;
177 }
178 if(rcp.amount <= 0)
179 {
180 return InvalidAmount;
181 }
182 setAddress.insert(rcp.address);
183 ++nAddresses;
184
185 vecSend.emplace_back(CRecipient{DecodeDestination(rcp.address.toStdString()), rcp.amount, rcp.fSubtractFeeFromAmount});
186
187 total += rcp.amount;
188 }
189 }
190 if(setAddress.size() != nAddresses)
191 {
192 return DuplicateAddress;
193 }
194
195 // If no coin was manually selected, use the cached balance
196 // Future: can merge this call with 'createTransaction'.
197 CAmount nBalance = getAvailableBalance(&coinControl);
198
199 if(total > nBalance)
200 {
201 return AmountExceedsBalance;
202 }
203
204 try {
205 auto& newTx = transaction.getWtx();
206 const auto& res = m_wallet->createTransaction(vecSend, coinControl, /*sign=*/!wallet().privateKeysDisabled(), /*change_pos=*/std::nullopt);
207 if (!res) {
208 Q_EMIT message(tr("Send Coins"), QString::fromStdString(util::ErrorString(res).translated),

Callers 1

PrepareSendTextMethod · 0.80

Calls 15

DecodeDestinationFunction · 0.85
ErrorStringFunction · 0.85
SendCoinsReturnClass · 0.85
getRecipientsMethod · 0.80
createTransactionMethod · 0.80
privateKeysDisabledMethod · 0.80
setTransactionFeeMethod · 0.80
reassignAmountsMethod · 0.80
getDefaultMaxTxFeeMethod · 0.80
emptyMethod · 0.45
insertMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected