diff options
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r-- | src/wallet/wallet.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 74650b8f3f..30ba95c3c1 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1136,7 +1136,13 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const SyncTxS // Block disconnection override an abandoned tx as unconfirmed // which means user may have to call abandontransaction again TxState tx_state = std::visit([](auto&& s) -> TxState { return s; }, state); - return AddToWallet(MakeTransactionRef(tx), tx_state, /*update_wtx=*/nullptr, /*fFlushOnClose=*/false, rescanning_old_block); + CWalletTx* wtx = AddToWallet(MakeTransactionRef(tx), tx_state, /*update_wtx=*/nullptr, /*fFlushOnClose=*/false, rescanning_old_block); + if (!wtx) { + // Can only be nullptr if there was a db write error (missing db, read-only db or a db engine internal writing error). + // As we only store arriving transaction in this process, and we don't want an inconsistent state, let's throw an error. + throw std::runtime_error("DB error adding transaction to wallet, write failed"); + } + return true; } } return false; @@ -2332,24 +2338,24 @@ bool CWallet::TopUpKeyPool(unsigned int kpSize) return res; } -BResult<CTxDestination> CWallet::GetNewDestination(const OutputType type, const std::string label) +util::Result<CTxDestination> CWallet::GetNewDestination(const OutputType type, const std::string label) { LOCK(cs_wallet); auto spk_man = GetScriptPubKeyMan(type, false /* internal */); if (!spk_man) { - return strprintf(_("Error: No %s addresses available."), FormatOutputType(type)); + return util::Error{strprintf(_("Error: No %s addresses available."), FormatOutputType(type))}; } spk_man->TopUp(); auto op_dest = spk_man->GetNewDestination(type); if (op_dest) { - SetAddressBook(op_dest.GetObj(), label, "receive"); + SetAddressBook(*op_dest, label, "receive"); } return op_dest; } -BResult<CTxDestination> CWallet::GetNewChangeDestination(const OutputType type) +util::Result<CTxDestination> CWallet::GetNewChangeDestination(const OutputType type) { LOCK(cs_wallet); @@ -2357,7 +2363,7 @@ BResult<CTxDestination> CWallet::GetNewChangeDestination(const OutputType type) bilingual_str error; ReserveDestination reservedest(this, type); if (!reservedest.GetReservedDestination(dest, true, error)) { - return error; + return util::Error{error}; } reservedest.KeepDestination(); |