From 90371049c02604b7e26bf558f455bbabaff85231 Mon Sep 17 00:00:00 2001 From: Bertrand Darbon Date: Thu, 15 Sep 2022 17:48:13 +0200 Subject: [PATCH] Limit UTXOs for transactions (#906) * Limit UTXOs for transactions To avoid HSM crash :p * use configuration --- core/src/wallet/bitcoin/BitcoinLikeAccount.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/wallet/bitcoin/BitcoinLikeAccount.cpp b/core/src/wallet/bitcoin/BitcoinLikeAccount.cpp index f574f05188..62a651381a 100644 --- a/core/src/wallet/bitcoin/BitcoinLikeAccount.cpp +++ b/core/src/wallet/bitcoin/BitcoinLikeAccount.cpp @@ -766,7 +766,14 @@ namespace ledger { auto keychain = self->getKeychain(); soci::session session(self->getWallet()->getDatabase()->getPool()); - return BitcoinLikeUTXODatabaseHelper::queryAllUtxos(session, self->getAccountUid(), self->getWallet()->getCurrency()); + auto utxos = BitcoinLikeUTXODatabaseHelper::queryAllUtxos(session, self->getAccountUid(), self->getWallet()->getCurrency()); + const auto maxUtxo = self->getWallet()->getConfig()->getInt("MAX_UTXO").value_or(std::numeric_limits::max()); + + if (utxos.size() > maxUtxo) { + throw std::runtime_error(fmt::format("Too many utxos. Got {}, but max is {}.", utxos.size(), maxUtxo)); + } + + return utxos; }); }; auto getTransaction = [self](const std::string &hash) -> FuturePtr {