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

Method CommitTransaction

src/wallet/wallet.cpp:2334–2371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2332}
2333
2334void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm)
2335{
2336 LOCK(cs_wallet);
2337 WalletLogPrintf("CommitTransaction:\n%s\n", util::RemoveSuffixView(tx->ToString(), "\n"));
2338
2339 // Add tx to wallet, because if it has change it's also ours,
2340 // otherwise just for transaction history.
2341 CWalletTx* wtx = AddToWallet(tx, TxStateInactive{}, [&](CWalletTx& wtx, bool new_tx) {
2342 CHECK_NONFATAL(wtx.mapValue.empty());
2343 CHECK_NONFATAL(wtx.vOrderForm.empty());
2344 wtx.mapValue = std::move(mapValue);
2345 wtx.vOrderForm = std::move(orderForm);
2346 return true;
2347 });
2348
2349 // wtx can only be null if the db write failed.
2350 if (!wtx) {
2351 throw std::runtime_error(std::string(__func__) + ": Wallet db error, transaction commit failed");
2352 }
2353
2354 // Notify that old coins are spent
2355 for (const CTxIn& txin : tx->vin) {
2356 CWalletTx &coin = mapWallet.at(txin.prevout.hash);
2357 coin.MarkDirty();
2358 NotifyTransactionChanged(coin.GetHash(), CT_UPDATED);
2359 }
2360
2361 if (!fBroadcastTransactions) {
2362 // Don't submit tx to the mempool
2363 return;
2364 }
2365
2366 std::string err_string;
2367 if (!SubmitTxMemoryPoolAndRelay(*wtx, err_string, node::TxBroadcast::MEMPOOL_AND_BROADCAST_TO_ALL)) {
2368 WalletLogPrintf("CommitTransaction(): Transaction cannot be broadcast immediately, %s\n", err_string);
2369 // TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
2370 }
2371}
2372
2373DBErrors CWallet::PopulateWalletFromDB(bilingual_str& error, std::vector<bilingual_str>& warnings)
2374{

Callers 5

CommitTransactionFunction · 0.80
commitTransactionMethod · 0.80
FinishTransactionFunction · 0.80
SendMoneyFunction · 0.80

Calls 7

RemoveSuffixViewFunction · 0.85
NotifyTransactionChangedFunction · 0.85
ToStringMethod · 0.45
emptyMethod · 0.45
atMethod · 0.45
MarkDirtyMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected