| 350 | } |
| 351 | |
| 352 | Result CommitTransaction(CWallet& wallet, const Txid& txid, CMutableTransaction&& mtx, std::vector<bilingual_str>& errors, Txid& bumped_txid) |
| 353 | { |
| 354 | LOCK(wallet.cs_wallet); |
| 355 | if (!errors.empty()) { |
| 356 | return Result::MISC_ERROR; |
| 357 | } |
| 358 | auto it = txid.IsNull() ? wallet.mapWallet.end() : wallet.mapWallet.find(txid); |
| 359 | if (it == wallet.mapWallet.end()) { |
| 360 | errors.emplace_back(Untranslated("Invalid or non-wallet transaction id")); |
| 361 | return Result::MISC_ERROR; |
| 362 | } |
| 363 | const CWalletTx& oldWtx = it->second; |
| 364 | |
| 365 | // make sure the transaction still has no descendants and hasn't been mined in the meantime |
| 366 | Result result = PreconditionChecks(wallet, oldWtx, /* require_mine=*/ false, errors); |
| 367 | if (result != Result::OK) { |
| 368 | return result; |
| 369 | } |
| 370 | |
| 371 | // commit/broadcast the tx |
| 372 | CTransactionRef tx = MakeTransactionRef(std::move(mtx)); |
| 373 | mapValue_t mapValue = oldWtx.mapValue; |
| 374 | mapValue["replaces_txid"] = oldWtx.GetHash().ToString(); |
| 375 | |
| 376 | wallet.CommitTransaction(tx, std::move(mapValue), oldWtx.vOrderForm); |
| 377 | |
| 378 | // mark the original tx as bumped |
| 379 | bumped_txid = tx->GetHash(); |
| 380 | if (!wallet.MarkReplaced(oldWtx.GetHash(), bumped_txid)) { |
| 381 | errors.emplace_back(Untranslated("Created new bumpfee transaction but could not mark the original transaction as replaced")); |
| 382 | } |
| 383 | return Result::OK; |
| 384 | } |
| 385 | |
| 386 | } // namespace feebumper |
| 387 | } // namespace wallet |
no test coverage detected