Changeset View
Changeset View
Standalone View
Standalone View
src/qt/walletmodel.cpp
Show First 20 Lines • Show All 255 Lines • ▼ Show 20 Lines | if (total > nBalance) { | ||||
LOCK2(cs_main, wallet->cs_wallet); | LOCK2(cs_main, wallet->cs_wallet); | ||||
transaction.newPossibleKeyChange(wallet); | transaction.newPossibleKeyChange(wallet); | ||||
Amount nFeeRequired = Amount::zero(); | Amount nFeeRequired = Amount::zero(); | ||||
int nChangePosRet = -1; | int nChangePosRet = -1; | ||||
std::string strFailReason; | std::string strFailReason; | ||||
CWalletTx *newTx = transaction.getTransaction(); | CTransactionRef &newTx = transaction.getTransaction(); | ||||
CReserveKey *keyChange = transaction.getPossibleKeyChange(); | CReserveKey *keyChange = transaction.getPossibleKeyChange(); | ||||
bool fCreated = wallet->CreateTransaction(vecSend, *newTx, *keyChange, | bool fCreated = wallet->CreateTransaction(vecSend, newTx, *keyChange, | ||||
nFeeRequired, nChangePosRet, | nFeeRequired, nChangePosRet, | ||||
strFailReason, coinControl); | strFailReason, coinControl); | ||||
transaction.setTransactionFee(nFeeRequired); | transaction.setTransactionFee(nFeeRequired); | ||||
if (fSubtractFeeFromAmount && fCreated) { | if (fSubtractFeeFromAmount && fCreated) { | ||||
transaction.reassignAmounts(nChangePosRet); | transaction.reassignAmounts(nChangePosRet); | ||||
} | } | ||||
if (!fCreated) { | if (!fCreated) { | ||||
Show All 19 Lines | |||||
WalletModel::SendCoinsReturn | WalletModel::SendCoinsReturn | ||||
WalletModel::sendCoins(WalletModelTransaction &transaction) { | WalletModel::sendCoins(WalletModelTransaction &transaction) { | ||||
/* store serialized transaction */ | /* store serialized transaction */ | ||||
QByteArray transaction_array; | QByteArray transaction_array; | ||||
{ | { | ||||
LOCK2(cs_main, wallet->cs_wallet); | LOCK2(cs_main, wallet->cs_wallet); | ||||
CWalletTx *newTx = transaction.getTransaction(); | |||||
std::vector<std::pair<std::string, std::string>> vOrderForm; | |||||
for (const SendCoinsRecipient &rcp : transaction.getRecipients()) { | for (const SendCoinsRecipient &rcp : transaction.getRecipients()) { | ||||
if (rcp.paymentRequest.IsInitialized()) { | if (rcp.paymentRequest.IsInitialized()) { | ||||
// Make sure any payment requests involved are still valid. | // Make sure any payment requests involved are still valid. | ||||
if (PaymentServer::verifyExpired( | if (PaymentServer::verifyExpired( | ||||
rcp.paymentRequest.getDetails())) { | rcp.paymentRequest.getDetails())) { | ||||
return PaymentRequestExpired; | return PaymentRequestExpired; | ||||
} | } | ||||
// Store PaymentRequests in wtx.vOrderForm in wallet. | // Store PaymentRequests in wtx.vOrderForm in wallet. | ||||
std::string key("PaymentRequest"); | |||||
std::string value; | std::string value; | ||||
rcp.paymentRequest.SerializeToString(&value); | rcp.paymentRequest.SerializeToString(&value); | ||||
newTx->vOrderForm.push_back(make_pair(key, value)); | vOrderForm.emplace_back("PaymentRequest", std::move(value)); | ||||
} else if (!rcp.message.isEmpty()) { | } else if (!rcp.message.isEmpty()) { | ||||
// Message from normal bitcoincash:URI | // Message from normal bitcoincash:URI | ||||
// (bitcoincash:123...?message=example) | // (bitcoincash:123...?message=example) | ||||
newTx->vOrderForm.push_back( | vOrderForm.emplace_back("Message", rcp.message.toStdString()); | ||||
make_pair("Message", rcp.message.toStdString())); | |||||
} | } | ||||
} | } | ||||
CTransactionRef &newTx = transaction.getTransaction(); | |||||
CReserveKey *keyChange = transaction.getPossibleKeyChange(); | CReserveKey *keyChange = transaction.getPossibleKeyChange(); | ||||
CValidationState state; | CValidationState state; | ||||
if (!wallet->CommitTransaction(*newTx, *keyChange, g_connman.get(), | if (!wallet->CommitTransaction( | ||||
state)) { | newTx, {} /* mapValue */, std::move(vOrderForm), | ||||
{} /* fromAccount */, *keyChange, g_connman.get(), state)) { | |||||
return SendCoinsReturn( | return SendCoinsReturn( | ||||
TransactionCommitFailed, | TransactionCommitFailed, | ||||
QString::fromStdString(state.GetRejectReason())); | QString::fromStdString(state.GetRejectReason())); | ||||
} | } | ||||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); | CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); | ||||
ssTx << *newTx->tx; | ssTx << newTx; | ||||
transaction_array.append(&(ssTx[0]), ssTx.size()); | transaction_array.append(&(ssTx[0]), ssTx.size()); | ||||
} | } | ||||
// Add addresses / update labels that we've sent to to the address book, and | // Add addresses / update labels that we've sent to to the address book, and | ||||
// emit coinsSent signal for each recipient | // emit coinsSent signal for each recipient | ||||
for (const SendCoinsRecipient &rcp : transaction.getRecipients()) { | for (const SendCoinsRecipient &rcp : transaction.getRecipients()) { | ||||
// Don't touch the address book when we have a payment request | // Don't touch the address book when we have a payment request | ||||
if (!rcp.paymentRequest.IsInitialized()) { | if (!rcp.paymentRequest.IsInitialized()) { | ||||
▲ Show 20 Lines • Show All 316 Lines • Show Last 20 Lines |