mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
Merge #17154: wallet: Remove return value from CommitTransaction
9e95931865[wallet] Remove `state` argument from CWallet::CommitTransaction (John Newbery)d1734f9a3b[wallet] Remove return value from CommitTransaction() (John Newbery)b6f486a02b[wallet] Add doxygen comment to CWallet::CommitTransaction() (John Newbery)8bba91b22d[wallet] Fix whitespace in CWallet::CommitTransaction() (John Newbery) Pull request description: `CommitTransaction()` returns a bool to indicate success, but since commitb3a7410(#9302) it only returns true, even if the transaction was not successfully broadcast. This commit changes CommitTransaction() to return void. All dead code in `if (!CommitTransaction())` branches has been removed. Two additional commits fix up the idiosyncratic whitespace in `CommitTransaction` and add a doxygen comment for the function. ACKs for top commit: laanwj: ACK9e95931865Tree-SHA512: a55a2c20369a45222fc0e02d0891495655a926e71c4f52cb72624768dd7b9c1dca716ea67d38420afb90f40c6e0fd448caa60c18fd693bb10ecb110b641820e6
This commit is contained in:
@@ -3284,51 +3284,44 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call after CreateTransaction unless you want to abort
|
||||
*/
|
||||
bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm, CValidationState& state)
|
||||
void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm)
|
||||
{
|
||||
{
|
||||
auto locked_chain = chain().lock();
|
||||
LOCK(cs_wallet);
|
||||
auto locked_chain = chain().lock();
|
||||
LOCK(cs_wallet);
|
||||
|
||||
CWalletTx wtxNew(this, std::move(tx));
|
||||
wtxNew.mapValue = std::move(mapValue);
|
||||
wtxNew.vOrderForm = std::move(orderForm);
|
||||
wtxNew.fTimeReceivedIsTxTime = true;
|
||||
wtxNew.fFromMe = true;
|
||||
CWalletTx wtxNew(this, std::move(tx));
|
||||
wtxNew.mapValue = std::move(mapValue);
|
||||
wtxNew.vOrderForm = std::move(orderForm);
|
||||
wtxNew.fTimeReceivedIsTxTime = true;
|
||||
wtxNew.fFromMe = true;
|
||||
|
||||
WalletLogPrintf("CommitTransaction:\n%s", wtxNew.tx->ToString()); /* Continued */
|
||||
{
|
||||
WalletLogPrintf("CommitTransaction:\n%s", wtxNew.tx->ToString()); /* Continued */
|
||||
|
||||
// Add tx to wallet, because if it has change it's also ours,
|
||||
// otherwise just for transaction history.
|
||||
AddToWallet(wtxNew);
|
||||
// Add tx to wallet, because if it has change it's also ours,
|
||||
// otherwise just for transaction history.
|
||||
AddToWallet(wtxNew);
|
||||
|
||||
// Notify that old coins are spent
|
||||
for (const CTxIn& txin : wtxNew.tx->vin)
|
||||
{
|
||||
CWalletTx &coin = mapWallet.at(txin.prevout.hash);
|
||||
coin.BindWallet(this);
|
||||
NotifyTransactionChanged(this, coin.GetHash(), CT_UPDATED);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the inserted-CWalletTx from mapWallet so that the
|
||||
// fInMempool flag is cached properly
|
||||
CWalletTx& wtx = mapWallet.at(wtxNew.GetHash());
|
||||
|
||||
if (fBroadcastTransactions)
|
||||
{
|
||||
std::string err_string;
|
||||
if (!wtx.SubmitMemoryPoolAndRelay(err_string, true, *locked_chain)) {
|
||||
WalletLogPrintf("CommitTransaction(): Transaction cannot be broadcast immediately, %s\n", err_string);
|
||||
// TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
|
||||
}
|
||||
}
|
||||
// Notify that old coins are spent
|
||||
for (const CTxIn& txin : wtxNew.tx->vin) {
|
||||
CWalletTx &coin = mapWallet.at(txin.prevout.hash);
|
||||
coin.BindWallet(this);
|
||||
NotifyTransactionChanged(this, coin.GetHash(), CT_UPDATED);
|
||||
}
|
||||
|
||||
// Get the inserted-CWalletTx from mapWallet so that the
|
||||
// fInMempool flag is cached properly
|
||||
CWalletTx& wtx = mapWallet.at(wtxNew.GetHash());
|
||||
|
||||
if (!fBroadcastTransactions) {
|
||||
// Don't submit tx to the mempool
|
||||
return;
|
||||
}
|
||||
|
||||
std::string err_string;
|
||||
if (!wtx.SubmitMemoryPoolAndRelay(err_string, true, *locked_chain)) {
|
||||
WalletLogPrintf("CommitTransaction(): Transaction cannot be broadcast immediately, %s\n", err_string);
|
||||
// TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
|
||||
|
||||
Reference in New Issue
Block a user